我是一名Python 语言的新手.早些时候,我安装了一些包,如matplotlib、nupy、pip(23.3.1版)、Well(0.41.2版)等,并用它们进行了一些编程.我使用命令C:\Users\UserName>pip list来查找我已经安装的包的列表,并且我正在使用Python3.12.0(通过使用代码C:\Users\UserName>py -V).

我需要用pyspedas来分析一些数据.我正在按照从SITE收到的说明安装包,但有一个变化(我不确定这是否重要:我使用的是py,而不是python).我使用的命令的顺序是:

py -m venv pyspedas
.\pyspedas\Scripts\activate
pip install pyspedas

在最后一步之后,我得到了以下输出:

Collecting pyspedas
  Using cached pyspedas-1.4.47-py3-none-any.whl.metadata (14 kB)
Collecting numpy>=1.19.5 (from pyspedas)
  Using cached numpy-1.26.1-cp312-cp312-win_amd64.whl.metadata (61 kB)
Collecting requests (from pyspedas)
  Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)
Collecting geopack>=1.0.10 (from pyspedas)
  Using cached geopack-1.0.10-py3-none-any.whl (114 kB)
Collecting cdflib<1.0.0 (from pyspedas)
  Using cached cdflib-0.4.9-py3-none-any.whl (72 kB)
Collecting cdasws>=1.7.24 (from pyspedas)
  Using cached cdasws-1.7.43.tar.gz (21 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting netCDF4>=1.6.2 (from pyspedas)
  Using cached netCDF4-1.6.5-cp312-cp312-win_amd64.whl.metadata (1.8 kB)
Collecting pywavelets (from pyspedas)
  Using cached PyWavelets-1.4.1.tar.gz (4.6 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [33 lines of output]
      Traceback (most recent call last):
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 112, in get_requires_for_build_wheel
          backend = _build_backend()
                    ^^^^^^^^^^^^^^^^
        File "C:\Users\UserName\pyspedas\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 77, in _build_backend
          obj = import_module(mod_path)
                ^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\UserName\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1304, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
        File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
        File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 994, in exec_module
        File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\setuptools\__init__.py", line 16, in <module>
          import setuptools.version
        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\setuptools\version.py", line 1, in <module>
          import pkg_resources
        File "C:\Users\UserName\AppData\Local\Temp\pip-build-env-_lgbq70y\overlay\Lib\site-packages\pkg_resources\__init__.py", line 2191, in <module>
          register_finder(pkgutil.ImpImporter, find_on_path)
                          ^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

经过一点谷歌搜索,我才知道这个问题在多个地方都有报道,但这个包没有.我确实在答案here中提到的新环境中安装了车轮,但问题仍然存在.

我没有设置虚拟环境,而是简单地执行了命令py -m pip install pyspedas.但我还是犯了错误.

我所能了解到的是,该计划存在一个问题

Collecting pywavelets (from pyspedas)
  Using cached PyWavelets-1.4.1.tar.gz (4.6 MB)
  Installing build dependencies ... done

我在Windows 11中使用的是IDLE.

有人能帮我吗? 谢谢,提前.

Edit (2023-10-27):我遇到的问题似乎是因为latest version of python.当我重新安装旧版本的python(在我的例子中是Python 3.11.4)时,没有问题.感谢@悟空(见答案的 comments ).

推荐答案

如果你能用python 3.11,那么你就不会面临任何问题.看起来问题还在继续.


AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?应为python 3.12

由于删除了长期不推荐使用的pkgutil.ImpImporter类,pip命令可能不适用于Python 3.12

这是一个描述它的帖子的链接:https://ubuntuh和book.org/index.php/2023/10/fix-broken-pip-python-312-ubuntu/

you just have to manually install pip for Python 3.12

有几种方法可以解决此问题:

Task 1:

Python附带了一个ensurepip,它可以在Python环境中安装pip.

https://pip.pypa.io/en/stable/installation/

Linux/MacOS端子上:

python -m ensurepip --upgrade

On Windows:

py -m ensurepip --upgrade

然后:

pip install --upgrade setuptools

Task 2:

https://virtualenv.pypa.io/en/latest/installation.html

你需要通过以下方式安装软件包(virtualenv):

python -m pip install --user virtualenv

如果它已经存在,则:

pip install --upgrade virtualenv

然后:

通过以下方式创建新的虚拟环境:

virtualenv your_virtual_environment --python=python3.12

激活your_virtual_environment,您就可以安装包了.

一百:

virtualenv喜欢缓存包以节省加载环境,包括缓存旧版本的PIP

你可能有一个旧的缓存版本的pip在你的计算机.

您可能需要运行:

virtualenv --upgrade-embed-wheels

virtualenv --reset-app-data

最好也升级setuptools:

python3.12 -m pip install --upgrade setuptools

https://pythontest.com/posts/2023/2023-10-02-py312-impimporter/



引用自:https://github.com/readthedocs/readthedocs.org/pull/10844

pip的过时版本仍然是主要问题,但pip的过时版本不是来自python安装,而是来自virtualenv创建.

在创建环境时,Virtualenv会安装一些特定的/过时的pip/setupTools/wills版本.

virtualenv


相关GITS:

https://github.com/pypa/pip/issues/11501

https://github.com/xlwings/xlwings/issues/2342

https://github.com/pypa/pip/issues/12179

https://github.com/readthedocs/readthedocs.org/issues/10832

https://github.com/pypa/setuptools/issues/3935

https://github.com/googleapis/gapic-generator-python/issues/1824

Python相关问答推荐

Pandas dataframe中str.place()的奇怪行为.删除与目标字符串不匹配的值

Python-迭代PANAS中的数据框并替换列表中不包含字符串的值

在多索引的Pandas数据帧中,有可能有一个值引用更高级别索引的列吗?

优化数组加法(y,x,RGBA)

为什么要导入一个Python类来实例化它?

压平JSON后的Pandas 保留柱

为什么我不能在Sphinxcontrib-HttpExample中使用python来换行JSON属性?

我正在试着做一个简单的程序来判断学校的一个项目的调查数据,但它不起作用,有人能帮我吗?

支持向量机模型突出错误的数据点作为支持向量

使用CSS Select 器和::before抓取不会显示文本

用于具有多个输出的函数的JAX`Custom_vjp`

如何在Python中处理钻石依赖?

在模拟无限WHILE循环下的IF语句暂停整个程序

删除2个列标题,并在数据帧中将整个列行左移

到docker.套接字(使用aiodocker)的100个连接的限制从何而来?

使用类和词典键入Numba函数

如何正确地定义一个类方法来访问一个损坏的子属性的值?

在使用pip安装时,我应该写jupyter_server还是jupyter-server?

在POLAS中运行GROUP_BY_DYNAMIC,但仅在时间戳上运行

迭代地将任意深度列表转换为字典