【发布时间】:2018-01-21 06:04:39
【问题描述】:
我刚刚使用 pip 安装了一个 Python 包:
$ sudo pip install py_vollib
Password:
Collecting py_vollib
Downloading py_vollib-1.0.1.tar.gz
Collecting py_lets_be_rational (from py_vollib)
Downloading py_lets_be_rational-1.0.1.tar.gz
Requirement already satisfied: simplejson in /Library/Python/2.7/site-packages (from py_vollib)
Requirement already satisfied: numpy in /Library/Python/2.7/site-packages (from py_vollib)
Collecting pandas (from py_vollib)
Downloading pandas-0.20.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.0MB)
100% |████████████████████████████████| 15.1MB 54kB/s
Requirement already satisfied: scipy in /Library/Python/2.7/site-packages (from py_vollib)
Requirement already satisfied: pytz>=2011k in /Library/Python/2.7/site-packages (from pandas->py_vollib)
Requirement already satisfied: python-dateutil in /Library/Python/2.7/site-packages (from pandas->py_vollib)
Requirement already satisfied: six>=1.5 in /Library/Python/2.7/site-packages (from python-dateutil->pandas->py_vollib)
Installing collected packages: py-lets-be-rational, pandas, py-vollib
Running setup.py install for py-lets-be-rational ... done
Running setup.py install for py-vollib ... done
Successfully installed pandas-0.20.3 py-lets-be-rational-1.0.1 py-vollib-1.0.1
并且我已验证它已正确安装:
$ pip freeze | grep vollib
py-vollib==1.0.1
但我无法在 Python 中导入它:
$ python
Python 2.7.13 (default, Jul 20 2017, 18:14:09)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_vollib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py_vollib
有人知道我在这里做错了什么吗?
[编辑]
我查看了help('modules'),其中还显示了py_vollib 包:
【问题讨论】:
-
您的机器上是否安装了多个 Python? PATH 中最先出现的
pip可能与 PATH 中最先出现的 python 不同。我会比较pip --version、which pip和which python之类的输出,并确保它们都指向同一个位置。另外,请查看 Python 的 site-packages 目录,并确保有 py_vollib 的目录。 -
@GabeHackebeil - 我看过它,但即使从 Python
py_vollib查看help('modules')的输出也在那里(请参阅编辑的问题)。所以这应该告诉我它在我使用的Python中可用吗?
标签: python import package edit python-import