[Biopython-dev] Leaked handles in PAML unit tests

Peter Cock p.j.a.cock at googlemail.com
Thu Aug 4 15:59:42 UTC 2011


On Thu, Aug 4, 2011 at 4:38 PM, Brandon Invergo <b.invergo at gmail.com> wrote:
> Hi Peter,
> (I'm CCing this to the dev list for the info in the second paragraph)
> Thanks for the reply. I solved the Python2 problem by fixing my
> PYTHONPATH. Running the tests from the Tests directory couldn't find the
> Bio module due to a mistake in the PYTHONPATH, so I tried to run them
> from the parent directory, resulting in test failures. A dumb mistake
> but anyway it's fixed. Sorry for wasting your time with that.

No problem - learning about paths and imports is a bit tricky.

> I still have the following error with Python 3.2, though, which prevents
> me from figuring out the leaked handle problem in Py3k:
> [brandon at brandon-linux Tests]$ python test_PAML_baseml.py
> Traceback (most recent call last):
>  File "test_PAML_baseml.py", line 10, in <module>
>    from Bio.Phylo.PAML import baseml
>  File "/home/brandon/Projects/pypaml/biopython/Bio/Phylo/__init__.py",
> line 12, in <module>
>    from Bio.Phylo._io import parse, read, write, convert
>  File "/home/brandon/Projects/pypaml/biopython/Bio/Phylo/_io.py", line
> 12, in <module>
>    from Bio.Phylo import BaseTree, NewickIO, NexusIO
>  File "/home/brandon/Projects/pypaml/biopython/Bio/Phylo/BaseTree.py",
> line 222
>    return u'%s(%s)' % (self.__class__.__name__,
>
> SyntaxError: invalid syntax

Hang on - that looks like you ran it with "python" meaning Python 2.x

Working with Python 3 the following should "just work":

cd /home/brandon/Projects/pypaml/biopython
python3 setup.py build
python3 setup.py test
python3 setup.py install #Use sudo or --prefix etc if you want

However, if you want to run the offline test only, you need
to go into the Python3 converted Tests directory, not the
unconverted Python2 Tests directory. Note that this is
Biopython specific (but based on what NumPy does). e.g.

cd /home/brandon/Projects/pypaml/biopython
python3 setup.py build
cd build/py3.2/Tests
python3 run_tests.py --offline

Likewise if you want to test just one module,

cd /home/brandon/Projects/pypaml/biopython
python3 setup.py build
cd build/py3.2/Tests
python3 run_tests.py test_PAML_baseml.py

In the above, run_tests.py should take care of the path
settings to ensure the freshly built Biopython is used
(not whatever old version may be installed elsewhere).

If the above works nicely for you, stick with that.

Alternatively, I often just install in-development versions of
Biopython on my personal machine under my home directory
(where Python 3 was also installed using the --prefix option
so I don't need to mess about with the PYTHONPATH):

cd /home/brandon/Projects/pypaml/biopython
python3 setup.py install --prefix=$HOME
cd build/py3.2/Tests
python3 test_PAML_baseml.py

If your Python 3 is installed at system level you can do this but
it isn't very clean (certainly don't do it on a shared machine):

cd /home/brandon/Projects/pypaml/biopython
sudo python3 setup.py install
cd build/py3.2/Tests
python3 test_PAML_baseml.py

Alternatively if your Python 3 is at the system level you can
install Biopython under your home directory but then you have
to mess about with PYTHONPATH and keep changing it for
Python2 vs Python3, since they use the same variable (a
design choice I fail to see any advantages in).

Confusing isn't it?

There are other potential solutions to having multiple copies
of Python installed, like using virtualenv...

Peter




More information about the Biopython-dev mailing list