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