Python3:在 setup.py 中安装基于 github 的模块? [英] Python3: install github-based module in setup.py?
问题描述
用pip
安装,我可以写如下requirements.txt
文件:
Installing with pip
, I can write the following requirements.txt
file:
git+https://repo@branch#egg=foo&subdirectory=this/bar/foo
numpy
并成功安装需求文件:
python3 -m pip install -r requirements.tx
但是,我在目录中放置了一个 setup.py
脚本,其中列出了:
However, I have co-located in the directory a setup.py
script that lists:
setuptools.setup(
...
install_requires = get_lines('requirements.txt'),
...
)
并且使用 pip
安装这个子模块涉及 pip
运行 setup.py
...它无法处理模块链接:
And installing this submodule using pip
involves pip
running setup.py
...which fails to handle the module link:
git+https://github.com/repo@branch#egg=foo&subdirectory=this/bar/foo
我可以看到很多解决这个问题的方法,但似乎应该有一种明确的方法来做到这一点,在 setup.py
脚本.
I can see a lot of ways around this, but it seems like there should be one non-ambiguous way to do this which changes as little as possible in the setup.py
script.
有这种方法吗?
推荐答案
您可能需要将 requirements.txt
中的行更改为:
You probably need to change the line in requirements.txt
to something like:
foo @ git+https://repo@branch#egg=foo&subdirectory=this/bar/foo
参考文献:
- https://pip.pypa.io/en/稳定/参考/pip_install/#requirement-specifiers
- https://www.python.org/dev/peps/pep-0440/#direct-references
虽然我不完全确定它会起作用.requirements.txt
文件、直接pip 和setuptools 中接受的符号之间可能存在细微差别.特别是我不知道 egg
和 subdirectory
之类的东西的支持情况如何.
Although I am not entirely sure it will work. There might be subtle differences between the notations accepted in requirements.txt
files, pip directly and setuptools. In particular I do not know how well things like egg
and subdirectory
are supported.
建议:
- 从现在开始避免调用
python setup.py install
或python setup.py develop
,并确保调用python -m pip install .
code> 或python -m pip install --editable .
代替. - 我确实考虑从
setup.py
中读取requirements.txt
作为危险信号(或至少是黄色信号).setuptools 的install_requires
和requirements.txt
的内容通常用于不同的目的.
- Avoid calling
python setup.py install
orpython setup.py develop
from now on, and make sure to callpython -m pip install .
orpython -m pip install --editable .
instead. - I do consider reading
requirements.txt
from withinsetup.py
as a red flag (or at least yellow). The contents ofinstall_requires
of setuptools andrequirements.txt
usually serve different purposes.
这篇关于Python3:在 setup.py 中安装基于 github 的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!