4

I'm new to Python and need to use a python-based tool called chromosomer that imports some python packages including bioformats. Bioformats has many modules including bed. On running chromosomer, I get the error:

smeeta:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import chromosomer
>>> from chromosomer.cli import bioformats
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/chromosomer/cli.py", line 8, in <module>
    import bioformats.bed
ImportError: No module named bed
>>> import bioformats
>>> import bioformats.bed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named bed
>>> 

How do I install the package chromosomer and its dependent packages ?

Meeta Sunil
  • 55
  • 1
  • 7
  • Thanks for the edit and the answers below; but I've already installed chromosomer and its dependencies using sudo -E pip install --index-url=http://pypi.python.org/simple/ -r requirements.txt. After doing this, I had to add /usr/local/lib/python2.7/dist-packages// to PYTHONPATH in my bashrc. I'm still getting the import error mentioned above.. – Meeta Sunil Dec 20 '16 at 06:37
  • 'from chromosomer.cli import chromosomer' worked fine for me, see last section of my answer. My suggestion here is, remove/uninstall the chromosomer package and also the path line from bashrc - then re-install it. – Nabeel Ahmed Dec 20 '16 at 07:46

3 Answers3

3

Use pip

E.g.

#>pip install <desired package>
#>pip install chromosomer

Official pip documentation link.

For Python 2.7.9+ and 3.4+ It should come preinstalled with pip

Python 2 ≤ 2.7.8 and Python 3 ≤ 3.3 Follow the instructions from here : https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip

For more discussion about this question: Does Python have a package/module management system?

Community
  • 1
  • 1
Ajeet Ganga
  • 8,353
  • 10
  • 56
  • 79
1

So in python most of things gets installed using the pip command ,recommended tool for installing Python packages.

Also did you tried :

pip install python-bioformats
Nishant Singh
  • 3,055
  • 11
  • 36
  • 74
0

For any packages other than default ones, you need to install them before import/using them.

The most common and convenient way for installing a Python package is via the pip package management utility.

1.Install pip:

sudo apt-get install python-pip  # for Debian/Ubuntu
sudo yum -y install python-pip  # for CentOS/RHEL

Note: For Python 2.7.9+ and 3.4+ pip comes pre-installed.


2.Install python packages:

sudo pip install chromosomer

It'll install bioinformats, future, pyfaidx, PyVCF, six packages as dependencies. Note: no need for sudo if already root user, or using a vitualenv.

Verification - can verify the installation using pip freeze command:

(venv_bioinformatics)[nahmed@localhost virtualenvs]$ pip freeze
bioformats==0.1.14
chromosomer==0.1.3
future==0.16.0
pyfaidx==0.4.8.1
PyVCF==0.6.8
six==1.10.0
wheel==0.24.0

Test - I installed the chromosomer and imported, worked fine:

(venv_bioinformatics)[nahmed@localhost virtualenvs]$ python 
Python 2.7.5 (default, Sep 15 2016, 22:37:39) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from chromosomer.cli import chromosomer
>>> 
Nabeel Ahmed
  • 18,328
  • 4
  • 58
  • 63
  • did you try the importing in Python shell ? and also tally the package versions with the ones I have shared, as it worked fine for me. – Nabeel Ahmed Dec 20 '16 at 06:48
  • Also, if I import just the package, it gets imported, but if I try to access a module, it throws up the error.. – Meeta Sunil Dec 20 '16 at 06:49
  • kindly, share the full session i.e the traceback(error) and the import statement causing the issues. Add it in the question as Edit 1: (below the current content) – Nabeel Ahmed Dec 20 '16 at 06:53
  • Yes, in Python shell, the packages are getting imported smoothly but not their modules.. `import ` doesn't give any error while `from import module` throws up the error.. And yes, the versions of most of the installed packages are same except six==1.5.2 and Python is 2.7.6.. – Meeta Sunil Dec 20 '16 at 06:56