[英]How do I specify which python and which modules are being used in my jupyter notebook?
When I do 当我做
import sys
sys.executable
I get '/usr/local/opt/python/bin/python2.7'
in my ordinary python shell and '/usr/bin/python'
in IPython or my jupyter notebook. 我在普通的python shell中得到了
'/usr/local/opt/python/bin/python2.7'
,在IPython或jupyter笔记本中得到了'/usr/local/opt/python/bin/python2.7'
'/usr/bin/python'
。 I would like to force my jupyter notebook to use this same python that the shell is using. 我想强制我的jupyter笔记本使用外壳程序使用的同一Python。 I have installed many modules and would like to be able to use the same ones in jupyter than I am using already in the shell.
我已经安装了许多模块,并且希望能够在jupyter中使用与我已经在shell中使用的模块相同的模块。 How can I do this?
我怎样才能做到这一点?
The simplest way is to install IPython and Jupyter with the Python you want them to use. 最简单的方法是使用您希望它们使用的Python安装IPython和Jupyter。 You can do this using pip:
您可以使用pip执行此操作:
path/to/python -m pip install jupyter
You could alternatively set up the IPython kernel to run with your desired Python without reinstalling the notebook. 您可以选择将IPython内核设置为与所需的Python一起运行,而无需重新安装笔记本。 See the docs on installing kernels .
请参阅有关安装内核的文档 。 This is more complicated than just installing everything again, though.
但是,这比再次安装所有内容要复杂得多。
I had the same problem when using jupyter from a virtualenv. 使用来自virtualenv的jupyter时,我遇到了同样的问题。
In my case I had two kernels named python3 . 就我而言,我有两个名为python3的内核。 Doing a
jupyter kernelspec list
it reported only one kernel named python3 that pointed to an incorrect binary. 做一份
jupyter kernelspec list
它只报告了一个名为python3的 内核 ,该内核指向错误的二进制文件。 I removed it using jupyter kernelpec remove python3
and magically appeared the correct one pointing to my activated virtualenv. 我使用
jupyter kernelpec remove python3
删除了它,并神奇地出现了指向我激活的virtualenv的正确代码。
If you need to reinstall the kernel then, from the bin directory of the virtualenv you can do, 如果您需要重新安装内核,则可以从 virtualenv 的bin目录中执行操作,
./python -m pip install ipykernel sudo ./python -m ipykernel install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.