一、更换pip为国内源
1.使用PyCharm创建一个工程
2.通过File -> Setting…
选择解释器为本工程下的Python解释器。
3.单击下图中添加“+”,
4.单击下图中的“Manage Repositories”按钮,
6.目前国内靠谱的 pip 镜像源有:
1 2 |
清华:https://pypi.tuna.tsinghua.edu.cn/simple |
1 2 |
阿里云:http://mirrors.aliyun.com/pypi/simple/ |
1 2 |
中国科技大学 :https://pypi.mirrors.ustc.edu.cn/simple/ |
1 2 |
豆瓣:http://pypi.douban.com/simple/ |
择一即可。
使用PyCharm内的终端进行安装所需模块即可:
二、有的包只能使用pip默认源下载
使用清华源等国内源下载速度很快,但是修改pip默认镜像源后,有的包可能只有默认源有。只能临时使用默认源安装:(pip默认镜像地址:https://pypi.org/simple)
1 2 |
pip install <module> -i https://pypi.org/simple |
三、镜像源使用方法:
1 2 |
pip install <module> -i <镜像源> |
四、PyCharm依赖包导入导出方法
在PyCharm的terminal中输入:
1.将依赖包导出至requirements文件
1 2 |
pip freeze > requirements.txt |
2.从requirements文件中导入依赖包
1 2 |
pip install -r requirements.txt |