[英]How to import python packages?
I'm new to Python and need to use a python-based tool called chromosomer that imports some python packages including bioformats. 我是Python的新手,需要使用一个名为chromosomer的基于python的工具,它可以导入一些python包,包括bioformats。 Bioformats has many modules including bed.
Bioformats有许多模块,包括床。 On running chromosomer, I get the error:
在运行chromosomer时,我收到错误:
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 ? 如何安装包装chromosomer及其相关包?
Use pip
使用
pip
Eg 例如
#>pip install <desired package>
#>pip install chromosomer
Official pip
documentation link . 官方
pip
文档链接 。
For Python 2.7.9+ and 3.4+ It should come preinstalled with pip
对于Python 2.7.9+和3.4+它应该预先安装
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 Python2≤2.7.8和Python3≤3.3按照此处的说明操作: 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? 有关此问题的更多讨论: Python是否有包/模块管理系统?
So in python most of things gets installed using the pip
command ,recommended tool for installing Python packages. 因此在python中,大多数东西都是使用
pip
命令安装的,这是一个用于安装Python包的推荐工具。
Also did you tried : 你也尝试过:
pip install python-bioformats
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. 安装Python包的最常见和最方便的方法是通过
pip
包管理实用程序。
1. Install pip : 1. 安装点子 :
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. 注意 :对于Python 2.7.9+和3.4+
pip
预安装。
2. Install python packages : 2. 安装python包 :
sudo pip install chromosomer
It'll install bioinformats
, future
, pyfaidx
, PyVCF
, six
packages as dependencies. 它将安装
bioinformats
, future
, pyfaidx
, PyVCF
, six
包作为依赖项。 Note : no need for sudo
if already root
user, or using a vitualenv
. 注意 :如果已经是
root
用户,或者使用vitualenv
,则不需要sudo
。
Verification - can verify the installation using pip freeze
command: 验证 - 可以使用
pip freeze
命令验证安装:
(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
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.