我的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。


当前回答

正如@Philippe Remy所提到的,应从setuptools导入

from setuptools import setup

参考:官方文件https://setuptools.pypa.io/en/latest/index.html

其他回答

这个错误很奇怪,因为许多人都提出了答案,但得到的解决方案却不尽相同。我试过了,加上它们。直到我添加了pip安装时,升级pip才为我消除了错误。但我没有时间隔离哪个是哪个,所以这只是fyi。

它帮助我遵循这里的指示:

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

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

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

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

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

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

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

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

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