no module named pysam

2,692 views
Skip to first unread message

bioflorcorrea

unread,
Nov 4, 2014, 9:03:11 AM11/4/14
to pysam-us...@googlegroups.com
Hello everybody,
Some days ago I installed pysam, and it was working fine.
But today I am trying to use through the emirge.py script, but it gave me this error:
No module named pysam
So I upgraded it

 pip install pysam --upgrade

Requirement already satisfied (use --upgrade to upgrade): pysam in /usr/lib64/python2.6/site-packages
Requirement already satisfied (use --upgrade to upgrade): cython>=0.12.1 in /usr/lib64/python2.6/site-packages (from pysam)
Cleaning up...

But the error was still appearing, when executing emirge.py.
So I uninstall it by:

pip uninstall pysam

And it worked fine, and I installed it again:
pip install pysam

The run the emirge.py again and the same error appear

[root@host00 bin]# python emirge.py --help
Traceback (most recent call last):
  File "emirge.py", line 54, in <module>
    import pysam
ImportError: No module named pysam

How can I fix it please? Any help? I do not understand what is happening... the module is installed but emirge.py seems not to be finding it? Should I change sth?
Thanks a lot!!

Dennis Simpson

unread,
Nov 4, 2014, 9:37:57 AM11/4/14
to pysam-us...@googlegroups.com
Do you have two different versions of Python installed and are potentially invoking the one without pysam?

--
You received this message because you are subscribed to the Google Groups "Pysam User group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pysam-user-gro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bioflorcorrea

unread,
Nov 4, 2014, 9:47:22 AM11/4/14
to pysam-us...@googlegroups.com
ANother strange thing for me is that if I run python in terminal, inside python I tried import pysam, and it worked fine!
What can I do, any ideas please??!
Thanks

bioflorcorrea

unread,
Nov 4, 2014, 9:50:17 AM11/4/14
to pysam-us...@googlegroups.com
I dont think that is the problem, beacause when I used

python --version

the output is

python: /usr/bin/python /usr/bin/python2.6-config /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz

Looks like only python 2.6 is installed, rigth?

Florian Finkernagel

unread,
Nov 4, 2014, 9:51:01 AM11/4/14
to pysam-us...@googlegroups.com
It is possible that 'emigre.py' is manipulating sys.path - which is what python uses to search for modules.

print sys.path in an interactive python
and once just before the import pysam line
and compare.

