Win10+Anaconda3+TensorFlow 2.0.0+PyTorch1.3.1+OpenCV4.1

1.Anaconda3:

  • 常用命令
conda create -n 環境名 numpy python=3.6    #後面可以接其他包 =用來指明版本
conda list         # 查看安裝包列表
conda --version # 查看版本號
conda info -e    #用於查看擁有的環境
conda remove -n 虛擬環境名稱 --all    #刪除對應環境
conda create –n 新名 –-clone 舊名    #用於克隆,改名也蠻好的
  • Anaconda3安裝完成之後,以管理員身份運行anaconda propmt
  • 更新所有的庫
conda update --all 
  • 若Win10安裝Anacondad3之後沒有pip則執行:
# 以管理員身份運行
cd  C:\ProgramData\Anaconda3\Scripts
easy_install.exe pip
python -m pip install --user --upgrade pip

2. 安裝

  • 升級pip
python -m pip install --user --upgrade pip
  • 創建tensorflow模塊目錄
    conda create -n ai pip python=3.6

  • 激活模塊
    conda activate ai
  • 禁用模塊
conda deactivate

2.1 安裝PyTorch

(ai)xx> pip install torch===1.3.1 torchvision===0.4.1  -f  torch-1.3.1-cp36-cp36m-win_amd64.whl
  • 測試(先執行python)
import torch
import torchvision
print(torch.__version__)
print(torch.cuda.is_available())  # 返回True, 則PyTorch的GPU安裝成功
  • 錯誤解決
pip install Pillow==6.1   # ImportError: cannot import name 'PILLOW_VERSION'

2.2 安裝tensorflow-gpu 2.0

https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.0.0-cp36-cp36m-win_amd64.whl
  • 安裝tensorflow
pip install tensorflow-gpu==2.0.0 -f d:\ztools\tensorflow_gpu-2.0.0-cp36-cp36m-win_amd64.whl
  • 升級tensorflow
    pip install --upgrade tensorflow         #升級到最新版本 (不支持GPU)
    pip install –upgrade tensorflow-gpu  #升級到最新版本 (支持GPU) 
  • 查看TensorFlow版本號
import tensorflow as tf;
print(tf.__version__)    # 獲取TensorFlow版本號
  • 查看GPU是否安裝好
import tensorflow as tf;
tf.test.is_built_with_cuda()   #檢測cuda 返回true或者false
tf.test.is_gpu_available()    # 檢測gpu 返回true或者false
                                           # 如果兩個都是true 那麼gpu就安裝好了
  • 錯誤解決
#  FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be  understood as (type, (1,)) / '(1,)type'.  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
pip install numpy==1.16.0

2.3 安裝OpenCV

  • 安裝
pip install opencv-python==4.1.2.30                 # only install main modules
pip install opencv-contrib-python==4.1.2.30     #  install both main and contrib modules
  • 測試
import cv2
print(cv2.__version__)

3. 問題解決

3.1 安裝Anaconda3

3.1.1 Install Microsfot VSCode failed

  • 解決方案:在/anaconda3/pkgs/vscode_inst.py中的def haveInternet():中增加允許重定向allow_redirects=True
def haveInternet():
    try:
        r = requests.head(VSCODE_ENDPOINT, timeout=5, allow_redirects=True)
        assert r.status_code == 200
        return True
    except Exception as e:
        log.exception('haveInternet')
        return False

4. 修改Anaconda中Jupyter Notebook默認路徑

  • 查看配置文件的路徑
jupyter notebook --generate-config
  • 修改jupyter_notebook_config.py
## The directory to use for notebooks and kernels.
#c.NotebookApp.notebook_dir = ''
#將其改爲
## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = 'E:\Jupyter'
#其中E:\Jupyter爲自己的工作空間
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章