英文:
pip install Python packages in Jupyter Notebook in a virtual environment
问题
我想在VS Code的虚拟环境中创建一个Jupyter Notebook。我想做不同类型的项目。为此,我尝试在VS Code内部创建一个虚拟环境,以便可以下载项目所需的包,如TensorFlow、PyTorch等。我想在Jupyter Notebook中进行这些项目,因为我也想要展示它们。
- 首先,在桌面上创建了一个文件夹。
[步骤1]:
- 将文件夹拖到VS Code窗口中。
[步骤2]:
- 创建了一个名为"Project1.ipynb"的Jupyter Notebook文件。
[步骤3]:
- 然后按Ctrl+Shift+P,并选择"> python:Create Environment" -> 输入"venv"和我拥有的Python版本作为解释器。
[步骤4]:
- 最后,将Jupyter Notebook文件移动到".venv"虚拟环境中。
- 我的问题是,我如何将特定的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.
- First, I created a folder in desktop.
[Step 1]:
- I dragged the folder on VS Code window.
[Step 2]:
- Created a Jupyter Notebook file called "Project1.ipynb"
[Step 3]:
- Then Ctrl+Shift+P, and chose "> python:Create Environment" -> Type "venv" and the later Python version that I have as interpreter
[Step 4]:
- At last, I moved the Jupyter Notebook file to ".venv" virtuasl environment.
-
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
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.
Another way is to run codes ! pip install packageName
in cells after choosing the python kernel.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论