首页 > 解决方案 > 使用 Pip 在不同的目录中安装测试 Python 包

问题描述

我有一个在生产中使用的 python distutils 模块。我在虚拟环境中安装了该生产模块。但是,我希望能够在生产环境中安装之前测试升级。我还试图避免创建第二个虚拟环境。因此我尝试了以下方法:

# inside my virtualenv
# checkout master of my repo
git clone git+git://github.com/myrepo
cd myrepo
# create directory where my testing install will live
mkdir testinstall
# prepend my testing install to the PYTHONPATH to over-ride the
# production install of my repo
export PYTHONPATH=$PWD/testinstall/lib/python2.7/site-packages:$PYTHONPATH
# install my local package with pip into the test area
pip install --prefix=$PWD/testinstall .

在这种情况下,我从 pip 得到错误:

Requirement already satisfied from /path/to/production/myrepo

如果我使用

pip install --upgrade --prefix=$PWD/testinstall

pip 继续从/path/to/production/myrepo该区域卸载生产版本并安装我的测试版本testinstall

知道如何强制 pip 以这种方式安装吗?

标签: pythonpipvirtualenv

解决方案


我只是使用一个新的 venv,但如果你真的不能,使用-t(target) 选项。

pip3 install --upgrade -t my_new_directory

推荐阅读