我有一个模块可以在python 2和python 3上工作.在Python <3.2中我想安装一个特定的包作为依赖.对于Python> = 3.2.
就像是:
install_requires=[
"threadpool >= 1.2.7 if python_version < 3.2.0",
],
Run Code Online (Sandbox Code Playgroud)
怎么能做到这一点?
我有一个setup.py看起来像这样:
from setuptools import setup
from subprocess import call
from setuptools.command.install import install
class MyInstall(install):
def run(self):
call(["pip install -r requirements.txt --no-clean"], shell=True)
install.run(self)
setup(
author='Attila Zseder',
version='0.1',
name='entity_extractor',
packages=['...'],
install_requires=['DAWG', 'mrjob', 'cchardet'],
package_dir={'': 'modules'},
scripts=['...'],
cmdclass={'install': MyInstall},
)
Run Code Online (Sandbox Code Playgroud)
我需要MyInstall因为我想从github安装一些库而我不想使用dependency_links选项,因为它不鼓励(例如这里),所以我可以用requirements.txt来做这件事.
当我安装这个软件包时pip,一切都运行正常,但由于某些原因,我必须以一种纯粹的方式解决这个问题python setup.py install.它没有.
当覆盖cmdclass在setup()与我自己的类,install_requires似乎被忽略.一旦我注释掉那一行,就会安装这些软件包.
我知道例如在distutils中不支持install_requires(如果我记得很清楚),但它在setuptools中.然后cmdclass就不会有任何影响install_requires.
我用Google搜索了这个问题几个小时,在stackoverflow上找到了很多相关的答案,但不是针对这个特殊的问题.
把所有需要的包放到requirements.txt,一切都运行正常,但我想了解为什么会这样.谢谢!
我想知道是否和.deb包一样,在我的setup.py中可以配置我的包的依赖项,然后运行:
$ sudo python setup.py install
Run Code Online (Sandbox Code Playgroud)
它们是自动安装的.已经研究过互联网,但我发现只是让我困惑,像"需要","install_requires"和"requirements.txt"之类的东西
我的存储库包含我自己的 python 模块和它的依赖项之一的子模块,它有自己的 setup.py。
我想在安装我自己的库时调用依赖项的 setupy.py,这怎么可能?
我的第一次尝试:
$ tree
.
??? dependency
? ??? setup.py
??? mylib
??? setup.py
$ cat mylib/setup.py
from setuptools import setup
setup(
name='mylib',
install_requires= ["../dependency"]
# ...
)
$ cd mylib && python setup.py install
error in arbalet_core setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'../depen'"
Run Code Online (Sandbox Code Playgroud)
但是install_requires不接受路径。
我的第二次尝试是使用dependency_links=["../dependency"]withinstall_requires=["dependency"]但是 Pypi 中已经存在同名的依赖项,因此 setuptools 尝试使用该版本而不是我的版本。
什么是正确/最干净的方法?
我有一个库(SUBX),这取决于subprocess32.subprocess32库是Python2.7的后端,提供超时kwarg.
我的图书馆需要超时kwarg.
只有目标平台是Python2.x时我才需要subprocess32.
我该如何在项目中定义依赖项?
我收到此错误消息,如果我subprocess32通过"install_requires"(setup.py)定义依赖项并且我在python3 virtualenv中:
===> pip install -e git+https://github.com/guettli/subx.git#egg=subx
Obtaining subx from git+https://github.com/guettli/subx.git#egg=subx
Cloning https://github.com/guettli/subx.git to ./src/subx
Collecting subprocess32 (from subx)
Using cached subprocess32-3.2.7.tar.gz
Complete output from command python setup.py egg_info:
This backport is for Python 2.x only.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lju3nl1y/subprocess32/
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 install_requires 中指定带有 CUDA 的 PyTorch。使用 pip 安装的命令是
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio===0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
如何在 setup.py install_requires 中做到这一点?
我创建了一个包'typing;python_version<"3.5"'在里面的install_requires。显然,这种依赖规范只在最近版本的setuptools. 如果setuptools用户机器上的 旧的,他们会得到:
'install_requires' 必须是包含有效项目/版本要求说明符的字符串或字符串列表;键入中的预期版本规范;python_version<"3.5" at ;python_version<"3.5"
简单的解决方案是告诉用户pip install 'setuptools>=36.2.1'之前pip install my-package。(请注意,这36.2.1只是我知道的一个版本,不一定是绝对最低要求)
但是有没有什么方法可以指定这个要求setup.py,让它自动完成?添加setuptools>=36.2.1到install_requires并setup_requires没有工作。它说Installed /tmp/pip-si2fqg-build/.eggs/setuptools-38.2.5-py3.3.egg然后给出与上面相同的错误。
python ×7
setuptools ×5
setup.py ×4
distutils ×2
dependencies ×1
distribute ×1
pip ×1
pytorch ×1