Mik*_*ski 34 python ipython anaconda jupyter jupyter-notebook
当我!pip install geocoder在Jupyter Notebook中运行时,我获得与pip install geocoder在终端中运行相同的输出,但是当我尝试导入时,地理编码器包不可用.
我正在使用Ubuntu 14.04,Anaconda 4.0.0和pip 8.1.2
安装地理编码器:
!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
Run Code Online (Sandbox Code Playgroud)
然后尝试导入它:
import geocoder
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-603a981d39f2> in <module>()
----> 1 import geocoder
ImportError: No module named geocoder
Run Code Online (Sandbox Code Playgroud)
我也尝试关闭笔记本电脑并重新启动它,没有任何运气.
编辑:我发现使用终端在/home/ubuntu/.local/lib/python2.7/site-packages中安装地理编码器包并使用笔记本将其安装在/usr/local/lib/python2.7/dist-中不在路径中的包.sys.path.append('/usr/local/lib/python2.7/dist-packages')解决了当前会话的问题.
那么如何永久修改路径或告诉pip安装地理编码器的位置?
小智 34
! pip install --user <package>
Run Code Online (Sandbox Code Playgroud)
该!通知笔记本执行单元作为shell命令.
Epo*_*ous 21
在IPython(jupyter)7.3和更高版本中,有一个魔术%pip和%conda命令可以安装到当前内核中(而不是安装到启动笔记本的Python实例中)。
%pip install geocoder
Run Code Online (Sandbox Code Playgroud)
在早期版本中,您需要使用sys来解决问题,例如FlyingZebra1的回答
import sys
!{sys.executable} -m pip install geocoder
Run Code Online (Sandbox Code Playgroud)
%pip install fedex #fedex = package name
Run Code Online (Sandbox Code Playgroud)
在2019年。
在较旧版本的conda中:
import sys
!{sys.executable} -m pip install fedex #fedex = package name
Run Code Online (Sandbox Code Playgroud)
*注意-您确实需要导入sys
| 归档时间: |
|
| 查看次数: |
71995 次 |
| 最近记录: |