问题描述
我创建了一个名为imagescraper的环境并用它安装了pip。
I created an environment called imagescraper and installed pip with it.
然后我继续使用pip来安装一个名为ImageScraper的包;
I then proceed to use pip to install a package called ImageScraper;
>>activate imagescraper
[imagescraper]>>pip install ImageScraper
为了确保我已成功安装包裹:
Just to ensure that I have the package successfully installed:
>>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笔记本,只是为了检查我们从哪里获得路径:
Before I launch Jupyter notebook, just to check where we are getting the path from:
[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
好了,所以我继续使用
[imagescraper]>>jupyter notebook
在笔记本中我创建了一本新书,当我尝试相同时;
Within the notebook I created a new book and when i tried the same;
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笔记本中的路径,我得到这个;
Doing the same to check the paths within Jupyter notebook, I get this;
import sys
sys.executable
'C:\\Anaconda2\\python.exe'
这告诉我它并不是指我安装模块的环境。
Which tells me that it is not referring to the environment where I installed the modules in.
有没有办法可以确保我的笔记本都引用自己的环境包?
Is there a way I can ensure that my notebooks all refer to its own env packages?
推荐答案
以下是两种可能的解决方案:
Here are two possible solutions:
你可以根据 imagescraper
环境注册新内核。内核将从 imagescraper
环境开始,因此可以看到它的所有包。
You can register a new kernel based on your imagescraper
environment. The kernel will start from the imagescraper
environment and thus sees all its packages.
source activate imagescraper
conda install ipykernel
ipython kernel install --name imagescraper
这将在你的jupyter仪表板中添加一个名为 imagescraper
的新内核。
This will add a new kernel named imagescraper
to your jupyter dashboard.
另一种解决方案是将jupyter笔记本安装到 imagescraper
环境中,并从环境中启动jupyter。这需要在你启动jupyter笔记本时激活 imagescraper
。
Another solution is to install jupyter notebook into the imagescraper
environment and start jupyter from the enviroment. This requires activating imagescraper
whenever you start jupyter notebook.
source activate imagescraper
conda install notebook
jupyter notebook
这篇关于来自Conda env的软件包在Jupyer Notebook中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!