最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何使用conda和pip批量安裝Python包

 更新時(shí)間:2023年02月02日 14:46:59   作者:macan_dct  
這篇文章主要介紹了如何使用conda和pip批量安裝Python包問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

使用conda和pip批量安裝Python包

在debug Yolov5之前,需要按照其txt文件中指定的包的版本來指定安裝工程需要的Python包,截圖如下:

(這里面的torch慎裝,因?yàn)檫@種方式裝的pytorch不吃吃GPU,如果某個(gè)包不想安裝,只要在該行前面輸入注釋符就行)

conda方式批量安裝

進(jìn)入(cd)到txt文件所在文件夾路徑下,運(yùn)行以下命令:

$ conda install --file=requirements_conda.txt

pip方式批量安裝

pip install -r requirements_conda.txt

conda和pip總結(jié)

conda相關(guān)

基本命令

  • 查看conda相關(guān)信息:conda info
  • 顯示所有的虛擬環(huán)境: conda info -e(–envs)
  • 激活環(huán)境:conda activate xxxx
  • 關(guān)閉環(huán)境:conda deactivate

創(chuàng)建、刪除虛擬環(huán)境

  • 創(chuàng)建環(huán)境: conda create -n xxxx python=3.7 #創(chuàng)建python3.7的xxxx虛擬環(huán)境
  • 刪除環(huán)境:conda remove -n xxxx --all //刪除xxxx虛擬環(huán)境

復(fù)制、重命名環(huán)境

Conda是沒有重命名環(huán)境的功能的, 要實(shí)現(xiàn)這個(gè)基本需求, 只能通過愚蠢的克隆-刪除的過程,切記不要直接mv移動(dòng)環(huán)境的文件夾來重命名, 會(huì)導(dǎo)致一系列無法想象的錯(cuò)誤的發(fā)生!

  • 克隆oldname環(huán)境為newname環(huán)境: conda create --name newname --clone oldname
  • 徹底刪除舊環(huán)境:conda remove --name oldname --all

注意:必須在base環(huán)境下進(jìn)行以上操作,否則會(huì)出現(xiàn)各種莫名的問題。

安裝、更新、卸載安裝包

  • 查看已經(jīng)安裝的文件包: conda list
  • 指定查看xxx虛擬環(huán)境下安裝的package: conda list -n xxx
  • 安裝xxx文件包:conda install xxx
  • 更新xxx文件包:conda update xxx
  • 卸載xxx文件包:conda uninstall xxx

conda安裝requirements中的包:

conda install --yes --file requirements.txt

但是這里存在一個(gè)問題,如果requirements.txt中的包不可用,則會(huì)拋出“無包錯(cuò)誤”。使用下面這個(gè)命令可以解決這個(gè)問題

while read requirement; do conda install --yes $requirement; done < requirements.txt

如果想要在conda命令無效時(shí)使用pip命令來代替,那么使用如下命令:

while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt

conda安裝包清理(conda瘦身)

  • conda clean -H:查看conda clean使用參數(shù)
  • conda clean -p:刪除一些沒用的包,這個(gè)命令會(huì)檢查哪些包沒有在包緩存中被硬依賴到其他地方,并刪除它們
  • conda clean -t:可以刪除conda保存下來的tar包。
  • conda clean -a:刪除索引緩存、鎖定文件、未使用過的包和tar包。

conda自動(dòng)開啟/關(guān)閉激活

  • 關(guān)閉自動(dòng)激活狀態(tài): conda config --set auto_activate_base false
  • 開啟自動(dòng)激活狀態(tài): conda config --set auto_activate_base true

conda批量導(dǎo)出、安裝:

  • 可以導(dǎo)出到.yml文件:conda env export > freeze.yml
  • 然后直接創(chuàng)建conda環(huán)境:conda env create -f freeze.yml

解決conda install 下載速度慢,conda數(shù)據(jù)源管理

  • 查看配置信息:conda config --show
  • 顯示目前conda的數(shù)據(jù)源有哪些: conda config --show channels

添加數(shù)據(jù)源:例如, 添加清華anaconda鏡像:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
conda config --add channels ?https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

然后運(yùn)行conda clean -i清除索引緩存,保證用的是鏡像站提供的索引

刪除單個(gè)數(shù)據(jù)源:

conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

恢復(fù)默認(rèn)源:conda config --remove-key channels

pip相關(guān)

安裝、更新、卸載包

  • 列出當(dāng)前緩存的包:pip list
  • 安裝xxx包: pip install xxx
  • 卸載xxx包: pip uninstall xxx
  • 展示指定的已安裝的xxx包: pip show xxx
  • 檢查xxx包的依賴是否合適:pip check xxx

pip數(shù)據(jù)源管理

  • 顯示目前pip的數(shù)據(jù)源有哪些:pip config list
  • 臨時(shí)使用數(shù)據(jù)源:pip install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple

永久使用該數(shù)據(jù)源:

方法一:

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple
pip config set global.trusted-host mirrors.aliyun.com

方法二:配置文件配置

vim ~/.pip/pip.conf

寫入以下內(nèi)容:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple
trusted-host = mirrors.aliyun.com

記錄一下pip國內(nèi)源

  • 阿里云: https://mirrors.aliyun.com/pypi/simple/
  • 中國科技大學(xué): https://pypi.mirrors.ustc.edu.cn/simple/
  • 豆瓣(douban):  https://pypi.douban.com/simple/
  • 清華大學(xué):  https://pypi.tuna.tsinghua.edu.cn/simple/
  • 中國科學(xué)技術(shù)大學(xué):  https://pypi.mirrors.ustc.edu.cn/simple/
  • 騰訊源: https://mirrors.cloud.tencent.com/pypi/simple

pip批量導(dǎo)出、安裝:

  • 生成requirements.txt文件:pip freeze > requirements.txt
  • 安裝requirements.txt文件依賴:pip install -r requirements.txt

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

四会市| 静安区| 封丘县| 潜山县| 永定县| 张北县| 建阳市| 利津县| 衡南县| 乡城县| 木里| 泸水县| 逊克县| 庆城县| 牟定县| 普兰县| 枝江市| 宁安市| 依兰县| 长葛市| 龙胜| 二手房| 望城县| 宜宾市| 盐亭县| 炉霍县| 琼中| 沙田区| 玉龙| 石屏县| 岑溪市| 富蕴县| 南城县| 大庆市| 通道| 徐水县| 石狮市| 通江县| 丰原市| 曲水县| 烟台市|