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

那么如何修改命令呢

pip install package_name

让PIP在默认的site-packages之外的地方安装这个包?


当前回答

有时它只对Cache参数有效

-m pip install -U pip --target=C:\xxx\python\lib\site-packages Pillow --cache-dir C:\tmp

其他回答

在@Ian Bicking的回答上再加一点:

如果想在远程服务器上的主目录(没有sudo用户权限)中安装一些Python包,使用——user选项指定安装目录也可以。

例如,

pip install --user python-memcached

该命令将包安装到PYTHONPATH中列出的目录之一。

我建议按照文档创建~/.pip/pip.conf文件。注意在文档中缺少指定的头目录,这将导致以下错误:

error: install-base or install-platbase supplied, but installation scheme is incomplete

conf文件的完整工作内容是:

[install]
install-base=$HOME
install-purelib=python/lib
install-platlib=python/lib.$PLAT
install-scripts=python/scripts
install-headers=python/include
install-data=python/data

不幸的是,我可以安装,但当尝试卸载pip告诉我没有这样的软件包卸载过程....所以还是有问题,但是包会回到预定义的位置。

新版本的pip(8或更高版本)可以直接使用——prefix选项:

pip install --prefix=$PREFIX_PATH package_name

其中$PREFIX_PATH是lib、bin和其他顶级文件夹所在的安装前缀。

为了将库安装在我想要的位置,我导航到我想要的带有终端的目录的位置

pip install mylibraryName -t . 

我的逻辑是从这一页:https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download

pip install packageName -t pathOfDirectory

or

pip install packageName --target pathOfDirectorty