Python3:在 setup.py 中安装基于 github 的模块? [英] Python3: install github-based module in setup.py?

查看:95
本文介绍了Python3:在 setup.py 中安装基于 github 的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

参考文献:

虽然我不完全确定它会起作用.requirements.txt 文件、直接pipsetuptools 中接受的符号之间可能存在细微差别.特别是我不知道 eggsubdirectory 之类的东西的支持情况如何.

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 installpython setup.py develop,并确保调用 python -m pip install .code> 或 python -m pip install --editable . 代替.
  • 我确实考虑从 setup.py 中读取 requirements.txt 作为危险信号(或至少是黄色信号).setuptoolsinstall_requiresrequirements.txt 的内容通常用于不同的目的.
  • Avoid calling python setup.py install or python setup.py develop from now on, and make sure to call python -m pip install . or python -m pip install --editable . instead.
  • I do consider reading requirements.txt from within setup.py as a red flag (or at least yellow). The contents of install_requires of setuptools and requirements.txt usually serve different purposes.

这篇关于Python3:在 setup.py 中安装基于 github 的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