2014-09-26 193 views
9

我正在使用python version 2.7pip version is 1.5.6pip安裝依賴關係鏈接

我想從url安裝額外的庫,就像正在安裝setup.py的git repo。

我在setup.pyinstall_requires參數中加入臨時演員。這意味着,我的圖書館需要額外的圖書館,他們也必須安裝。

... 
install_requires=[ 
    "Django", 
    .... 
], 
... 

但網址像git的回購協議是setup.pyinstall_requires無效的字符串。假設我想從github安裝一個庫。我已經搜索了關於這個問題,我發現了一些我可以把圖書館,在dependency_linkssetup.py。但這仍然行不通。這是我的依賴鏈接定義;

dependency_links=[ 
    "https://github.com/.../tarball/master/#egg=1.0.0", 
    "https://github.com/.../tarball/master#egg=0.9.3", 
], 

鏈接有效。我可以通過這些網址從互聯網瀏覽器下載它們。這些額外的庫仍未安裝我的設置。我也嘗試--process-dependency-links參數來強制點。但結果是一樣的。翻車時我不會錯。

安裝後,我看到pip freeze沒有庫,導致dependency_links

如何使用我的setup.py安裝程序下載它們?

編輯:

這裏是我的完整setup.py

from setuptools import setup 

try: 
    long_description = open('README.md').read() 
except IOError: 
    long_description = '' 

setup(
    name='esef-sso', 
    version='1.0.0.0', 
    description='', 
    url='https://github.com/egemsoft/esef-sso.git', 
    keywords=["django", "egemsoft", "sso", "esefsso"], 
    install_requires=[ 
     "Django", 
     "webservices", 
     "requests", 
     "esef-auth==1.0.0.0", 
     "django-simple-sso==0.9.3" 
    ], 
    dependency_links=[ 
     "https://github.com/egemsoft/esef-auth/tarball/master/#egg=1.0.0.0", 
     "https://github.com/egemsoft/django-simple-sso/tarball/master#egg=0.9.3", 
    ], 

    packages=[ 
     'esef_sso_client', 
     'esef_sso_client.models', 
     'esef_sso_server', 
     'esef_sso_server.models', 
    ], 
    include_package_data=True, 
    zip_safe=False, 
    platforms=['any'], 
) 

編輯2:

這裏是PIP日誌;

Downloading/unpacking esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 
    Getting page https://pypi.python.org/simple/esef-auth/ 
    Could not fetch URL https://pypi.python.org/simple/esef-auth/: 404 Client Error: Not Found 
    Will skip URL https://pypi.python.org/simple/esef-auth/ when looking for download links for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 
    Getting page https://pypi.python.org/simple/ 
    URLs to search for versions for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0): 
    * https://pypi.python.org/simple/esef-auth/1.0.0.0 
    * https://pypi.python.org/simple/esef-auth/ 
    Getting page https://pypi.python.org/simple/esef-auth/1.0.0.0 
    Could not fetch URL https://pypi.python.org/simple/esef-auth/1.0.0.0: 404 Client Error: Not Found 
    Will skip URL https://pypi.python.org/simple/esef-auth/1.0.0.0 when looking for download links for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 
    Getting page https://pypi.python.org/simple/esef-auth/ 
    Could not fetch URL https://pypi.python.org/simple/esef-auth/: 404 Client Error: Not Found 
    Will skip URL https://pypi.python.org/simple/esef-auth/ when looking for download links for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 
    Could not find any downloads that satisfy the requirement esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 
Cleaning up... 
    Removing temporary dir /Users/ahmetdal/.virtualenvs/esef-sso-example/build... 
No distributions at all found for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 
Exception information: 
Traceback (most recent call last): 
    File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main 
    status = self.run(options, args) 
    File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/commands/install.py", line 278, in run 
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) 
    File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/req.py", line 1177, in prepare_files 
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade) 
    File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/index.py", line 277, in find_requirement 
    raise DistributionNotFound('No distributions at all found for %s' % req) 
DistributionNotFound: No distributions at all found for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0) 

看來,它並不使用dependency_links中的來源。

回答

7

您需要確保您的依賴項也包含在您的install_requires中。

下面是一個例子setup.py

#!/usr/bin/env python 
from setuptools import setup 

setup(
    name='foo', 
    version='0.0.1', 
    install_requires=[ 
     'balog==0.0.7' 
    ], 
    dependency_links=[ 
     'https://github.com/balanced/balog/tarball/master#egg=balog-0.0.7' 
    ] 
) 

