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


当前回答

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

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

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

其他回答

在我的情况下,venv创建的wheel/pip/setuptools版本太旧了。这是有效的:

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

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

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

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

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

如果以上这些都不适用于您,那么您可能也遇到了与我相同的问题。我只是在尝试安装pyspark时看到了这个错误。解决方案在另一个无法安装pyspark的stackoverflow问题中解释。

我发布了这篇b/c,从错误消息中看不出我的问题完全源于pyspark对pypandoc的依赖,我希望能让其他人免于数小时的头痛!=)

我在Ubuntu中安装了python3dev,并在setup.py中添加了setup_requires=[“wheel”]