代码之家  ›  专栏  ›  技术社区  ›  Laimonas Sutkus

python setup.py-运行setup.py install时不构建轮子

  •  -1
  • Laimonas Sutkus  · 技术社区  · 6 年前

    我想使用setup.py和它的所有功能,但我不想为可安装的项目构建一个轮子。有没有旗子或什么东西只是跳过建筑轮子?

    这背后的原因是,我正在使用SETUPTOOLS提供的自定义installcommand将环境变量传递给下一个可安装项目(依赖项),并且在看不到构建车轮环境变量时,只有安装(而不是车轮构建)才有效。

    编辑:

    由于我正在使用生成选项,因此会收到警告:

    pip/_internal/commands/install.py:211:userwarning:由于使用--build options/--global options/--install options,禁用所有轮子的使用。

    既然我使用这个自定义的installcommand:

    class InstallCommand(install):
        user_options = install.user_options + [
        ('environment=', None, 'Specify a production or development environment.'),
    ]
    
    def initialize_options(self):
        install.initialize_options(self)
        self.environment = None
    
    def finalize_options(self):
        install.finalize_options(self)
    
        global ENVIRONMENT
    
        try:
            # Check if environment is set
            is_dev()
        except AssertionError:
            # If not - assert that this class has a set environment
            assert self.environment in ['dev', 'prod'], 'Bad environment propagated from parent project.'
            ENVIRONMENT = self.environment
    
    def run(self):
        install.run(self)
    

    我得到这个错误:

    installing to build/bdist.linux-x86_64/wheel
    running install
    Traceback (most recent call last):
    File "/tmp/pip-req-build-xnp6kolm/setup_helper.py", line 26, in finalize_options
      is_dev()
    File "/tmp/pip-req-build-xnp6kolm/setup_helper.py", line 126, in is_dev
    assert (prod or dev) is True, 'Environment should be set to dev or prod'
    AssertionError: Environment should be set to dev or prod
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    File "/tmp/pip-req-build-xnp6kolm/setup_helper.py", line 29, in finalize_options
      assert self.environment in ['dev', 'prod'], 'Bad environment propagated from parent project.'
    AssertionError: Bad environment propagated from parent project.
    
    ----------------------------------------
    Failed building wheel for ivs-repository-manager - HAVE A NOTICE AT THIS LINE !!! I HAVE RUN SETUP.PY INSTALL, NOT BDIST
    Running setup.py clean for ivs-repository-manager
    Failed to build ivs-repository-manager
    

    但是!在这个异常之后,isInstallation仍然成功,我看到安装的包。只是当安装工具试图构建轮子时,我会得到这些错误。

    所以,当构建轮子环境传播时,似乎看不到安装选项。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Laimonas Sutkus    6 年前

    找到了解决方案:

    不要使用setup.py安装,最好创建一个source distribution setup.py sdist 然后用PIP安装。例如:

    python setup.py sdist
    python -m pip install dist/* --install-option=--environment='dev'