Python setup.py-运行setup.py install

时间:2019-02-07 10:45:36

标签: python setuptools setup.py python-wheel python-install

我想使用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

但是!发生此异常后,安装仍然成功,并且我看到已安装的软件包。当setuptools尝试构建转轮时,只是我得到了这些错误。

因此,当用--install-options传播建筑轮环境时,似乎看不到。

1 个答案:

答案 0 :(得分:0)

找到解决方案:

请勿使用setup.py安装,最好创建源代码分发setup.py sdist 然后用pip安装。这是示例:

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