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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:28:44  来源:igfitidea点击:

Install library for jupyter notebook

pythonpippackagejupyter-notebook

提问by Kenenbek Arzymatov

I start my jupyternotebook with python2as:

我以以下方式开始我的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 notebookcell:

所以我在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 jupyteris 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.xpip3will be in /YOURPATH/bininstead 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 --userflag to install a module for the current user only.

如果您使用系统 python,并且在没有权限安装全局包的进程中运行 jupyter,则可以使用该--user标志仅为当前用户安装模块。

pip.main(['install', '--user', 'scipy'])