[英]pip install dependency links
I am using python version 2.7
and pip version is 1.5.6
. 我使用的是
python version 2.7
而pip version is 1.5.6
。
I want to install extra libraries from url like a git repo on setup.py is being installed. 我想从url安装额外的库,就像正在安装setup.py上的git repo一样。
I was putting extras in install_requires
parameter in setup.py
. 我在
setup.py
中的install_requires
参数中添加了额外内容。 This means, my library requires extra libraries and they must also be installed. 这意味着,我的库需要额外的库,并且还必须安装它们。
...
install_requires=[
"Django",
....
],
...
But urls like git repos are not valid string in install_requires
in setup.py
. 但是像git repos这样的url在
setup.py
中的install_requires
中不是有效的字符串。 Assume that, I want to install a library from github. 假设,我想从github安装一个库。 I have searched about that issue and I found something which I can put libraries such that in
dependency_links
in setup.py
. 我已经搜索了这个问题,我找到了一些可以将库放在
setup.py
中的dependency_links
中的东西。 But that still doesn't work. 但那仍然行不通。 Here is my dependency links definition;
这是我的依赖链接定义;
dependency_links=[
"https://github.com/.../tarball/master/#egg=1.0.0",
"https://github.com/.../tarball/master#egg=0.9.3",
],
The links are valid. 链接有效。 I can download them from a internet browser with these urls.
我可以使用这些网址从互联网浏览器下载它们。 These extra libraries are still not installed with my setting up.
我的设置仍然没有安装这些额外的库。 I also tried
--process-dependency-links
parameter to force pip. 我也尝试过
--process-dependency-links
参数来强制pip。 But result is same. 但结果是一样的。 I take no error when pipping.
我在翻录时没有错误。
After installation, I see no library in pip freeze
result in dependency_links
. 安装后,我发现在
dependency_links
中pip freeze
结果中没有库。
How can I make them to be downloaded with my setup.py
installation? 如何使用我的
setup.py
安装下载它们?
Here is my complete 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'],
)
Here is pip log; 这是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)
It seems, it does not use the sources in dependency_links
. 看起来,它不使用
dependency_links
的源代码。
Pip removed support for dependency_links a while back. Pip一段时间后删除了对dependency_links的支持。 The latest version of pip that supports dependency_links is 1.3.1 , to install it
支持dependency_links的最新版本的pip是1.3.1 ,以便安装它
pip install pip==1.3.1
your dependency links should work at that point. 您的依赖关系链接应该在那时工作。 Please note, that dependency_links were always the last resort for pip, ie.
请注意,dependency_links始终是pip的最后手段,即。 if a package with the same name exists on pypi it will be chosen over yours.
如果pypi上存在具有相同名称的包,则会选择超过您的包。
Note, https://github.com/pypa/pip/pull/1955 seems to start allowing dependency_links, pip kept it, but you might need to use some command line switches to use a newer version of pip. 注意, https://github.com/pypa/pip/pull/1955似乎开始允许dependency_links,pip保留它,但你可能需要使用一些命令行开关来使用更新版本的pip。
EDIT : As of pip 7 ... they rethought dep links and have enabled them, even though they haven't removed the deprecation notice, from the discussions they seem to be here to stay. 编辑 :从第7点开始......他们重新考虑了dep链接,并且已经启用了他们,即使他们没有删除弃用通知,也不会从他们似乎要留下的讨论中获得。 With pip>=7 here is how you can install things
使用pip> = 7,您可以在这里安装
pip install -e . --process-dependency-links --allow-all-external
Or add the following to a pip.conf, eg /etc/pip.conf
或者将以下内容添加到pip.conf中,例如
/etc/pip.conf
[install]
process-dependency-links = yes
allow-all-external = yes
trusted-host =
bitbucket.org
github.com
EDIT 编辑
A trick I have learnt is to bump up the version number to something really high to make sure that pip doesn't prefer the non dependency link version (if that is something you want). 我学到的一个技巧是将版本号提升到非常高的值,以确保pip不喜欢非依赖链接版本(如果这是你想要的东西)。 From the example above, make the dependency link look like:
从上面的示例中,使依赖关系链接看起来像:
"https://github.com/egemsoft/django-simple-sso/tarball/master#egg=999.0.0",
Also make sure the version either looks like the example or is the date version, any other versioning will make pip think its a dev version and wont install it. 还要确保版本看起来像示例或是日期版本,任何其他版本控制将使pip认为它是开发版本并且不会安装它。
You need to make sure you include the dependency in your install_requires
too. 您需要确保在
install_requires
包含依赖项。
Here's an example setup.py
这是一个
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'
]
)
Here's the issue with your example setup.py
: 以下是您的示例
setup.py
的问题:
You're missing the egg name in the dependency links you setup. 您在设置的依赖关系链接中缺少鸡蛋名称。
You have 你有
https://github.com/egemsoft/esef-auth/tarball/master/#egg=1.0.0.0
You need 你需要
https://github.com/egemsoft/esef-auth/tarball/master/#egg=esef-auth-1.0.0.0
The --process-dependency-links
option to enable dependency_links
was removed in Pip 19.0 . 在Pip 19.0中删除了启用
dependency_links
的--process-dependency-links
选项。
Instead, you can use a PEP 508 URL to specify your dependency, which is supported since Pip 18.1 . 相反,您可以使用PEP 508 URL来指定您的依赖关系,这是自Pip 18.1以来支持的 。 Here's an example excerpt from
setup.py
: 以下是
setup.py
的示例摘录:
install_requires=[
"numpy",
"package1 @ git+https://github.com/user1/package1",
"package2 @ git+https://github.com/user2/package2@branch1",
],
Note that Pip does not support installing packages with such dependencies from PyPI and in the future you will not be able to upload them to PyPI (see news entry for Pip 18.1) . 请注意,Pip不支持从PyPI安装具有此类依赖关系的包,并且将来您将无法将它们上载到PyPI(请参阅Pip 18.1的新闻条目) 。
I faced a similar situation where I want to use shapely as one of my package dependency. 我遇到了类似的情况,我希望将其作为我的包依赖项之一。 Shapely, however, has a caveat that if you are using windows, you have to use the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ .
然而,Shapely有一个警告,如果您使用的是Windows,则必须使用http://www.lfd.uci.edu/~gohlke/pythonlibs/中的.whl文件。 Otherwise, you have to install a C compiler, which is something I don't want.
否则,你必须安装一个C编译器,这是我不想要的。 I want the user to simply use
pip install mypackage
instead of installing a bunch of other stuffs. 我希望用户只需使用
pip install mypackage
而不是安装一堆其他东西。
And if you have the typical setup with dependency_links
如果您使用
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 = 'Costa.Huang@outlook.com',
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']
)
and run pip install .
并运行
pip install .
, it is simply going to pick the shapely on Pypi and cause trouble on Windows installation. ,它只是在Pypi上选择合适的形状并在Windows安装上造成麻烦。 After hours of researching, I found this link Force setuptools to use dependency_links to install mysqlclient and basically use
from setuptools.command.install import install as _install
to manually install shapely. 经过几个小时的研究,我发现这个链接强制setuptools使用dependency_links来安装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 = 'test@outlook.com',
cmdclass={'install': install}
)
And the script works out nicely. 而且脚本运行得很好。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.