python3.10版本通过cmd命令使用pip安装第三方包多个报错解决办法

python安装的可能有点问题在使用cmd安装第三方包的时候陆续报了一下错误


(c) Microsoft Corporation。保留所有权利。

C:\Users\Administrator>pip install numpy
Traceback (most recent call last):
  File "runpy.py", line 196, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "G:\Python\Scripts\pip.exe\__main__.py", line 4, in
ModuleNotFoundError: No module named 'pip'

C:\Users\Administrator>python -m ensurepip
G:\Python\python.exe: No module named ensurepip

C:\Users\Administrator>python get-pip.py
python: can't open file 'C:\\Users\\Administrator\\get-pip.py': [Errno 2] No such file or directory

C:\Users\Administrator>pip install numpy
ERROR: Operation cancelled by user

到此为止通过一篇文章发现解决办法,在python目录下找到python310._pth文件,(我的是3.10版本,其他的版本应该是可以使用python3‘x’._pth)用记事本打开文件,并在首行添加

Lib\site-packages

这一步的目的是修改调用pip的方式,解决后效果如下

C:\Users\Administrator>pip -V
pip 23.1.2 from g:\python\pip (python 3.10)

但是再尝试安装发现仍然报错

C:\Users\Administrator>pip install -i https://pypi.tuna.tainghua.edu.cn/simple numpy
Looking in indexes: https://pypi.tuna.tainghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/numpy/
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy

又尝试几个命令

C:\Users\Administrator>python -m pip install
ERROR: You must give at least one requirement to install (see "pip help install")

C:\Users\Administrator>python -m ensurepip
G:\Python\python.exe: No module named ensurepip

C:\Users\Administrator>python get-pip.py
python: can't open file 'C:\\Users\\Administrator\\get-pip.py': [Errno 2] No such file or directory

找到了第一个能开始下载的镜像地址

C:\Users\Administrator>pip install matplotlib-i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
Collecting http://mirrors.aliyun.com/pypi/simple
  Downloading http://mirrors.aliyun.com/pypi/simple (23.1 MB)
     ---------------------------------------- 23.1/23.1 MB 1.4 MB/s eta 0:00:00
  ERROR: Cannot unpack file C:\Users\Administrator\AppData\Local\Temp\pip-unpack-bqsqhywl\simple (downloaded from C:\Users\Administrator\AppData\Local\Temp\pip-req-build-qe7u3hde, content-type: text/html; charset=utf-8); cannot detect archive format
ERROR: Cannot determine archive format of C:\Users\Administrator\AppData\Local\Temp\pip-req-build-qe7u3hde

但是还是报错了,然后继续搜索解决错误的博客

最后解决了

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn 包名

使用上述命令后效果如下

C:\Users\Administrator>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn numpy
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting numpy
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/65/5d/46da284b0bf6cfbf04082c3c5e84399664d69e41c11a33587ad49b0c64e5/numpy-1.24.3-cp310-cp310-win_amd64.whl (14.8 MB)
     ---------------------------------------- 14.8/14.8 MB 121.5 kB/s eta 0:00:00
Installing collected packages: numpy
Successfully installed numpy-1.24.3

你可能感兴趣的:(笔记,python)