如何使setuptools安装包含多个软件包的轮子? [英] How to make setuptools install a wheel containing multiple packages?

查看:57
本文介绍了如何使setuptools安装包含多个软件包的轮子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设这个轮子:

M Filemode      Length  Date         Time      File
- ----------  --------  -----------  --------  -------------------------------------------
  -rw-rw-r--      1358  26-Sep-2018  21:08:40  azure/common/__init__.py
  -rw-rw-r--       327  26-Sep-2018  21:08:40  azure/common/_version.py
  -rw-rw-r--      8737  26-Sep-2018  21:08:40  azure/common/client_factory.py
  -rw-rw-r--       755  26-Sep-2018  21:08:40  azure/common/cloud.py
  -rw-rw-r--      2479  26-Sep-2018  21:08:40  azure/common/credentials.py
  -rw-rw-r--       805  26-Sep-2018  21:08:40  azure/common/exceptions.py
  -rw-rw-r--      6079  26-Sep-2018  21:08:40  azure/profiles/__init__.py
  -rw-rw-r--      3943  26-Sep-2018  21:08:40  azure/profiles/multiapiclient.py
  -rw-rw-r--         6  26-Sep-2018  21:21:54  azure_common-1.1.16.dist-info/top_level.txt
  -rw-rw-r--       110  26-Sep-2018  21:21:54  azure_common-1.1.16.dist-info/WHEEL
  -rw-rw-r--      3805  26-Sep-2018  21:21:54  azure_common-1.1.16.dist-info/METADATA
  -rw-rw-r--       997  26-Sep-2018  21:21:54  azure_common-1.1.16.dist-info/RECORD
- ----------  --------  -----------  --------  -------------------------------------------
                 29401                         12 files

其中包含三个不同的程序包:

It has three different packages in it:

  • azure.common
  • azure.profiles
  • azure_common

所有伟大的名字和伟大的布局.同样,在设计这一现代软件工程的奇迹时,很多伟大的思想都明确地投入到了工程中.

All great names, and great layout. Also, a lot of greatness of mind that unmistakably went into engineering this miracle of modern software engineering.

该轮子的名称为 azure-common .因此,当您像这样依赖 setup.py 时:

This wheel is distributed by the name azure-common. So, when you depend on in in setup.py like this:

setup(
    ...
    install_requires=['azure-common'],
    ...
)

您将仅安装 azure_common 软件包.也许.我真的不知道,似乎是这样,但是我尝试了几次却似乎只安装了 azure.common ,或者也许是我盯着它了……很难遵循所有的操作setuptools在包装上做.

You will only get azure_common package installed. Maybe. I don't really know, it seems so, but few times that I tried it seemed to only install azure.common, or maybe I eyeballed it... It's really hard to follow all the manipulations setuptools does on a package.

因此产生一个问题:我该如何强制 setuptools 安装在这种轮子上找到的所有软件包?另外,顺序很重要,因为此垃圾有时需要与其他提供 azure.something 软件包的软件包一起安装,这些软件包可能会覆盖 azure 目录中的内容.因此,理想情况下,我还想控制 install_requires 依赖项的处理顺序.

Hence the question: how can I force setuptools into installing all packages found in this kind of wheel? Also, the order is important because this garbage needs to be installed some of the times with other packages which also provide azure.something packages which may overwrite the stuff in azure directory. So, Ideally, I'd also like to control in which order install_requires dependencies are processed.

这是从这里开始的:如何在setup.py中指定括号依赖项?

推荐答案

当您通过 setup安装依赖项时,听起来像只有几个子目录(如 azure.common )安装到您的环境中.py install_requires = ['azure-common'] .我试图重现此问题,但是失败了,此软件包中的所有文件都已安装.

It sounds like only few sub-directories like azure.common installed into your environment when you installed dependencies via setup.py with install_requires=['azure-common']. I tried to reproduce this issue, but failed that all files in this package has been installed.

这是我在本地Windows计算机上执行的步骤,如下所示.

Here is my steps on my local Windows machine as below, which you can refer to.

  1. 创建目录 mkdir setuptmp ,并创建虚拟环境 virtualenv setuptmp ,然后创建 cd setuptmp .
  2. 使用以下内容创建一个 setup.py 文件.\

  1. Create a directory mkdir setuptmp, and create a virtual environment virtualenv setuptmp, then to cd setuptmp.
  2. Create a setup.py file with the content as below.\

from setuptools import setup, find_packages  

