我知道显而易见的答案是使用 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/