這裏的問題,你的榜樣setup.py

你在依賴你的鏈接設置中缺少的雞蛋名稱。

你有

https://github.com/egemsoft/esef-auth/tarball/master/#egg=1.0.0.0

你需要

https://github.com/egemsoft/esef-auth/tarball/master/#egg=esef-auth-1.0.0.0

+1

它說'找不到滿足要求的任何下載my-extra-libraray == 1.0.0.0(來自my-installed-library-currently == 1.0.0.0)' – 2014-09-28 17:19:10

+0

@AhmetDAL你有兩個依賴鏈接並安裝需要指定?你可以發佈你正在使用的完整的'setup.py'嗎? – mjallday 2014-09-28 18:33:32

+0

請參閱我的問題的編輯部分。 – 2014-10-01 12:57:07

14

皮普除去dependency_links而回的支持。latest version of pip that supports dependency_links is 1.3.1,安裝它

pip install pip==1.3.1 

您的依賴關係鏈接應該在這一點上工作。請注意,這個dependency_links總是最後的手段,即點。如果一個名稱相同的軟件包存在於pypi上,它將被選中而不是你的。

注意,https://github.com/pypa/pip/pull/1955似乎開始允許dependency_links,pip保留它,但您可能需要使用某些命令行開關才能使用較新版本的pip。

編輯:從點7開始......他們重新考慮了dep鏈接,並且已經使他們能夠在他們似乎留在這裏的討論中,即使他們沒有取消棄用通知。 pip> = 7這裏是您如何安裝東西

pip install -e . --process-dependency-links --allow-all-external 

或者將以下內容添加到pip.conf中,例如: /etc/pip.conf

[install] 
process-dependency-links = yes 
allow-all-external = yes 
trusted-host = 
    bitbucket.org 
    github.com 

編輯

我已經學了一招就是撞了版本號的東西實在是高,以確保PIP不喜歡非依賴性鏈接版本(如果那是後話你要)。從上面的例子中,使依賴鏈接的樣子:

"https://github.com/egemsoft/django-simple-sso/tarball/master#egg=999.0.0", 

還要確保版本無論是看起來像例子或者是最新版本,其他版本將PIP認爲它是一個開發版本,並不會安裝。

+0

看起來這不是更多的情況?據我所知,最新的點支持dependency_links。 – yelsayed 2017-01-11 23:01:56

+0

您仍然會看到警告,但是dependency_links將保留一段時間。就我所知,您仍然需要配置,請參閱答案的編輯部分中的註釋。 – Pykler 2017-01-16 15:18:18

+0

也許你應該刪除關於pip版本1.3.1的信息它是非常舊的 – 2017-08-23 15:23:26

1

我遇到過類似的情況,我想使用shapely作爲我的包依賴項之一。然而,身材勻稱的人有一個警告,如果你使用Windows,你必須使用http://www.lfd.uci.edu/~gohlke/pythonlibs/的.whl文件。否則,你必須安裝一個C編譯器,這是我不想要的。我希望用戶只需使用pip install mypackage而不是安裝一堆其他的東西。

如果你有典型的設置與dependency_links

setup(
    name = 'streettraffic', 
    packages = find_packages(), # this must be the same as the name above 
    version = '0.1', 
    description = 'A random test lib', 
    author = 'Costa Huang', 
    author_email = '[email protected]', 
    install_requires=['Shapely==1.5.17'], 
    dependency_links = ['http://www.lfd.uci.edu/~gohlke/pythonlibs/ru4fxw3r/Shapely-1.5.17-cp36-cp36m-win_amd64.whl'] 
) 

和運行python setup.py install,它只是會挑身材勻稱PyPI上,並導致在Windows上安裝的麻煩。經過數小時的研究,我發現這個鏈接Force setuptools to use dependency_links to install mysqlclient和基本上使用from setuptools.command.install import install as _install手動安裝形狀。

from setuptools.command.install import install as _install 
from setuptools import setup, find_packages 
import pip 

class install(_install): 
    def run(self): 
    _install.do_egg_install(self) 

    # just go ahead and do it 
    pip.main(['install', 'http://localhost:81/Shapely-1.5.17-cp36-cp36m-win_amd64.whl']) 

setup(
    name = 'mypackage', 
    packages = find_packages(), # this must be the same as the name above 
    version = '0.1', 
    description = 'A random test lib', 
    author = 'Costa Huang', 
    author_email = '[email protected]', 
    cmdclass={'install': install} 
) 

而且該腳本很好地工作。希望能幫助到你。