python环境切换导致的pip问题

最近打算使用aiohttp做一些实验,但是发现aiohttp一直装不上,安装报错

Building wheel for aiohttp (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for aiohttp (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [111 lines of output]
      *********************
      * Accelerated build *
      *********************
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-312
      creating build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\abc.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\base_protocol.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\client.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\client_exceptions.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\client_proto.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\client_reqrep.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\client_ws.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\connector.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\cookiejar.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\formdata.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\hdrs.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\helpers.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\http.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\http_exceptions.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\http_parser.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\http_websocket.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\http_writer.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\locks.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\log.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\multipart.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\payload.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\payload_streamer.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\pytest_plugin.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\resolver.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\streams.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\tcp_helpers.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\test_utils.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\tracing.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\typedefs.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_app.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_exceptions.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_fileresponse.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_log.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_middlewares.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_protocol.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_request.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_response.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_routedef.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_runner.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_server.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_urldispatcher.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\web_ws.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\worker.py -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\__init__.py -> build\lib.win-amd64-cpython-312\aiohttp
      running egg_info
      writing aiohttp.egg-info\PKG-INFO
      writing dependency_links to aiohttp.egg-info\dependency_links.txt
      writing requirements to aiohttp.egg-info\requires.txt
      writing top-level names to aiohttp.egg-info\top_level.txt
      reading manifest file 'aiohttp.egg-info\SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no files found matching 'aiohttp' anywhere in distribution
      warning: no previously-included files matching '*.pyc' found anywhere in distribution
      warning: no previously-included files matching '*.pyd' found anywhere in distribution
      warning: no previously-included files matching '*.so' found anywhere in distribution
      warning: no previously-included files matching '*.lib' found anywhere in distribution
      warning: no previously-included files matching '*.dll' found anywhere in distribution
      warning: no previously-included files matching '*.a' found anywhere in distribution
      warning: no previously-included files matching '*.obj' found anywhere in distribution
      warning: no previously-included files found matching 'aiohttp\*.html'
      no previously-included directories found matching 'docs\_build'
      adding license file 'LICENSE.txt'
      writing manifest file 'aiohttp.egg-info\SOURCES.txt'
      copying aiohttp\_cparser.pxd -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_find_header.pxd -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_headers.pxi -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_helpers.pyi -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_helpers.pyx -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_http_parser.pyx -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_http_writer.pyx -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\_websocket.pyx -> build\lib.win-amd64-cpython-312\aiohttp
      copying aiohttp\py.typed -> build\lib.win-amd64-cpython-312\aiohttp
      creating build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_cparser.pxd.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_find_header.pxd.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_helpers.pyi.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_helpers.pyx.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_http_parser.pyx.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_http_writer.pyx.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\_websocket.pyx.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      copying aiohttp\.hash\hdrs.py.hash -> build\lib.win-amd64-cpython-312\aiohttp\.hash
      running build_ext
      building 'aiohttp._websocket' extension
      creating build\temp.win-amd64-cpython-312
      creating build\temp.win-amd64-cpython-312\Release
      creating build\temp.win-amd64-cpython-312\Release\aiohttp
      "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -ID:\python\include -ID:\python\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" -ID:\sdk\include\10.0.17763.0\ucrt -ID:\sdk\include\10.0.17763.0\shared -ID:\sdk\include\10.0.17763.0\um -ID:\sdk\include\10.0.17763.0\winrt -ID:\sdk\include\10.0.17763.0\cppwinrt /Tcaiohttp/_websocket.c /Fobuild\temp.win-amd64-cpython-312\Release\aiohttp/_websocket.obj
      _websocket.c
      aiohttp/_websocket.c(1475): warning C4996: 'Py_OptimizeFlag': deprecated in 3.12
      d:\python\include\cpython/pydebug.h(13): note: 参见“Py_OptimizeFlag”的声明
      aiohttp/_websocket.c(3042): error C2039: “ob_digit”: 不是“_longobject”的成员
      d:\python\include\cpython/longintrepr.h(87): note: 参见“_longobject”的声明
      aiohttp/_websocket.c(3097): error C2039: “ob_digit”: 不是“_longobject”的成员
      d:\python\include\cpython/longintrepr.h(87): note: 参见“_longobject”的声明
      aiohttp/_websocket.c(3238): error C2039: “ob_digit”: 不是“_longobject”的成员
      d:\python\include\cpython/longintrepr.h(87): note: 参见“_longobject”的声明
      aiohttp/_websocket.c(3293): error C2039: “ob_digit”: 不是“_longobject”的成员
      d:\python\include\cpython/longintrepr.h(87): note: 参见“_longobject”的声明
      aiohttp/_websocket.c(3744): error C2039: “ob_digit”: 不是“_longobject”的成员
      d:\python\include\cpython/longintrepr.h(87): note: 参见“_longobject”的声明
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for aiohttp
Failed to build aiohttp
ERROR: Could not build wheels for aiohttp, which is required to install pyproject.toml-based projects

对于这个错误显示的Microsoft Visual Studio工具相关错误,怀疑为之前重装过不同的python版本导致,最后重新装了一个python3.9.8版本,路径直接放D盘下面,之后输入python --version查看版本之后,出现为空
在这里插入图片描述
环境变量又配置了python39的路径,在官网下载之后的文件夹默认命名为Python+版本号,安装前勾选添加到环境变量,因此环境变量如下
在这里插入图片描述
以前安装的文件名为python,把文件名python39改成了python之后就能显示版本号了,环境变量如上图所示没有改动,这里一度怀疑是有缓存没有清除(希望知道原因的大佬解释一下)
在这里插入图片描述
之后使用pip命令查看内容,出现错误

Fatal error in launcher: Unable to create process using '"D:\python39\python.exe"  "D:\python\Scripts\pip.exe" ': ???????????

在这里插入图片描述
此时使用python -m pip install --upgrade pip进行pip更新又出现以下报错

Traceback (most recent call last):
  File "D:\python\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\python\lib\site-packages\pip\__main__.py", line 29, in <module>
    from pip._internal.cli.main import main as _main
  File "D:\python\lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "D:\python\lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "D:\python\lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "D:\python\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 21, in <module>
    from pip._vendor.packaging.utils import canonicalize_name
  File "D:\python\lib\site-packages\pip\_vendor\packaging\utils.py", line 8, in <module>
    from .tags import Tag, parse_tag
  File "D:\python\lib\site-packages\pip\_vendor\packaging\tags.py", line 8, in <module>
    import sysconfig
  File "D:\python\lib\sysconfig.py", line 555, in <module>
    def get_paths(scheme=get_default_scheme(), vars=None, expand=True):
NameError: name 'get_default_scheme' is not defined. Did you mean: '_get_default_scheme'?

最后通过查一下资料,发现需要将旧的pip源文件进行删除,有两个位置需要清楚,具体路径为python/Lib/site-packages/pip-xx.xx.xx.dist-info,由于python版本不同,此处版本号不一定一样
在这里插入图片描述
另一处路径如下python/Scripts/,所有pip开头的文件
在这里插入图片描述
最后一步进行安装

python -m pip install --upgrade pip

在这里插入图片描述
重装完成之后正常使用
在这里插入图片描述
使用pycharm安装aiohttp库也成功了,如果用命令行方式使用

pip install aiohttp

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/skybulex/article/details/131953488