(you'll need to import sys first)
Message has been deleted

bioflorcorrea

unread,
Nov 4, 2014, 9:58:31 AM11/4/14
to pysam-us...@googlegroups.com
In the emirge,py script import sys comes in the first line..
I also tried adding the specific path where pysam is to add it to the PYTHONPATH, but it did not work either...

I am lost.
Please, help me!
Thanks

Florian Finkernagel

unread,
Nov 4, 2014, 10:03:14 AM11/4/14
to pysam-us...@googlegroups.com
Please provide the output of 
import sys
print sys.path
from within an interactive python console,

and from within emirge.py by sticking it in line 53.

Marcel Martin

unread,
Nov 4, 2014, 10:15:17 AM11/4/14
to pysam-us...@googlegroups.com
On 2014-11-04 15:58, bioflorcorrea wrote:
> In the emirge,py script import sys comes in the first line..
> I also tried adding the specific path where pysam is to add it to the
> PYTHONPATH, but it did not work either...
>
> I am lost.
> Please, help me!

It would have been a good idea to include the link to the software you
are trying to use:
https://github.com/csmiller/EMIRGE

Run the following command and paste the output here:

which python

Then run "python --version" again. The output should be "Python 2.6" or
so. If you actually do get what you wrote in your previous mail, then
something strange is going on with your installation.

Even if the Python version is the same, it could still be that you are
using two different Pythons. One could be 32 bit, the other 64 bit, or
they could just be installed into different directories.

Do not set PYTHONPATH. It sometimes makes things work, but it makes them
worse later on.

Also, it's a good idea never to use sudo when installing Python
packages, even when the installation instructions say so. Just install
them into your home directory by adding --user to the install command.

Try to install pysam with this command:

python -m pip install --user pysam

You can also install emirge, as it says in its README. That is, run

python setup.py install --user

in the directory where you downloaded emirge. The binary will be in
$HOME/.local/bin/ . Add that to your PATH (or specify the full path
every time you run it).

Marcel

bioflorcorrea

unread,
Nov 5, 2014, 3:40:13 AM11/5/14
to pysam-us...@googlegroups.com
>>> import sys
>>> print sys.path
['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages']

And from emirge.py script, which is:

"""
EMIRGE: Expectation-Maximization Iterative Reconstruction of Genes from the Environment
Copyright (C) 2010-2012 Christopher S. Miller  (christophe...@ucdenver.edu)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>

https://github.com/csmiller/EMIRGE

for help, type:
python emirge.py --help
"""

USAGE = \
"""usage: %prog DIR <required_parameters> [options]

This version of EMIRGE (%prog) attempts to reconstruct rRNA SSU genes from
Illumina metagenomic data.
DIR is the working directory to process data in.
Use --help to see a list of required and optional arguments

Additional information:
https://groups.google.com/group/emirge-users
https://github.com/csmiller/EMIRGE/wiki

If you use EMIRGE in your work, please cite these manuscripts, as appropriate.

Miller CS, Baker BJ, Thomas BC, Singer SW, Banfield JF (2011)
EMIRGE: reconstruction of full-length ribosomal genes from microbial community short read sequencing data.
Genome biology 12: R44. doi:10.1186/gb-2011-12-5-r44.

Miller CS, Handley KM, Wrighton KC, Frischkorn KR, Thomas BC, Banfield JF (2013)
Short-Read Assembly of Full-Length 16S Amplicons Reveals Bacterial Diversity in Subsurface Sediments.
PloS one 8: e56018. doi:10.1371/journal.pone.0056018.
"""

import sys
import os
import re
import csv
from optparse import OptionParser, OptionGroup
# from MyFasta import FastIterator, Record  # moved this code into this file.
import pysam
import numpy
from scipy import sparse

The output after executing ./emirge.py [options]


Traceback (most recent call last):
  File "./emirge.py", line 54, in <module>

    import pysam
ImportError: No module named pysam

But strickingly, if I ran the same script this way:
emirge.py [options]
This return different output:


Traceback (most recent call last):
  File "/usr/bin/emirge.py", line 55, in <module>
    import numpy
  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
    import add_newdocs
  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
    from type_check import *
  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
    import numpy.core.numeric as _nx
  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
    import multiarray
AttributeError: PyCapsule_Import "datetime.datetime_CAPI" is not valid

Florian Finkernagel

unread,
Nov 5, 2014, 3:47:28 AM11/5/14
to pysam-us...@googlegroups.com
On Wednesday, November 5, 2014 9:40:13 AM UTC+1, bioflorcorrea wrote:
>>> import sys
>>> print sys.path
['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages']

  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
    import add_newdocs
  File "/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>

Note the discrepancy between python 2.6 and python 2.7.
You have foobared your python installation with something that things the right approach to packaging is to install everything to it's local environment and then mess with your paths.

And you really should not be working as root...!

Simplest work around is probably to actually call 'python emirge.py' instead of ./emigre.py - which will use the same python you get interactively.

The method I'd prefer though would be to read up on docker, and get yourself a well defined research environment.

bioflorcorrea

unread,
Nov 5, 2014, 3:48:01 AM11/5/14
to pysam-us...@googlegroups.com
Hi!
 It is true I completely forgot to add the link to the EMIRGE web page, sorry for that!
Thanks for the advice. One question:

Before installing anything again, should I uninstall pysam, emirge...?
Thanks!

bioflorcorrea

unread,
Nov 5, 2014, 6:11:57 AM11/5/14
to pysam-us...@googlegroups.com
Sorry, I do not fully understand your comment... You said you would run the script as python emirge.py but when i do that the output is the same as ./emirge.py
And I agree with you I have to read up... but meanwhile how do you solve out this sspecif problem? how can I make emirge to work? I have now realized that when installin another software (qiime) another version of python was installed... but how can I go backwards? Uninstall qiime would help?

Florian Finkernagel

unread,
Nov 5, 2014, 8:16:36 AM11/5/14
to pysam-us...@googlegroups.com
You still have not added print sys.path to emigre.py and sent us the output - this is the acid test to reveal whether you're running the same python in both cases.

bioflorcorrea

unread,
Nov 6, 2014, 4:10:13 AM11/6/14
to pysam-us...@googlegroups.com
This is it, when I ran it as ./modemirge.py (because if I ran it as python modemirge,py it only ouputs the pysam error without printing the sys.path)

['/home/sadmin/PROGRAMAS/EMIRGE-master', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/Sphinx-1.0.4-py2.7.egg', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/docutils-0.12-py2.7.egg', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/Jinja2-2.7.3-py2.7.egg', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/Pygments-2.0rc1-py2.7.egg', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/MarkupSafe-0.23-py2.7-linux-x86_64.egg', '/root/qiime_software/pyqi-0.3.1-release/lib/python2.7/site-packages/pyqi-0.3.1-py2.7.egg', '/root/qiime_software/MySQL-python-1.2.3-release/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg', '/root/qiime_software/setuptools-0.6c11-release/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/root/qiime_software/matplotlib-1.3.1-release/lib/python2.7/site-packages', '/root/qiime_software/pprospector-1.0.1-release/lib/python2.7/site-packages', '/root/qiime_software/tax2tree-1.0-release/lib/python2.7/site-packages', '/root/qiime_software/pynast-1.2.2-release/lib/python2.7/site-packages', '/root/qiime_software/pycogent-1.5.3-release/lib/python2.7/site-packages', '/root/qiime_software/emperor-0.9.3-release/lib/python2.7/site-packages', '/root/qiime_software/biom-format-1.3.1-release/lib/python2.7/site-packages', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages', '/root/qiime_software/pyqi-0.3.1-release/lib/python2.7/site-packages', '/root/qiime_software/MySQL-python-1.2.3-release/lib/python2.7/site-packages', '/root/qiime_software/mpi4py-1.2.2-release/lib/python2.7/site-packages', '/root/qiime_software/setuptools-0.6c11-release/lib/python2.7/site-packages', '/root/qiime_software/pysqlite-2.6.3-release/lib/python2.7/site-packages', '/root/qiime_software/gdata-2.0.17-release/lib/python2.7/site-packages', '/root/qiime_software/qcli-0.1.0-release/lib/python2.7/site-packages', '/root/qiime_software/tornado-3.1.1-release/lib/python2.7/site-packages', '/root/qiime_software/SQLAlchemy-0.7.1-release/lib/python2.7/site-packages', '/root/qiime_software/pyzmq-2.1.11-release/lib/python2.7/site-packages', '/root/qiime_software/numpy-1.7.1-release/lib/python2.7/site-packages', '/home/sadmin/PROGRAMAS/EMIRGE-master', '/root/qiime_software/python-2.7.3-release/lib/python27.zip', '/root/qiime_software/python-2.7.3-release/lib/python2.7', '/root/qiime_software/python-2.7.3-release/lib/python2.7/plat-linux2', '/root/qiime_software/python-2.7.3-release/lib/python2.7/lib-tk', '/root/qiime_software/python-2.7.3-release/lib/python2.7/lib-old', '/root/qiime_software/python-2.7.3-release/lib/python2.7/lib-dynload', '/root/qiime_software/python-2.7.3-release/lib/python2.7/site-packages', '/root/qiime_software/matplotlib-1.3.1-release/lib/python2.7/site-packages']

Traceback (most recent call last):
  File "./modemirge.py", line 55, in <module>

    import pysam
ImportError: No module named pysam


Florian Finkernagel

unread,
Nov 6, 2014, 4:17:50 AM11/6/14
to pysam-us...@googlegroups.com
On Thursday, November 6, 2014 10:10:13 AM UTC+1, bioflorcorrea wrote:
This is it, when I ran it as ./modemirge.py (because if I ran it as python modemirge,py it only ouputs the pysam error without printing the sys.path)

That makes no sense whatsoever - they're after all running the same script.

What's the output of 'which python'?
What's the output of 'which python2'?.
 

['/home/sadmin/PROGRAMAS/EMIRGE-master', '/root/qiime_software/sphinx-1.0.4-release/lib/python2.7/site-packages/Sphinx-1.0.4-py2.7.egg', 
This proves you have a second python installation.

Here is what to do:
using virtualenv, create yourself a virtual python environment. (sudo pip install virtualenv, virtualnev my_experiments --no-site-packages, source my_experiments/bin/activate).
Using the pip in that environment (my_experiments/bin/activate) you install pysam and whatever else you need.
Then, while having the environment active (that's what the source ... bin/activate does), you run your emigre.py

This should  give you a clean python microenvironment.
Reply all
Reply to author
Forward
0 new messages