Python无法找到使用pip安装的软件包。

3

在Mac上,尝试设置Python 3.6。

Sams-MacBook-Pro:~ samgreenberg$ which pip3
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3
Sams-MacBook-Pro:~ samgreenberg$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

那么

Sams-MacBook-Pro:~ samgreenberg$ pip3 list
DEPRECATION: The default format will switch to columns in the future. 

You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
biopython (1.70)
certifi (2017.7.27.1)
chardet (3.0.4)
cycler (0.10.0)
decorator (4.1.2)
idna (2.6)
ipython-genutils (0.2.0)
jsonschema (2.6.0)
jupyter-core (4.3.0)
matplotlib (2.0.2)
nbformat (4.4.0)
numpy (1.13.1)
olefile (0.44)
Pillow (4.3.0)
pip (9.0.1)
plotly (2.0.15)
pyparsing (2.2.0)
python-dateutil (2.6.1)
pytz (2017.2)
requests (2.18.4)
setuptools (28.8.0)
six (1.10.0)
traitlets (4.3.2)
urllib3 (1.22)

所以,biopython似乎已安装。
Sams-MacBook-Pro:~ samgreenberg$ python3 -m pip install biopython
Requirement already satisfied: biopython in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from biopython)

已经成功安装。

Sams-MacBook-Pro:~ samgreenberg$ python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>> import biopython
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'biopython'
>>> 

urllib3可以正常工作,但新安装的包却不能。使用pip卸载并重新安装没有效果,在尝试其他随机包时也出现了同样的结果。我做错了什么?我对Python或OSX并不是特别有经验。我的电脑预装了Python 2.7,但我在命令中小心地使用了Python3。

1个回答

2
当我们使用一些Python模块时,通常会写>>> import module。例如,>>> import urllib3。但是,有些包,包括biopython在内,不符合这个规则。您可以尝试输入>>> import Bio>>> print(Bio.__version__)。请在http://biopython.org/DIST/docs/tutorial/Tutorial.html查看更多详细信息。
>>import sys
>>print(sys.path)

我认为只有 python2 的模块路径,而没有 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
如果你想临时解决这个问题,请使用以下方法:
>>sys.path.append("/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages")

请在~/.bash_profile中定义PYTHONPATH并重新启动终端,如果您经常使用python3:
PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages:$PYTHONPATH


导入 sys>>> 打印(sys.path) ['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib- dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages']
- Sam
我曾经误解了什么是biopython。当我们使用一些Python模块时,通常会写成 >>> import module 的形式。例如,>>> import urllib3。但是,有些包,包括biopython在内,不适用于这个规则。你需要尝试输入 >>> import Bio>>> print(Bio.__version__)。请查看更多详细信息,请访问http://biopython.org/DIST/docs/tutorial/Tutorial.html。 - montblanc18
非常感谢,我应该先阅读文档。我尝试使用Pillow进行测试,但由于不知道该软件包还有另一个名称,所以结果相同。 - Sam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接