【问题标题】:Python can't find packages installed with pipPython 找不到用 pip 安装的包
【发布时间】:2018-03-16 11:02:58
【问题描述】:

在 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。

【问题讨论】:

    标签: macos python-3.x pip


    【解决方案1】:

    我们在使用一些python模块的时候,一般会写成&gt;&gt;&gt; import module。例如,&gt;&gt;&gt; import urllib3。但是,包括 biopython 在内的一些软件包不在此规则范围内。您尝试输入&gt;&gt;&gt; import Bio&gt;&gt;&gt; print(Bio.__version__)。请在http://biopython.org/DIST/docs/tutorial/Tutorial.html查看更多详细信息。

    --原始答案--

    请尝试输入以下脚本:

    >>import sys
    >>print(sys.path)
    

    我认为只有/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages的模块路径不是python2

    如果您想暂时解决此问题,请使用以下方法:

    >>sys.path.append("/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages")
    

    如果您总是使用 python3,请在 ~/.bash_profile 中定义 PYTHONPATH 并重新启动终端:

    PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages:$PYTHONPATH
    

    【讨论】:

    • >>> import sys>>> print(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']
    • 我误解了什么是 biopython。当我们使用一些python模块时,我们通常写&gt;&gt;&gt; import module。例如,&gt;&gt;&gt; import urllib3。但是,包括 biopython 在内的一些软件包不在此规则范围内。您尝试输入&gt;&gt;&gt; import Bio&gt;&gt;&gt; print(Bio.__version__)。请在http://biopython.org/DIST/docs/tutorial/Tutorial.html查看更多详细信息。
    • 非常感谢,我应该阅读文档。我尝试使用 Pillow 作为测试并得到相同的结果,但没有意识到该包也以不同的名称导入。
    猜你喜欢
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 2020-04-14
    • 2012-10-09
    • 1970-01-01
    相关资源
    最近更新 更多