当我在Jupyter Notebook中运行!pip install geocoder
时,输出结果与在终端中运行pip install geocoder
的结果相同,但是当我尝试导入它时,geocoder包不可用。
我正在使用Ubuntu 14.04,Anaconda 4.0.0和pip 8.1.2。
安装geocoder:
!pip install geocoder
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting geocoder
Downloading geocoder-1.15.1-py2.py3-none-any.whl (195kB)
100% |████████████████████████████████| 204kB 3.2MB/s
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): ratelim in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): click in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): decorator in /usr/local/lib/python2.7/dist-packages/decorator-4.0.10-py2.7.egg (from ratelim->geocoder)
Installing collected packages: geocoder
Successfully installed geocoder-1.15.1
然后尝试进行导入:
import geocoder
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-603a981d39f2> in <module>()
----> 1 import geocoder
ImportError: No module named geocoder
我也试过关闭笔记本电脑并重新启动它,但没有成功。
编辑: 我发现使用终端安装geocoder包会将其安装在/home/ubuntu/.local/lib/python2.7/site-packages
中,而使用笔记本电脑安装则会将其安装在/usr/local/lib/python2.7/dist-packages
中,而此路径不在路径中。sys.path.append('/usr/local/lib/python2.7/dist-packages')
解决了当前会话中的问题。
那么,我该如何永久修改路径或告诉pip在哪里安装geocoder呢?
PYTHONPATH
- Konstantin