歪打正着解决 ModuleNotFoundError: No module named ‘setuptools.command.build‘ 问题

用户在Anaconda创建的Python3.7环境中遇到使用pip安装包时模块setuptools.command.build找不到的问题。尝试升级pip、setuptools和wheel等方法无效。最终发现是setuptools版本问题,通过卸载并重新安装setuptools解决了问题,成功安装了pinyin包。
摘要由CSDN通过智能技术生成

利用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,哈哈哈,不知道怎么想的,直接省略了前一个步骤,执行了第二个命令,我的天,发生了啥,竟然成功了,虽然我也不知道原因出在哪里,但这个问题真的困扰了我很久了!!必须记录一下
在这里插入图片描述

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可爱的小张同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值