python使用pip安装第三方模块常见问题及解决方法

一、下载速度过慢

使用国内源

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/ 

豆瓣:http://pypi.douban.com/simple/

使用例子

pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/

二、ImportError: cannot import name 'main'

由于pip版本的不同,可能会没有main模块,需要修改pip源文件
1、找到安装pycharm的路径,例如我的:F:IDEPyCharm 2019.3.3pluginspythonhelpers
2、修改文件夹中packaging_tool.py的两个函数
修改如下


def do_install(pkgs):
    try:
        try:
            from pip.internal import main
        except Exception:
            from pip._internal import main as main
    except ImportError:
	    error_no_pip()
    return main(['install'] + pkgs)

def do_uninstall(pkgs):
    try:
        try:
            from pip.internal import main
        except Exception:
            from pip._internal import main as main
    except ImportError:
	    error_no_pip()
    return main(['uninstall', '-y'] + pkgs)	

三、python package tools not found

出现这种情况一般是镜像源的问题,修改默认的镜像源安装地址,一般用国内的豆瓣或者清华的源,访问下载速度快。

豆瓣:http://pypi.douban.com/simple/
清华:https://pypi.tuna.tsinghua.edu.cn/simple
原文地址:https://www.cnblogs.com/best-hym/p/14817066.html