python - 使用 pip 将 Python 包安装到不同的目录中?

标签 python pip

我知道显而易见的答案是使用 virtualenv 和 virtualenvwrapper,但由于各种原因我不能/不想这样做。

那么如何修改命令

pip install package_name

要让 pip 将包安装到默认 site-packages 以外的其他位置?

最佳答案

--target switch 就是你要找的东西:

pip install --target=d:\somewhere\other\than\the\default package_name

但您仍然需要将 d:\somewhere\other\than\the\default 添加到 PYTHONPATH 才能从该位置实际使用它们。

-t, --target <dir>
Install packages into <dir>. By default this will not replace existing files/folders in <dir>.
Use --upgrade to replace existing packages in <dir> with new versions.


如果目标开关不可用,则升级 pip:

在 Linux 或 OS X 上:

pip install -U pip

在 Windows 上(这适用于 an issue ):

python -m pip install -U pip

关于python - 使用 pip 将 Python 包安装到不同的目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2915471/

相关文章:

python-3.x - 使用自动配置脚本进行代理设置时使用 pip install

python-2.7 - 使用 pip 和 python 2.7 在 Windows 7 上安装 lxml

python - 用于特征选择的详尽网格搜索

python - 奇运算符优先级/关联行为

python - 如何在Python中传递任意参数

c# - 如何公开 Amazon EC2 实例的进程状态

python - 安装 simplejson 后没有名为 'json' 的模块

python - 使用 stdin/stdout 通过 Python 子进程与 smbpasswd 通信

python - Theano 属性错误: 'module' object has no attribute 'relu'

python-3.x - 用于设置 virtualenv 和 pip 的 Shell 脚本