【发布时间】:2020-05-06 12:10:22
【问题描述】:
我正在尝试将我的 python 代码打包到 wheel 文件中。我的代码依赖项因平台而异。
例如,在 Windows 中,我需要 psycopg2,而在 linux 中,我需要 psycopg2-binary。
我在我的项目中创建了两个单独的文件:requirements.txt 和 requirements_linux.txt。
下面是我的详细资料
Setup.py
requirement_file='requirements.txt'
if sys.platform == 'linux':
requirement_file = 'requirements_linux.txt'
here = os.path.abspath(os.path.dirname(__file__))
# setup method inside setup.py
setup(
...
...
install_requires=open(os.path.join(here,requirement_file)).readlines(),
...
)
现在我正在使用来自 Windows 系统的命令 python setup.py bdist_wheel 命令创建轮文件。但是上面的代码似乎不起作用。当我在 linux 环境中运行 wheel 文件时,它会搜索 psycopg2 而不是 psycopg2-binary。我错过了什么吗?
如何为 linux 或 Mac 等其他平台创建 wheel 文件并在其中具有单独的依赖项?
【问题讨论】:
-
“似乎不起作用”不是一个很有帮助的问题描述。如果您遇到错误,请考虑将完整的错误堆栈添加到您的问题中。
-
我已经更新了这个问题。请检查。
标签: python python-3.x python-wheel python-packaging