来自Conda env的软件包在Jupyer Notebook中找不到

Ber*_*rdL 11 python ipython jupyter-notebook

我创建了一个名为imagescraper的环境,并用它安装了pip.

然后我继续使用pip来安装一个名为ImageScraper的包;

>>activate imagescraper
[imagescraper]>>pip install ImageScraper
Run Code Online (Sandbox Code Playgroud)

只是为了确保我已成功安装包:

>>conda list

[imagescraper] C:\Users\John>conda list
# packages in environment at C:\Anaconda2\envs\imagescrap
#
future                    0.15.2                    <pip>
imagescraper              2.0.7                     <pip>
lxml                      3.6.0                     <pip>
numpy                     1.11.0                    <pip>
pandas                    0.18.0                    <pip>
pip                       8.1.1                    py27_1
python                    2.7.11                        4
python-dateutil           2.5.2                     <pip>
pytz                      2016.3                    <pip>
requests                  2.9.1                     <pip>
setproctitle              1.1.9                     <pip>
setuptools                20.3                     py27_0
simplepool                0.1                       <pip>
six                       1.10.0                    <pip>
vs2008_runtime            9.00.30729.1                  0
wheel                     0.29.0                   py27_0
Run Code Online (Sandbox Code Playgroud)

在我推出Jupyter笔记本之前,只需检查我们从哪里获取路径:

[imagescraper] C:\Users\John>python
Python 2.7.11 |Continuum Analytics, Inc.| (default, Feb 16 2016, 09:58:36) [MSC
v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import sys
>>> sys.executable
'C:\\Anaconda2\\envs\\imagescraper\\python.exe'
>>> import image_scraper
Run Code Online (Sandbox Code Playgroud)

似乎没问题,所以我继续使用推出Jupyter笔记本

[imagescraper]>>jupyter notebook
Run Code Online (Sandbox Code Playgroud)

在笔记本中我创作了一本新书,当我尝试同样的时候;

import image_scraper
Run Code Online (Sandbox Code Playgroud)

我回来了:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-6c2b65c9cdeb> in <module>()
----> 1 import image_scraper

ImportError: No module named image_scraper
Run Code Online (Sandbox Code Playgroud)

做同样的事情来检查Jupyter笔记本中的路径,我得到了这个;

import sys

sys.executable

'C:\\Anaconda2\\python.exe'
Run Code Online (Sandbox Code Playgroud)

这告诉我它并不是指我安装模块的环境.

有没有办法可以确保我的笔记本都引用自己的env包?

cel*_*cel 15

这有两种可能的解决方案:

您可以根据您的imagescraper环境注册新内核.内核将从imagescraper环境开始,从而查看其所有包.

source activate imagescraper
conda install ipykernel
ipython kernel install --name imagescraper
Run Code Online (Sandbox Code Playgroud)

这将添加一个名为imagescraperjupyter仪表板的新内核.


另一种解决方案是将jupyter笔记本安装到imagescraper环境中并从环境中启动jupyter.这需要imagescraper在您启动jupyter笔记本时激活.

source activate imagescraper
conda install notebook
jupyter notebook
Run Code Online (Sandbox Code Playgroud)