【问题标题】:Packages from Conda env not found in Jupyer Notebook在 Jupyter Notebook 中找不到来自 Conda env 的包
【发布时间】:2016-07-22 19:19:59
【问题描述】:

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

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

>>activate imagescraper
[imagescraper]>>pip install ImageScraper

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

>>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

在我启动 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

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

[imagescraper]>>jupyter notebook

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

import image_scraper

我回来了:

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

ImportError: No module named image_scraper

用同样的方法检查 Jupyter notebook 中的路径,我明白了;

import sys

sys.executable

'C:\\Anaconda2\\python.exe'

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

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

【问题讨论】:

  • 是的,你要么:在imagescraper 环境中安装 ipykernel。您可以在这里使用我的答案作为模板:stackoverflow.com/questions/30492623/…。或者:在 imagescraper 环境中安装 jupyter 并从该环境启动 jupyter。
  • 谢谢你帮我解决了!
  • @cel 您应该将其扩展为答案:-)

标签: python jupyter-notebook anaconda ipython


【解决方案1】:

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

您可以根据您的imagescraper 环境注册一个新内核。内核将从imagescraper 环境启动,因此可以看到它的所有包。

source activate imagescraper
conda install ipykernel
ipython kernel install --name imagescraper

这会将名为 imagescraper 的新内核添加到您的 jupyter 仪表板。


另一种解决方案是将jupyter notebook 安装到imagescraper 环境中,并从该环境中启动jupyter。这需要在您启动 jupyter notebook 时激活 imagescraper

source activate imagescraper
conda install notebook
jupyter notebook

【讨论】:

  • 谢谢!我更喜欢在我所有单独的环境中安装 jupyter。像魅力一样工作。
猜你喜欢
  • 2021-02-21
  • 1970-01-01
  • 2020-08-13
  • 1970-01-01
  • 2019-07-09
  • 1970-01-01
  • 2018-07-31
  • 2021-07-25
  • 2019-02-05
相关资源
最近更新 更多