gpt4 book ai didi

python - 从 Jupyter Notebook 中安装 pip 包不起作用

转载 作者:IT老高 更新时间:2023-10-28 20:32:00 34 4
gpt4 key购买 nike

当我在 Jupyter Notebook 中运行 !pip install geocoder 时,我得到与在终端中运行 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

然后尝试导入:

import geocoder

---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-603a981d39f2> in <module>()
----> 1 import geocoder

ImportError: No module named geocoder

我也尝试关闭笔记本并重新启动它,但没有任何运气。

编辑:我发现使用终端会在 /home/ubuntu/.local/lib/python2.7/site-packages 中安装地理编码器包并使用notebook 将其安装在路径中的 /usr/local/lib/python2.7/dist-packages 中。 sys.path.append('/usr/local/lib/python2.7/dist-packages') 解决当前 session 的问题。

那么我怎样才能永久修改路径或告诉 pip 在哪里安装地理编码器?

最佳答案

在 IPython (jupyter) 7.3 及更高版本中,有一个神奇的 %pip%conda 命令将安装到当前内核中(而不是进入启动笔记本的 Python 实例)。

%pip install geocoder

在早期版本中,您需要使用 sys 来修复问题,如 the answer by FlyingZebra1

import sys
!{sys.executable} -m pip install geocoder

关于python - 从 Jupyter Notebook 中安装 pip 包不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38368318/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com