2014-09-26 35 views
9

Tôi đang sử dụng python version 2.7pip version is 1.5.6.liên kết phụ thuộc cài đặt pip

Tôi muốn cài đặt thêm thư viện từ url như git repo trên setup.py đang được cài đặt.

Tôi đã đặt phần bổ sung trong thông số install_requires trong setup.py. Điều này có nghĩa, thư viện của tôi yêu cầu thêm thư viện và chúng cũng phải được cài đặt.

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

Nhưng url như Repos git là chuỗi không hợp lệ trong install_requires trong setup.py. Giả sử rằng, tôi muốn cài đặt một thư viện từ github. Tôi đã tìm kiếm về vấn đề đó và tôi tìm thấy một cái gì đó mà tôi có thể đặt các thư viện như vậy trong dependency_links trong setup.py. Nhưng điều đó vẫn không hiệu quả. Đây là định nghĩa liên kết phụ thuộc của tôi;

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

Các liên kết hợp lệ. Tôi có thể tải xuống từ trình duyệt internet với các url này. Các thư viện bổ sung này vẫn chưa được cài đặt với thiết lập của tôi. Tôi cũng đã thử tham số --process-dependency-links để buộc pip. Nhưng kết quả là như nhau. Tôi không có lỗi khi pipping.

Sau khi cài đặt, tôi không thấy thư viện nào trong số pip freeze dẫn đến dependency_links.

Tôi làm cách nào để tải xuống chúng bằng cài đặt setup.py của tôi?

được sửa đổi:

Dưới đây là hoàn chỉnh của tôi 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'], 
) 

Sửa 2:

Đây là pip log;

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) 

Dường như, nó không sử dụng các nguồn trong dependency_links.

Trả lời

7

Bạn cần chắc chắn rằng bạn cũng bao gồm sự phụ thuộc trong số install_requires của mình.

Dưới đây là một ví dụ 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' 
    ] 
) 

Dưới đây là vấn đề với ví dụ của bạn setup.py:

Bạn đang thiếu tên trứng trong các liên kết phụ thuộc bạn thiết lập.

Bạn có

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

Bạn cần

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

+1

Nó nói 'Không thể tìm thấy bất kỳ tải xuống nào đáp ứng yêu cầu my-extra-libraray == 1.0.0.0 (từ my-installed-library-current == 1.0.0.0) ' –

+0

@AhmetDAL bạn có cả hai liên kết phụ thuộc và cài đặt yêu cầu được chỉ định? bạn có thể đăng 'setup.py' hoàn chỉnh mà bạn đang sử dụng không? – mjallday

+0

Vui lòng xem phần đã chỉnh sửa của câu hỏi của tôi. –

14

Pip loại bỏ hỗ trợ cho dependency_links một thời gian trở lại.latest version of pip that supports dependency_links is 1.3.1, để cài đặt nó

pip install pip==1.3.1 

liên kết phụ thuộc của bạn sẽ hoạt động tại thời điểm đó. Xin lưu ý rằng dependency_links luôn là phương sách cuối cùng cho pip, tức là. nếu một gói có cùng tên tồn tại trên pypi nó sẽ được chọn trên của bạn.

Lưu ý, https://github.com/pypa/pip/pull/1955 dường như bắt đầu cho phép dependency_links, pip giữ nó, nhưng bạn có thể cần sử dụng một số công tắc dòng lệnh để sử dụng phiên bản pip mới hơn.

EDIT: Theo pip 7 ... họ đã suy nghĩ lại các liên kết và đã kích hoạt chúng, mặc dù chúng chưa loại bỏ thông báo không dùng nữa, từ các cuộc thảo luận mà chúng dường như ở đây để ở. Với pip> = 7 đây là cách bạn có thể cài đặt những thứ

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

Hoặc thêm dòng sau vào một pip.conf, ví dụ /etc/pip.conf

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

EDIT

Một trick Tôi đã học được là phải bump lên số phiên bản để một cái gì đó thực sự cao để đảm bảo rằng pip không thích phiên bản liên kết không phụ thuộc (nếu đó là một cái gì đó bạn muốn). Từ ví dụ trên, làm cho giao diện liên kết phụ thuộc như:

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

Ngoài ra hãy chắc chắn rằng phiên bản hoặc trông giống như ví dụ hoặc là phiên bản cập nhật, bất kỳ phiên bản khác sẽ làm cho pips nghĩ của mình một phiên bản dev và sẽ không cài đặt nó .

+0

Có vẻ như đây không còn là trường hợp nữa? dependency_links được hỗ trợ trong pip mới nhất theo như tôi thấy. – yelsayed

+0

Bạn vẫn thấy cảnh báo, nhưng dependency_links sẽ ở lại một thời gian. Bạn vẫn cần cấu hình theo như tôi biết, xem ghi chú trong phần chỉnh sửa của câu trả lời. – Pykler

+0

có lẽ bạn nên loại bỏ thông tin về phiên bản 1.3.1 pip nó rất cũ –

1

Tôi phải đối mặt với một tình huống tương tự mà tôi muốn sử dụng shapely là một trong những gói phụ thuộc của tôi. Tuy nhiên, một điều đáng báo động là nếu bạn đang sử dụng các cửa sổ, bạn phải sử dụng tệp .whl từ http://www.lfd.uci.edu/~gohlke/pythonlibs/. Nếu không, bạn phải cài đặt trình biên dịch C, cái mà tôi không muốn. Tôi muốn người dùng chỉ cần sử dụng pip install mypackage thay vì cài đặt một loạt các nội dung khác.

Và nếu bạn có thiết lập điển hình với 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'] 
) 

và chạy python setup.py install, nó chỉ đơn giản là sẽ chọn quyến rũ trên Pypi và gây ra rắc rối về cài đặt Windows. Sau nhiều giờ nghiên cứu, tôi tìm thấy liên kết này Force setuptools to use dependency_links to install mysqlclient và về cơ bản sử dụng from setuptools.command.install import install as _install để cài đặt thủ công một cách dễ dàng.

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} 
) 

Và tập lệnh hoạt động độc đáo. Hy vọng nó giúp.

Các vấn đề liên quan