在开发python包时经常需要用到python setup.py develop将当前路径动态注册到python,
以后每次修改都不需要重新安装就可以在全局引用包。
但是最近发现在运行python setup.py develop时报错,显示
Traceback (most recent call last):
File "setup.py", line 38, in <module>
'attrs>=17.4.0'
File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/site-packages/setuptools/command/develop.py", line 27, in run
self.install_for_development()
File "/usr/lib/python2.7/site-packages/setuptools/command/develop.py", line 129, in install_for_development
self.process_distribution(None, self.dist, not self.no_deps)
File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 701, in process_distribution
distreq.project_name, distreq.specs, requirement.extras
TypeError: __init__() takes exactly 2 arguments (4 given)
原因是python默认安装了旧版本的setuptools,pip安装时不会删除默认版本,导致site-packages下面有多个版本
ll /lib/python2.7/site-packages | grep setuptools
drwxr-xr-x. 6 root root 4096 Jul 8 11:43 setuptools
drwxr-xr-x. 2 root root 179 Jul 8 11:43 setuptools-0.9.8-py2.7.egg-info
drwxr-xr-x. 2 root root 170 Jul 8 11:33 setuptools-41.0.1.dist-info
-rw-r--r--. 1 root root 33 Jul 8 11:33 setuptools.pth
解决方法是多次运行pip uninstall删除所有版本,再重新安装
pip uninstall setuptools
pip uninstall setuptools
pip install setuptools