[Biopython] Bio won't import in *.py scripts
Leighton Pritchard
lpritc at scri.ac.uk
Fri Dec 18 08:49:51 UTC 2009
Hi,
On 17/12/2009 22:59, "Peter Cock" <p.j.a.cock at googlemail.com> wrote:
> Hi Jeff,
>
> On Thu, Dec 17, 2009 at 7:43 PM, Jeff Tomkins <jtomkins at icr.org> wrote:
>> I installed biopython 1.52 as directed for OS X leopard.
>> Everything imports using the python prompt in the terminal,
>> idle, ipython, wing ide, etc.
>
> Good :)
>
>> But when I run a standard python script (#!/usr/bin/python)
>> in the shell it cannot locate Bio. What setup feature have I missed?
It could be a $PATH issue.
On my Mac, /usr/bin/python is where Apple's Python lives. I leave that
installation alone, and don't replace it to avoid problems with the OS's
potential use of Python (I had horrors with it back at 10.2). My 'working'
version of Python is installed as /usr/local/bin/python.
lpmacpro:scripts lpritc$ /usr/bin/python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
lpmacpro:scripts lpritc$ which python
/usr/local/bin/python
lpmacpro:scripts lpritc$ python
Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
lpmacpro:scripts lpritc$ /usr/local/bin/python
Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
You could check to see if your setup is similar.
What this means is that, as I have /usr/local/bin ahead of /usr/bin in my
$PATH (don't shout at me, everyone!), command-line invocation and module
installations with 'python setup.py' use the 'working' version, so install
modules under that version of Python only. This would mean that if I had
#!/usr/bin/python at the head of my script, it would use Apple's Python, and
not see modules installed under my 'working' Python. This would give the
same error you seem to describe:
lpmacpro:scripts lpritc$ python
Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Bio
>>>
lpmacpro:scripts lpritc$ /usr/bin/python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Bio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Bio
>>>
If this is the issue, then one way to get around the problem is to use
#!/usr/bin/env python at the top of your script so that it uses the Python
you would get from the command-line. This is better in some ways, as you
don't have to make guesses about where the Python executable is installed
when you move the script to another machine, though it probably won't matter
on Windows, and there may be security issues that arise from this shortcut
under some circumstances. If you're at all worried about those, just try
'which python' at the command-line, and substitute that location for
/usr/bin/python.
Cheers,
L.
--
Dr Leighton Pritchard MRSC
D131, Plant Pathology Programme, SCRI
Errol Road, Invergowrie, Perth and Kinross, Scotland, DD2 5DA
e:lpritc at scri.ac.uk w:http://www.scri.ac.uk/staff/leightonpritchard
gpg/pgp: 0xFEFC205C tel:+44(0)1382 562731 x2405
______________________________________________________
SCRI, Invergowrie, Dundee, DD2 5DA.
The Scottish Crop Research Institute is a charitable company limited by guarantee.
Registered in Scotland No: SC 29367.
Recognised by the Inland Revenue as a Scottish Charity No: SC 006662.
DISCLAIMER:
This email is from the Scottish Crop Research Institute, but the views expressed by the sender are not necessarily the views of SCRI and its subsidiaries. This email and any files transmitted with it are confidential to the intended recipient at the e-mail address to which it has been addressed. It may not be disclosed or used by any other than that
addressee.
If you are not the intended recipient you are requested to preserve this confidentiality and you must not use, disclose, copy, print or rely on this e-mail in any way. Please notify postmaster at scri.ac.uk quoting the name of the sender and delete the email from your system.
Although SCRI has taken reasonable precautions to ensure no viruses are present in this email, neither the Institute nor the sender accepts any responsibility for any viruses, and it is your responsibility to scan the email and the attachments (if any).
______________________________________________________
More information about the Biopython
mailing list