Python 为 jupyter notebook 安装库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44800223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install library for jupyter notebook
提问by Kenenbek Arzymatov
I start my jupyter
notebook with python2
as:
我以以下方式开始我的jupyter
笔记本python2
:
jupyter notebook nameofnotebook
jupyter notebook nameofnotebook
Then I want to import library like this:
然后我想像这样导入库:
import scipy
import scipy
But I have an error telling that there is no such library.
但是我有一个错误,告诉我没有这样的库。
So I execute in the notebook
cell:
所以我在notebook
单元格中执行:
!pip2 install scipy
Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages
How to install package correctly to jupyter kernel?
如何将软件包正确安装到 jupyter 内核?
回答by vishes_shell
@h?ken-lidis right. There are probably several versions of python. So to install your package to python where your jupyter
is located:
@h?ken-lid是对的。可能有几个版本的python。因此,要将您的软件包安装到您所在的python jupyter
:
$ which jupyter
/YOURPATH/bin/jupyter
$ /YOURPATH/bin/pip install scipy
This will do for Python 2.x
这适用于Python 2.x
For Python 3.xpip3
will be in /YOURPATH/bin
instead of single pip
对于Python 3.xpip3
将在/YOURPATH/bin
而不是单个pip
回答by H?ken Lid
You can run pip from python.
您可以从 python 运行 pip。
import pip
pip.main(['install', 'scipy'])
If you are using the system python, and running jupyter in a process that doesn't have permission to install global packages, you can use the --user
flag to install a module for the current user only.
如果您使用系统 python,并且在没有权限安装全局包的进程中运行 jupyter,则可以使用该--user
标志仅为当前用户安装模块。
pip.main(['install', '--user', 'scipy'])