在 Windows 8 上,我有一个 Python 3 项目的以下结构:
../Project/
../Project/app/app.py
../Project/app/setup.py
在应用程序文件夹中,我调用以下命令来创建并进入虚拟环境:
pyvenv.py venv
cd venv\Scripts
activate.bat
cd ../..
现在我想将 Nose
单元测试框架安装到我的虚拟环境中:
pip install nose
... 并且 Nose 安装到全局文件夹中(在我的例子中,C:\Python33)。
当我调用 python setup.py install
时,我的自定义模块会安装到虚拟环境中。为什么 PIP 不这样做?
最佳答案
在关注 docs 后对我来说效果很好:
Common installation tools such as
Distribute
andpip
work as expected with venvs - i.e. when a venv is active, they install Python packages into the venv without needing to be told to do so explicitly. Of course, you need to install them into the venv first: this could be done by runningdistribute_setup.py
with the venv activated, followed by runningeasy_install pip
. Alternatively, you could download the source tarballs and runpython setup.py install
after unpacking, with the venv activated.
关于python - 如何让pip将包安装到虚拟环境中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19853855/