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


当前回答

pip install wheel

为我工作,但你也可以添加这个

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

安装.py并保存一个pip安装命令

其他回答

我的修复是apt-install python3 dev

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

from setuptools import setup

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

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

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

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

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

也许,你的pip版本已经过时了。在新创建的虚拟环境中安装模块时,我在WSL中遇到了同样的问题。我能够通过运行以下命令来解决此问题:

$ ./bin/python3 -m pip install --upgrade pip