在上面的答案中发表评论并收到反馈后,我想将我的评论变成答案。请注意,上面的答案都很好,但根据我的经验,我发现这些答案中“缺少”一件事,需要指出,所以我将在此说明这个问题。
为了说明的简单性和完整性,我编写了一个非常简单的 Python 3 项目。它使用的唯一 3rd 方包是著名的 SSH 客户端包paramiko(它的官方 PyPi 页面可以找到here)。
我的项目虚拟环境中的Python解释器版本是3.6.9
现在,为了检查 python_requires 属性“正在运行”,我已将其添加到项目的 setup.py 脚本中,如下所示:
from setuptools import setup, find_packages
setup(name='mySampleProject',
version='1.0',
description='Sample project in Python 3',
author='Guy Avraham',
license='MIT',
packages=find_packages(),
include_package_data=True,
python_requires='>=3.8',
install_requires=['paramiko'])
请注意,我“要求”Python 版本为 3.8+。这当然应该不与项目虚拟环境中的当前 Python 版本(即 3.6.9)一起使用。
现在,当我使用setup.py 中的“正常”用法(即运行:python3 setup.py install)构建项目时,项目已成功构建。运行python3 setup.py install 命令后查看pip3 list 命令的以下输出:
(mySampleProject_env) guya@ubuntu:~/mySampleProject$ pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --
format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
bcrypt (3.2.0)
cffi (1.14.3)
cryptography (3.1.1)
mySampleProject (1.0)
paramiko (2.7.2)
pip (9.0.1)
pkg-resources (0.0.0)
pycparser (2.20)
PyNaCl (1.4.0)
setuptools (39.0.1)
six (1.15.0)
如您所见,该项目及其所有“子依赖项”已安装,即使我没想到它也会安装。
另一方面,当我使用以下命令安装项目时:pip3 install -e .(注意. 表示“当前工作目录”),我得到以下输出:
(mySampleProject_env) guya@ubuntu:~/mySampleProject$ pip3 install -e .
Obtaining file:///home/guya/mySampleProject
mySampleProject requires Python '>=3.8' but the running Python is 3.6.9
现在确实“考虑”了python_requires 属性,因此“失败”了项目的构建。
在this page教程的第一段中有详细说明
以及在 this video 的几分钟内 ~09:00 - 11:00
注意:我确实不检查以上所有内容以了解 Python 2(或 pip 了解 Python 2)。