简体   繁体   English

pip 安装未安装到 virtualenv

[英]pip installing does not install to virtualenv

I'm very new to all of this, so bear with me.我对这一切都很陌生,所以请耐心等待。

I started, and activated, a virtual environment.我启动并激活了一个虚拟环境。 But when I pip install anything, it installs to the computer, not the the virtual env.但是当我 pip 安装任何东西时,它会安装到计算机上,而不是虚拟环境中。

I'm on a Mac, trying to build a Django website.我在 Mac 上,试图建立一个 Django 网站。

Example: With the virtual machine activated.示例:激活虚拟机。 I type:我输入:

python -m pip install Django

Then I can deactivate the virtual env, and type:然后我可以停用虚拟环境,然后输入:

pip freeze

And it will list out the freshly installed version of Django.它将列出新安装的 Django 版本。

Any clue as to why this is happening?关于为什么会发生这种情况的任何线索?

Run this line from your project folder where "env" is your virtual enviroment从您的项目文件夹中运行此行,其中“env”是您的虚拟环境

# A virtualenv's python:
$ env/bin/python -m pip install django

If you want to install to your virtualenvironment you have to activate it, otherwise it will install to the main folder.如果你想安装到你的虚拟环境,你必须激活它,否则它将安装到主文件夹。

Confirm you're in the virtual environment by checking the location of your Python interpreter, it should point to the env directory.通过检查 Python 解释器的位置来确认您在虚拟环境中,它应该指向 env 目录。

On macOS and Linux:在 macOS 和 Linux 上:

which python
.../env/bin/python

As long as your virtual environment is activated pip will install packages into that specific environment and you'll be able to import and use packages in your Python application.只要您的虚拟环境被激活,pip 就会将软件包安装到该特定环境中,您就可以在 Python 应用程序中导入和使用软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM