TensorFlow與Python的版本對應(yīng),注意,一定要選擇對應(yīng)的版本,否則會讓你非常痛苦,折騰很久搞不清楚原因。
建議使用國內(nèi)鏡像源安裝
沒有GPU后綴的就表示是CPU版本的,不加版本就是最新
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
還可以指定版本
pip install tensorflow==1.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
GPU版本
pip install tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tensorflow-gpu==1.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
完成虛擬環(huán)境配置以及包的安裝就可以運(yùn)行程序啦
如下,成功了
pytorch也是一樣,但是要注意去pytorch官網(wǎng)上進(jìn)行版本的匹配和選擇
https://pytorch.org/get-started/previous-versions/
這里有不同模塊的版本對應(yīng),一定要看清楚了再安裝下載,不然很容易失敗。torchvision是專門做視覺的,如果不需要可以不下
cuda和pytorch的對應(yīng)
安裝,用清華源加速
pip install torch===1.7.0 torchvision===0.8.0 -i https://pypi.tuna
.tsinghua.edu.cn/simple
然后,出錯了,ERROR: torch has an invalid wheel, .dist-info directory not found
巧的是,貌似只有1.7安裝會出現(xiàn)這個問題,這個時候就不要再使用清華源了,所以有時候國內(nèi)鏡像源并非全能。
恢復(fù)到國外的
pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
注意,以上語法均是臨時使用清華源加速,若想默認(rèn),則使用以下語句設(shè)置
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
另外也可以使用離線下載安裝
https://download.pytorch.org/whl/torch_stable.html
選擇需要的版本進(jìn)行下載,cu102 # 表示 CUDA=10.2 ,cp37 # 表示 python=3.7
下載好 torch 的 .whl 文件后,用 pip 安裝,先 cd 到下載的文件夾,然后執(zhí)行安裝命令
pip install torch-1.7.0+cu101-cp36-cp36m-win_amd64.whl
如果下載了torchvision,則安裝也是一樣文章來源:http://www.zghlxwxcb.cn/news/detail-707547.html
pip install torchvision-0.8.0-cp36-cp36m-win_amd64.whl
注意注意注意
報錯一般情況下都是因為版本不匹配的問題,所以出錯了一定要從版本入手檢查問題,這樣才更容易解決問題文章來源地址http://www.zghlxwxcb.cn/news/detail-707547.html
到了這里,關(guān)于TensorFlow與pytorch特定版本虛擬環(huán)境的安裝的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!