setup(
    name = "setuptmp",
    install_requires = ['azure-common']
)

  • 通过 Scripts \ activate.bat 激活虚拟环境.

    运行 python 打开REPL解释器以测试您所说的所有软件包,

    Run python to open the REPL interpreter to test all packages as you said,

    (setuptmp) D:\projects\setuptmp>python
    Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import azure.common
    >>> import azure.profiles
    >>> azure.common.__file__
    'D:\\projects\\setuptmp\\lib\\site-packages\\azure_common-1.1.16-py3.7.egg\\azure\\common\\__init__.py'
    >>> azure.profiles.__file__
    'D:\\projects\\setuptmp\\lib\\site-packages\\azure_common-1.1.16-py3.7.egg\\azure\\profiles\\__init__.py'
    >>> import azure_common
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'azure_common'
    

  • 注意: azure_common 不是一个模块,只是一个egg信息目录.

    Note: azure_common is not a module, just an egg info directory.

    1. 通过 cd Lib \ site-packages dir tree azure_common-1.1.16-py3.7检查在我的环境中安装的软件包.egg/F 如下.

    (setuptmp) D:\projects\setuptmp\Lib\site-packages>dir
     Volume in drive D is Data
     Volume Serial Number is BA4B-64AA
    
     Directory of D:\projects\setuptmp\Lib\site-packages
    
    2018/12/26  14:48    <DIR>          .
    2018/12/26  14:48    <DIR>          ..
    2018/12/26  14:48    <DIR>          azure_common-1.1.16-py3.7.egg
    2018/12/26  14:48                61 easy-install.pth
    2018/12/26  14:46               126 easy_install.py
    2018/12/26  14:46    <DIR>          pip
    2018/12/26  14:46    <DIR>          pip-18.1.dist-info
    2018/12/26  14:46    <DIR>          pkg_resources
    2018/12/26  14:48               965 setuptmp-0.0.0-py3.7.egg
    2018/12/26  14:46    <DIR>          setuptools
    2018/12/26  14:46    <DIR>          setuptools-40.6.3.dist-info
    2018/12/26  14:46    <DIR>          wheel
    2018/12/26  14:46    <DIR>          wheel-0.32.3.dist-info
    2018/12/26  14:46    <DIR>          __pycache__
                   3 File(s)          1,152 bytes
                  11 Dir(s)  80,896,319,488 bytes free
    
    (setuptmp) D:\projects\setuptmp\Lib\site-packages>tree azure_common-1.1.16-py3.7.egg /F
    Folder PATH listing for volume Data
    Volume serial number is BA4B-64AA
    D:\PROJECTS\SETUPTMP\LIB\SITE-PACKAGES\AZURE_COMMON-1.1.16-PY3.7.EGG
    ├─azure
    │  ├─common
    │  │  │  client_factory.py
    │  │  │  cloud.py
    │  │  │  credentials.py
    │  │  │  exceptions.py
    │  │  │  _version.py
    │  │  │  __init__.py
    │  │  │
    │  │  └─__pycache__
    │  │          _version.cpython-37.pyc
    │  │          __init__.cpython-37.pyc
    │  │
    │  └─profiles
    │          multiapiclient.py
    │          __init__.py
    │
    └─EGG-INFO
            PKG-INFO
            RECORD
            requires.txt
            top_level.txt
            WHEEL
    

  • 将以上内容与从azure-common 包的文件结构进行比较Pypi网站的rel ="nofollow noreferrer">链接.我使用 7-Zip azure_common-1.1.16-py2.py3-none-any.whl 文件解压缩到临时目录中,并在 tree 中进行了压缩

  • Compare the above with the file structure of azure-common package downloaded from the link of Pypi website. I decompressed azure_common-1.1.16-py2.py3-none-any.whl file using 7-Zip into a temp directory and tree it.

    D:\tmp>tree azure_common-1.1.16-py2.py3-none-any /F
    Folder PATH listing for volume Data
    Volume serial number is BA4B-64AA
    D:\tmp\AZURE_COMMON-1.1.16-PY2.PY3-NONE-ANY
    ├─azure
    │  ├─common
    │  │      client_factory.py
    │  │      cloud.py
    │  │      credentials.py
    │  │      exceptions.py
    │  │      _version.py
    │  │      __init__.py
    │  │
    │  └─profiles
    │          multiapiclient.py
    │          __init__.py
    │
    └─azure_common-1.1.16.dist-info
            METADATA
            RECORD
            top_level.txt
            WHEEL
    

  • 然后,您将找到步骤 6 &的文件结构. 7 几乎相同.

    Then, you will find the file structure of step 6 & 7 is almost same.

    希望它会有所帮助.如果您有任何疑问,请随时告诉我.

    Hope it helps. If you have any concern, please feel free to let me know.

    我在Linux上执行了相同的操作,并得到了相同的结果.我保存了 tree lib/>的输出.我的Linux setuptmp 的lib_ [before | after] .txt 在运行 python setup.py install 之前和之后,然后使用 diff lib_进行比较* .txt 如下.

    I did the same above on Linux and got the same result. I saved the output of tree lib/ > lib_[before|after].txt of my Linux setuptmp before and after run python setup.py install, then to compare them using diff lib_*.txt as below.

    (setuptmp) peter@peterpc:~/setuptmp$ diff lib*.txt
    92a93,111
    >     │   ├── azure_common-1.1.16-py3.6.egg
    >     │   │   ├── EGG-INFO
    >     │   │   │   ├── PKG-INFO
    >     │   │   │   ├── RECORD
    >     │   │   │   ├── WHEEL
    >     │   │   │   ├── requires.txt
    >     │   │   │   └── top_level.txt
    >     │   │   └── azure
    >     │   │       ├── common
    >     │   │       │   ├── __init__.py
    >     │   │       │   ├── _version.py
    >     │   │       │   ├── client_factory.py
    >     │   │       │   ├── cloud.py
    >     │   │       │   ├── credentials.py
    >     │   │       │   └── exceptions.py
    >     │   │       └── profiles
    >     │   │           ├── __init__.py
    >     │   │           └── multiapiclient.py
    >     │   ├── easy-install.pth
    827a847
    >     │   ├── setuptmp-0.0.0-py3.6.egg
    1043c1063
    < 118 directories, 922 files
    ---
    > 123 directories, 937 files
    

    这篇关于如何使setuptools安装包含多个软件包的轮子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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