noteswiki

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

安装第三方库,提示:

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)

 

 

 

posted on 2022-01-01 15:11  noteswiki  阅读(20392)  评论(0编辑  收藏  举报