Pip本身是一个Python包,实际的pip命令只是运行一个小的Python脚本,然后导入并运行pip包。
您可以编辑locations.py来更改安装目录,但是,如上所述,我建议您不要这样做,我建议您使用高度。
皮普命令
皮普接受一个标志, '--install选项= “ - 安装脚本”,',它可以用来更改安装目录:
pip install somepackage --install-option="--install-scripts=/usr/local/bin"
源方法
论PIP/locations.py线124,我们看到了以下内容:
site_packages = sysconfig.get_python_lib()
user_site = site.USER_SITE
您可以在技术上编辑这些以更改默认安装路径,但是,使用虚拟环境将是非常可取的。然后这用于查找egglink路径,然后找到dist路径(下面的代码,从pip/__init__.py
)。
def egg_link_path(dist):
"""
Return the path for the .egg-link file if it exists, otherwise, None.
There's 3 scenarios:
1) not in a virtualenv
try to find in site.USER_SITE, then site_packages
2) in a no-global virtualenv
try to find in site_packages
3) in a yes-global virtualenv
try to find in site_packages, then site.USER_SITE
(don't look in global location)
For #1 and #3, there could be odd cases, where there's an egg-link in 2
locations.
This method will just return the first one found.
"""
sites = []
if running_under_virtualenv():
if virtualenv_no_global():
sites.append(site_packages)
else:
sites.append(site_packages)
if user_site:
sites.append(user_site)
else:
if user_site:
sites.append(user_site)
sites.append(site_packages)
for site in sites:
egglink = os.path.join(site, dist.project_name) + '.egg-link'
if os.path.isfile(egglink):
return egglink
def dist_location(dist):
"""
Get the site-packages location of this distribution. Generally
this is dist.location, except in the case of develop-installed
packages, where dist.location is the source code location, and we
want to know where the egg-link file is.
"""
egg_link = egg_link_path(dist)
if egg_link:
return egg_link
return dist.location
然而,再次使用的virtualenv更加溯源,任何皮普更新将覆盖这些变化,不像自己的virtualenv。
你为什么要这么做?把你的软件包和你的软件包放在@frlan的本地virtualenv – frlan
表示同意,这是一个更好的主意,但我认为atm对我来说更容易做升级,而不是教16个用户如何使用virtualenv;我无法进行分发升级,因为'yum' –
$ virtualenv使用了系统默认值,所以我无法升级。其次是bin/python对你来说是多么的类?使用pip全局安装软件包并不是一个好主意 – frlan