利用Anaconda创建了一个python3.7的环境,后续通过pip install命令安装很多包时,均遇到了 ModuleNotFoundError: No module named ‘setuptools.command.build’ ,遇见了很多次,我去网上查看,好多人都遇见了这个问题,我尝试了很多人推荐的的方法,都无法解决问题:
python3 -m pip install --upgrade pip setuptools wheel
后来我还尝试了
pip3 install 包名 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
甚至我还更新了pip版本
pip install --upgrade pip
更新setuptools版本
pip install --upgrade setuptools
但这大家来说很有效的方法,对我来说毫无用处!!!!!下边我将以pip install pinyin -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com这条命令为例,来完整的展示一下问题到底是什么。
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting pinyin
Using cached http://mirrors.aliyun.com/pypi/packages/32/95/d2969f1071b7bc0afff407d1d7b4b3f445e8e6b59df7921c9c09e35ee375/pinyin-0.4.0.tar.gz (3.6 MB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [51 lines of output]
running egg_info
creating C:\Users\zdm\AppData\Local\Temp\pip-pip-egg-info-pp39i6cl\pinyin.egg-info
writing C:\Users\zdm\AppData\Local\Temp\pip-pip-egg-info-pp39i6cl\pinyin.egg-info\PKG-INFO
writing dependency_links to C:\Users\zdm\AppData\Local\Temp\pip-pip-egg-info-pp39i6cl\pinyin.egg-info\dependency_links.txt
writing entry points to C:\Users\zdm\AppData\Local\Temp\pip-pip-egg-info-pp39i6cl\pinyin.egg-info\entry_points.txt
writing top-level names to C:\Users\zdm\AppData\Local\Temp\pip-pip-egg-info-pp39i6cl\pinyin.egg-info\top_level.txt
writing manifest file 'C:\Users\zdm\AppData\Local\Temp\pip-pip-egg-info-pp39i6cl\pinyin.egg-info\SOURCES.txt'
Traceback (most recent call last):
File "<string>", line 36, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\zdm\AppData\Local\Temp\pip-install-0s80o2m4\pinyin_ab01038a81c249598cc1f2a7b59501b2\setup.py", line 34, in <module>
"Programming Language :: Python :: Implementation :: PyPy",
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "D:\anaconda3\envs\py37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "D:\anaconda3\envs\py37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "D:\anaconda3\envs\py37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\command\egg_info.py", line 299, in run
self.find_sources()
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\command\egg_info.py", line 306, in find_sources
mm.run()
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\command\egg_info.py", line 541, in run
self.add_defaults()
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\command\egg_info.py", line 578, in add_defaults
sdist.add_defaults(self)
File "D:\anaconda3\envs\py37\lib\distutils\command\sdist.py", line 226, in add_defaults
self._add_defaults_python()
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\command\sdist.py", line 111, in _add_defaults_python
build_py = self.get_finalized_command('build_py')
File "D:\anaconda3\envs\py37\lib\distutils\cmd.py", line 299, in get_finalized_command
cmd_obj.ensure_finalized()
File "D:\anaconda3\envs\py37\lib\distutils\cmd.py", line 107, in ensure_finalized
self.finalize_options()
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\command\build_py.py", line 29, in finalize_options
orig.build_py.finalize_options(self)
File "D:\anaconda3\envs\py37\lib\distutils\command\build_py.py", line 45, in finalize_options
('force', 'force'))
File "D:\anaconda3\envs\py37\lib\distutils\cmd.py", line 286, in set_undefined_options
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
File "D:\anaconda3\envs\py37\lib\distutils\dist.py", line 857, in get_command_obj
klass = self.get_command_class(command)
File "D:\anaconda3\envs\py37\lib\site-packages\setuptools\dist.py", line 893, in get_command_class
self.cmdclass[command] = cmdclass = ep.load()
File "D:\anaconda3\envs\py37\lib\site-packages\pkg_resources\__init__.py", line 2465, in load
return self.resolve()
File "D:\anaconda3\envs\py37\lib\site-packages\pkg_resources\__init__.py", line 2471, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'setuptools.command.build'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
最开始,我只关注了**ModuleNotFoundError: No module named 'setuptools.command.build,我查了很多资料,问题并未解决【哭唧唧,已经开始怀疑人生了】。而且我发现我创建的另外一个python3.8的环境,可以很容易的通过pip install pinyin**进行安装,我真的,我开始怀疑python版本的影响了,哈哈哈。
后来,我想着我得完整的看一下这个错误,看看到底是哪个环节出了问题?然后我又看见了**× python setup.py egg_info did not run successfully. │ exit code: 1,然后我又去百度,又去查原因,然后我看到了需要开通专栏才能看的博客,天生一身反骨,需要花钱??不不不,我就不开!!然后我继续看呀看呀看呀,突然灵光一现,我通过pip list看了一下python3.8环境安装的包中,到底有没有setuptools**,果然,我发现这里的版本是67.7.2。然而我的python3.7环境中,setuptools包的版本是65.6.3。
抱着试一试的想法,我执行了pip uninstall setuptools。
当时脑子里还纠结了一会,是不是需要先执行pip install setuptools==67.7.2,然后再试pip3 install pinyin -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com,哈哈哈,不知道怎么想的,直接省略了前一个步骤,执行了第二个命令,我的天,发生了啥,竟然成功了,虽然我也不知道原因出在哪里,但这个问题真的困扰了我很久了!!必须记录一下