为什么python setup.py在Travis CI上说无效命令’bdist_wheel’?

问题:为什么python setup.py在Travis CI上说无效命令’bdist_wheel’?

我的Python软件包具有一个setup.py在本地配置时可以在Ubuntu Trusty和新的Vagrant Ubuntu Trusty VM上正常运行的软件包:

sudo apt-get install python python-dev --force-yes --assume-yes --fix-broken
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
sudo -H pip install setuptools wheel virtualenv --upgrade

但是,当我在Travis CI Trusty Beta VM上执行相同操作时:

- sudo apt-get install python python-dev --force-yes --assume-yes --fix-broken
- curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
- sudo -H pip install setuptools wheel virtualenv --upgrade

我得到:

python2.7 setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help
error: invalid command 'bdist_wheel'

为什么我不能在python中创建轮子?是相关的,但请注意,我正在安装滚轮并升级setuptools。

My Python package has a setup.py which builds fine locally on Ubuntu Trusty and on a fresh Vagrant Ubuntu Trusty VM when I provision it like this:

sudo apt-get install python python-dev --force-yes --assume-yes --fix-broken
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
sudo -H pip install setuptools wheel virtualenv --upgrade

But when I do the same on a Travis CI Trusty Beta VM:

- sudo apt-get install python python-dev --force-yes --assume-yes --fix-broken
- curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
- sudo -H pip install setuptools wheel virtualenv --upgrade

I get:

python2.7 setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help
error: invalid command 'bdist_wheel'

This Why can I not create a wheel in python? is related but note I am installing wheel and upgrading setuptools.


回答 0

不得不安装该wheel软件包。一切都是最新的,但仍然给出错误。

pip install wheel

然后

python setup.py bdist_wheel 

工作没有问题。

Had to install the wheel package. Everything was up to date but still giving the error.

pip install wheel

then

python setup.py bdist_wheel 

Worked without issues.


回答 1

pip install wheel

为我工作,但您也可以添加此内容

setup(
    ...
    setup_requires=['wheel']
)

来setup.py并保存点子安装命令

pip install wheel

worked for me, but you can also add this

setup(
    ...
    setup_requires=['wheel']
)

to setup.py and save yourself a pip install command


回答 2

2020年1月

浪费了2个小时。

在AWS上Ubuntu 18.04 new machine,需要进行以下安装:

sudo apt-get install gcc libpq-dev -y
sudo apt-get install python-dev  python-pip -y
sudo apt-get install python3-dev python3-pip python3-venv python3-wheel -y
pip3 install wheel

特别是最后一行是必须的。
但是,可能需要3行之前。

希望能有所帮助。

Jan 2020

2 hours wasted.

On a AWS Ubuntu 18.04 new machine, below installations are required:

sudo apt-get install gcc libpq-dev -y
sudo apt-get install python-dev  python-pip -y
sudo apt-get install python3-dev python3-pip python3-venv python3-wheel -y
pip3 install wheel

Especially the last line is must.
However before 3 lines might be required as prerequisites.

Hope that helps.


回答 3

该问题是由于:

  • 已为Python 2.7安装了旧版本的pip(6.1.1)
  • Trusty Beta映像上安装的Python 2.7的多个副本
  • 用于Python 2.7的其他位置 sudo

这一切都有点复杂,这里https://github.com/travis-ci/travis-ci/issues/4989可以更好地解释。

我的解决方案是使用user travis而非sudo

- pip2.7 install --upgrade --user travis pip setuptools wheel virtualenv

This problem is due to:

  • an old version of pip (6.1.1) being installed for Python 2.7
  • multiple copies of Python 2.7 installed on the Trusty Beta image
  • a different location for Python 2.7 being used for sudo

It’s all a bit complicated and better explained here https://github.com/travis-ci/travis-ci/issues/4989.

My solution was to install with user travis instead of sudo:

- pip2.7 install --upgrade --user travis pip setuptools wheel virtualenv

回答 4

如果已经安装了所有必需的模块,则可能需要将setuptools模块导入setup.py文件中。因此,只需在setup.py文件开头添加以下行。

import setuptools
from distutils.core import setup
# other imports and setups

Wheel的文档中也提到了这一点。https://wheel.readthedocs.io/en/stable/#usage

If you already have all the required modules installed you probably need to import the setuptools module in your setup.py file. So just add the following line at the leading of setup.py file.

import setuptools
from distutils.core import setup
# other imports and setups

This is also mentioned in wheel’s documentation. https://wheel.readthedocs.io/en/stable/#usage


回答 5

