从Jupyter笔记本中安装pip包不起作用

从Jupyter笔记本中安装pip包不起作用

本文介绍了从Jupyter笔记本中安装pip包不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Jupyter Notebook中运行!pip install geocoder 时,我获得与运行 pip install geocoder 相同的输出当我尝试导入时,终端但地理编码包不可用。

When I run !pip install geocoder in Jupyter Notebook I get the same output as running pip install geocoder in the terminal but the geocoder package is not available when I try to import it.

我正在使用Ubuntu 14.04,Anaconda 4.0.0和pip 8.1.2

I'm using Ubuntu 14.04, Anaconda 4.0.0 and 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

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

I also tried shutting down the notebook and restarting it without any luck.

编辑:我发现使用终端在/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')解决了当前会话的问题。

I found that using the terminal installs the geocoder package in /home/ubuntu/.local/lib/python2.7/site-packages and using a notebook installs it in /usr/local/lib/python2.7/dist-packages which is not in the path. sys.path.append('/usr/local/lib/python2.7/dist-packages') solves the problem for the current session.

那么如何永久修改路径或告诉pip安装地理编码器的位置?

So how can I permanently modify the path or tell pip where to install geocoder?

推荐答案

! pip install --user <package>

告诉笔记本执行cell作为shell命令。

The ! tells the notebook to execute the cell as a shell command.

这篇关于从Jupyter笔记本中安装pip包不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:29