可安装的Python tar.gz包取决于用于构建tarball的操作系统

2024-10-04 05:29:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近遇到了一个奇怪的场景,我想将我的(格式正确的)Python包coolpackage转换为tarball,以便简单地分发给一些同事,但是生成的tarball的有效性取决于用于生成它的操作系统

对于上下文,coolpackage可以通过macOS和Ubuntu Linux上的pip从源目录安装,而不会出现以下问题:

cd coolpackage
pip install .

这在macOS和Linux上都有效,并且在这两种情况下都是在conda环境中运行的,在包方面是相同的

现在,如果我在Ubuntu中生成一个tarball

# run inside Ubuntu 18.04
tar -czvf coolpackage.tar.gz coolpackage

然后可以在macOS和Ubuntu上使用pip安装tar.gz文件:

pip install coolpackage.tar.gz

但是,如果我在macOS中生成一个tarball

# run inside macOS Mojave
tar -czvf coolpackage.tar.gz coolpackage

tarball不能安装在macOS或Ubuntu上,并且在这两种情况下退出时的错误基本相同(尽管有路径):

    pip install coolpackage.tar.gz
    Processing ./coolpackage.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /Users/alex/Python/conda/envs/localconda/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/2n/xtzsyspd32v6vglg_pd5gmw80000gn/T/pip-req-build-tz8wnxlx/setup.py'"'"'; __file__='"'"'/private/var/folders/2n/xtzsyspd32v6vglg_pd5gmw80000gn/T/pip-req-build-tz8wnxlx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/2n/xtzsyspd32v6vglg_pd5gmw80000gn/T/pip-req-build-tz8wnxlx/pip-egg-info
         cwd: /private/var/folders/2n/xtzsyspd32v6vglg_pd5gmw80000gn/T/pip-req-build-tz8wnxlx/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/alex/Python/conda/envs/localconda/lib/python3.7/tokenize.py", line 447, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/2n/xtzsyspd32v6vglg_pd5gmw80000gn/T/pip-req-build-tz8wnxlx/setup.py'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

想知道以前是否有人遇到过这种情况,或者对可能发生的事情有什么想法?我可以通过在Linux中构建来避免这种情况,所以这不是一个紧迫的问题,但我不喜欢不理解为什么某些东西会失败


Tags: pipbuildvarubuntumacostarprivatereq
2条回答

tar有许多方言/风味基本相似。在本例中,我们将介绍Linux系统上常用的GNU工具和BSD(>;Darwin->;MacOS X)上使用的BSD工具

如果您想在Linux上运行BSD tar,请尝试bsdtar;如果您想在BSD上使用GNU tar(以及其他一些U*X系统),请尝试gtar

这也转化为tarball的其他消费者,这似乎是trips pip,它显然期望GNU版本(gtar)风味的输入

由于您使用的是Python,因此直接使用其标准库中的^{}^{}可能是一个好主意。它应该足够便携

另外,假设项目是用setuptools(或distutils)打包的,那么在大多数情况下直接使用sdist应该足够好了(^{

相关问题 更多 >