conda和pip常用方法,更換源,包的安裝、更新、刪除、查看


conda和pip可以說各有優劣。pip的模塊更全更多,而conda使用更方便,安裝模塊時會檢查環境,自動下載。conda 特別是在數據分析方面,會對某些常用的包做了專門的優化。

更換源
pip
臨時更換
pip install <包名> -i https://pypi.douban.com/simple
1
上面使用的是豆瓣源,下面是其他國內源,替換上面的地址即可,都很快,隨便用哪個。

# 阿里雲 http://mirrors.aliyun.com/pypi/simple/
# 中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
# 豆瓣(douban) http://pypi.douban.com/simple/
# 清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
# 中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
1
2
3
4
5
永久更換
Windows
user目錄中創建一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini,內容如下:

[global]
index-url = http://pypi.douban.com/simple/
[install]
trusted-host=pypi.douban.com
1
2
3
4
Linux
修改 ~/.pip/pip.conf (沒有就創建一個), 添加內容與上面代碼一致。

mkdir ~/.pip/
vim ~/.pip/pip.conf
1
2
conda
Windows / Linux
Windows 和 Linux方法一致,並且是永久更換。

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
1
2
包管理
安裝
# pip
pip install <包名>
# conda
conda install <包名>
1
2
3
4
更新自己
# pip
python -m pip install --upgrade pip
# conda
conda update conda
1
2
3
4
查看過期的包
# pip兩種方法均可
pip list --outdated
pip list -o
#conda 查看所有包及其版本
conda list
1
2
3
4
5
單個更新包
# pip 兩種均可
pip install --upgrade <包名>
pip install -U <包名>
# conda
conda update <包名>
1
2
3
4
5
批量更新包
pip
以下是python代碼,需要打開Python后運行

import pip
from subprocess import call
from pip._internal.utils.misc import get_installed_distributions
for dist in get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
1
2
3
4
5
conda

conda update --all
————————————————

原文鏈接:https://blog.csdn.net/sscc_learning/article/details/85339529


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM