代码之家  ›  专栏  ›  技术社区  ›  wvxvw

如何使setuptools安装包含多个软件包的控制盘?

  •  -2
  • wvxvw  · 技术社区  · 6 年前

    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
    

    它有三个不同的软件包:

    • azure.common

    这个轮子是按名字分配的 azure-common . 所以,当你依靠在 setup.py

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

    你只会得到 azure_common 已安装程序包。也许 吧。我真的不知道,似乎是这样,但我尝试过的几次似乎只是安装 azure.common ,或者是我的眼睛。。。很难遵循setuptools对一个包所做的所有操作。

    因此,问题是:我怎样才能强制 setuptools 安装这种轮子里的所有包裹?另外,顺序也很重要,因为这个垃圾有时需要与其他包一起安装,这些包也提供 azure.something azure 目录。所以,理想情况下,我还想控制顺序 install_requires 处理依赖关系。


    这就是开始的地方: How to specify bracket dependencies in setup.py?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Peter Pan    6 年前

    听起来只有很少的子目录像 azure.common 通过安装依赖项时安装到环境中 setup.py install_requires=['azure-common']

    下面是我在本地Windows机器上的操作步骤,您可以参考。

    1. 创建目录 mkdir setuptmp virtualenv setuptmp ,然后到 cd setuptmp
    2. 设置.py

      from setuptools import setup, find_packages  
      
      setup(
          name = "setuptmp",
          install_requires = ['azure-common']
      )
      
    3. Scripts\activate.bat .

    4. python setup.py install 安装我的 设置.py
    5. python 打开REPL解释器来测试您所说的所有包,

      (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

    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
      
    2. azure-common 从下载的包 link Pypi网站的。我减压了 azure_common-1.1.16-py2.py3-none-any.whl 文件使用 7-Zip 进入临时目录,然后 tree

      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
      

    然后,您将找到step的文件结构 6 &安培; 7 几乎一样。

    希望有帮助。如果您有任何顾虑,请随时告诉我。


    我在Linux上也做了同样的操作,得到了相同的结果。我保存了 tree lib/ > lib_[before|after].txt 我的Linux setuptmp python设置.py安装 ,然后使用 diff lib_*.txt 如下所示。

    (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