pip 安装 numpy 报错 AttributeError: module ‘pkgutil‘ has no attribute ‘ImpImporter‘

conda 环境下 pip 安装 numpy 1.x 版本,报如下错误

        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\pkg_resources\__init__.py", line 2191, in 
          register_finder(pkgutil.ImpImporter, find_on_path)
                          ^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
      [end of output]

参考这个内容解决的问题:https://stackoverflow.com/questions/77364550/attributeerror-module-pkgutil-has-no-attribute-impimporter-did-you-mean

我没有试的方案

Due to the removal of the long-deprecated pkgutil.ImpImporter class, the pip command may not work for Python 3.12.

You just have to manually install pip for Python 3.12

(由于 python3.12 移除了长期过期的类 pkgutil.ImpImporter,对于 3.12 版本需要手动修复)

python -m ensurepip --upgrade
python -m pip install --upgrade setuptools
python -m pip install 

In your virtual environment:(虚拟环境下)

pip install --upgrade setuptools

(类似的,我还搜到了有人说可以降低 python 版本,我觉得是一个原理)


我采用的方案

由于我就是安装 numpy 有问题,安装其他的包没问题,所以一步到位,采用了下面的方案:python3.12 只能安装 numpy 1.26.4 版本(当然还可以安装 2.x)

To install numpy on Python 3.12, you must use numpy version 1.26.4

pip install numpy==1.26.4

问题搞定!


关于为何不安装 2.x 版本:因为我用的另一个包,强依赖 1.x 版本的 numpy,所以才有了上面的问题。

你可能感兴趣的:(我恨BUG,Linux运维,pip,numpy,python)