我刚刚使用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
包:
答案 0 :(得分:1)
您正在执行sudo pip install py_vollib
,它正在根env。
如果你在ipython笔记本中做import py_vollib
或其他什么,该模块将无法使用。
尝试sudo python
,然后执行导入
或者
执行pip install py_vollib
然后执行python
并尝试import py_vollib