在Jupyter Notebook中在虚拟环境中安装Python包。

huangapple go评论72阅读模式
英文:

pip install Python packages in Jupyter Notebook in a virtual environment

问题

我想在VS Code的虚拟环境中创建一个Jupyter Notebook。我想做不同类型的项目。为此,我尝试在VS Code内部创建一个虚拟环境,以便可以下载项目所需的包,如TensorFlow、PyTorch等。我想在Jupyter Notebook中进行这些项目,因为我也想要展示它们。

  1. 首先,在桌面上创建了一个文件夹。
    [步骤1]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  2. 将文件夹拖到VS Code窗口中。
    [步骤2]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  3. 创建了一个名为"Project1.ipynb"的Jupyter Notebook文件。
    [步骤3]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  4. 然后按Ctrl+Shift+P,并选择"> python:Create Environment" -> 输入"venv"和我拥有的Python版本作为解释器。
    [步骤4]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  5. 最后,将Jupyter Notebook文件移动到".venv"虚拟环境中。
    在Jupyter Notebook中在虚拟环境中安装Python包。
  • 我的问题是,我如何将特定的Python包使用pip安装到该虚拟环境中,并仅在该特定虚拟环境中使用,而不是全局安装?
英文:

I would like to create a Jupyter Notebook in a virtual environment in VS Code. I want to do different kinds of projects. For that, I have tried to create a virtual environment inside VS Code, where I can download the required packages for the project i.e. TensorFlow, PyTorch... And I want to do those projects in a Jupyter Notebook because I also would like to present them.

  1. First, I created a folder in desktop.
    [Step 1]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  2. I dragged the folder on VS Code window.
    [Step 2]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  3. Created a Jupyter Notebook file called "Project1.ipynb"
    [Step 3]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  4. Then Ctrl+Shift+P, and chose "> python:Create Environment" -> Type "venv" and the later Python version that I have as interpreter
    [Step 4]:
    在Jupyter Notebook中在虚拟环境中安装Python包。
  5. At last, I moved the Jupyter Notebook file to ".venv" virtuasl environment.
    在Jupyter Notebook中在虚拟环境中安装Python包。
  • So my question is how can I pip install specific python packages to that virtual environment and use them just in that particular virtual environment and not globally ?

答案1

得分: 0

First: 激活你创建的环境。
在conda中,你可以像这样激活环境:"conda activate venv"

Second: 激活后,你可以直接使用pip安装包名称。
查看图像描述

英文:

First: Activate the environment that you created.
like in conda, you can activate the environment as "conda activate venv"

Second: after activation you can just do pip install package-name.
enter image description here

答案2

得分: 0

一种方法是在终端中在venv环境中安装包。

首先,通过类似Path\to\venv\active的命令激活你的venv环境。

然后,你可以使用命令pip install packageName来安装你想要的Python包。

最后,不要忘记在Jupyter中选择Python内核。

另一种方法是在选择Python内核后,在单元格中运行代码! pip install packageName

英文:

One way is to install package in venv environment in the terminal.

Firstly, active your venv environment by command like Path\to\venv\active

在Jupyter Notebook中在虚拟环境中安装Python包。

Then you can use command pip install packageName to install the python package you want.

Finally, don't forget to choose the python kernel in jupyter.

在Jupyter Notebook中在虚拟环境中安装Python包。

Another way is to run codes ! pip install packageName in cells after choosing the python kernel.

在Jupyter Notebook中在虚拟环境中安装Python包。

huangapple
  • 本文由 发表于 2023年5月24日 23:44:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定