与许多建议的答案和不同的解决方案一样,此错误也很奇怪。我尝试过,添加它们。只有当我添加pip install --upgrade pip最终为我消除错误时。但是我没有时间隔离哪个是哪个,所以这只是一个问题。

This error is weird as many proposed answers and got mixed solutions. I tried them, add them. It was only when I added pip install --upgrade pip finally removed the error for me. But I have no time to isolate which is which,so this is just fyi.


回答 6

就我而言,venv创建的wheel / pip / setuptools版本太旧了。这有效:

venv/bin/pip  install --upgrade pip wheel setuptools

in my case, the version of wheel/pip/setuptools created by venv is too old. this works:

venv/bin/pip  install --upgrade pip wheel setuptools

回答 7

我已经wheel安装了,所以我尝试卸载并重新安装,它解决了此问题:

pip uninstall wheel
pip install wheel

奇怪的…

I already had wheel installed so I tried to uninstall and reinstall, and it fixed the issue:

pip uninstall wheel
pip install wheel

Weird…


回答 8

我的解决方法是 apt install python3-dev

My fix was apt install python3-dev


回答 9

在中setup.py,如果您有:

from distutils.core import setup

然后,将其更改为

from setuptools import setup

然后重新创建您的virtualenv并重新运行该命令,它应该可以工作。

In your setup.py, if you have:

from distutils.core import setup

Then, change it to

from setuptools import setup

Then re-create your virtualenv and re-run the command, and it should work.


回答 10

尝试通过从setuptools而不是distutils.core导入安装程序来修改setup.py文件

Try modifying the setup.py file by importing setup from setuptools instead of distutils.core


回答 11

apt-get install python3-dev在Ubuntu中做过,并添加setup_requires=["wheel"]setup.py

I did apt-get install python3-dev in my Ubuntu and added setup_requires=["wheel"] in setup.py


回答 12

它帮助我按照此处的说明进行操作:

https://packaging.python.org/guides/installing-using-linux-tools/

Debian / Ubuntu

Python 2:

sudo apt install python-pip

Python 3:

sudo apt install python3-venv python3-pip

It helped me to follow instructions in here:

https://packaging.python.org/guides/installing-using-linux-tools/

Debian/Ubuntu

Python 2:

sudo apt install python-pip

Python 3:

sudo apt install python3-venv python3-pip

回答 13

使用Ubuntu 18.04,可以通过安装python3-wheel软件包来解决此问题。

通常,它是作为对任何Python包的依赖项安装的。但是尤其是在构建容器映像时,您经常使用--no-install-recommends它,因此常常会丢失它,因此必须首先手动安装。

Using Ubuntu 18.04 this problem can be resolved by installing the python3-wheelpackage.

Usually this is installed as a dependency on any Python package. But especially when building container images you often work with --no-install-recommends and therefore it is often missing and has to be installed manually first.


回答 14

与Travis CI无关,但是尝试jupyter在Mac OSX 10.8.5上安装时遇到了类似的问题,其他答案都没有帮助。该问题是由于为名为“pyzmq,错误消息填充了数百页。

我发现的解决方案是直接安装该软件包的旧版本:

python -m pip install pyzmq==17 --user

之后,安装jupyter成功,没有错误。

Not related to Travis CI but I ran into similar problem trying to install jupyter on my Mac OSX 10.8.5, and none of the other answers was of help. The problem was caused by building the “wheel” for the package called pyzmq, with error messages filling hundreds of pages.

The solution I found was to directly install an older version of that package:

python -m pip install pyzmq==17 --user

After that, the installation of jupyter succeded without errors.


回答 15

如果您使用的是setup.cfg文件,请将其添加到install_require零件之前:

setup_requires =
    wheel

setup.cfg项目示例:

# setup.py
from setuptools import setup

setup()
# setup.cfg
[metadata]
name = name
version = 0.0.1
description = desc
long_description = file: README.md
long_description_content_type = text/markdown
url = url
author = author
classifiers =
    Programming Language :: Python
    Programming Language :: Python :: 3

[options]
include_package_data = true
packages = find:
setup_requires =
    wheel
install_requires =
    packages
    packages
    packages

If you’re using setup.cfg files, add this before the install_require part:

setup_requires =
    wheel

Example of setup.cfg project :

# setup.py
from setuptools import setup

setup()
# setup.cfg
[metadata]
name = name
version = 0.0.1
description = desc
long_description = file: README.md
long_description_content_type = text/markdown
url = url
author = author
classifiers =
    Programming Language :: Python
    Programming Language :: Python :: 3

[options]
include_package_data = true
packages = find:
setup_requires =
    wheel
install_requires =
    packages
    packages
    packages