安裝第三方庫,提示:
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'D:\Programming\Python_Virtaul_Env\Python_Study\newvenv\Scripts\python.exe'.
原因和解決辦法
1.pycharm里安裝的pip與電腦中按照的pip版本不一致
1)setting->project-project Interprete->查看pip的版本為19.2,
在cmd中查看: pip list -->安裝的pip版本為21.3.1
解決方法1:setting->project-project Interpreter->點擊pip->右側找到pip的版本選21.3.1,安裝完成。
解決方法2:使用方法1,可能還是提示無法安裝,這時可以嘗試先卸載,然后再安裝
python3-m pip install --upgrade pip --force-reinstall
python -m pip uninstall pip
pycharm Terminal 中執行:
先下載:
https://bootstrap.pypa.io/get-pip.py然后切換到對應目錄,
再執行:python get-pip.py
檢查安裝的版本,在cmd或 pycharm Terminal 中執行:
>>pip --version
【https://www.cnblogs.com/yaradish/p/10632246.html】
解決方法3:嘗試 切換下載源可能會解決問題
https://mirrors.aliyun.com/pypi/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
解決方法4:
將對應虛擬環境\Lib\site-packages\目錄下的pip文件夾刪除,
然后重新安裝,或者從python的安裝目錄拷貝一份過來,包括:pip文件夾和setup文件夾
D:\Programs\Python\Python38-32\Lib\site-packages
解決方法5:直接使用命令行安裝
pip install --trusted-host pypi.tuna.tsinghua.edu.cn -i https://pypi.tuna.tsinghua.edu.cn/simple flask
或者使用執行如下python腳本,調用命令行來安裝
#coding:utf-8 import os pipName = input("請輸入pip名字:") cmdstr = ("pip install "+ pipName +" -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com") information = os.popen(cmdstr) re = information.read() print(re) # cmd函數 def popen(cmd, mode="r", buffering=-1): if not isinstance(cmd, str): raise TypeError("invalid cmd type (%s, expected string)" % type(cmd)) if mode not in ("r", "w"): raise ValueError("invalid mode %r" % mode) if buffering == 0 or buffering is None: raise ValueError("popen() does not support unbuffered streams") import subprocess, io if mode == "r": proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, bufsize=buffering) return os._wrap_close(io.TextIOWrapper(proc.stdout), proc) else: proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, bufsize=buffering) return os._wrap_close(io.TextIOWrapper(proc.stdin), proc)