Running Python via Anaconda

Install

  1. Install Anaconda. (e.g. by default in C:\Users\tommyhu\anaconda3)
  2. Add the following paths to Path:
    • C:\Users\tommyhu\anaconda3
    • C:\Users\tommyhu\anaconda3\Scripts

Add libs

Online install

Install directly

1
conda install xxx

Via Anaconda cloud

  1. Search the lib on Anaconda Cloud
  2. Use the command listed on the lib page

    Take OpenCV as an example, run

    1
    conda install -c conda-forge opencv

Offline install

tar.bz2 type1

  1. Download lib of type tar.bz2 (e.g. search Anaconda Cloud)

    Note: download the lib with correct PC versions, including

    • Python (e.g. lib name contains like py37), which can be checked on PC via cmd
      1
      python
    • CUDA (e.g. lib name contains like cuda92), which can be checked on PC via cmd
      1
      nvcc --version
  2. Install in cmd
    1
    conda install --use-local xxx.tar.bz2

whl type

Some whl libs are available at Unofficial Windows Binaries for Python Extension Packages | dlib.

  1. Download lib of type whl (must match local Python and CUDA versions as above)
  2. Install in cmd
    1
    pip install xx.whl

From source

Take dlib as an example

  1. Download its source here (e.g. dlib-19.19.0.tar.gz).
  2. Extract it and run cmd (may need to run twice) in the folder
    1
    python setup.py install

Run

  1. Run Anaconda Command Prompt or cmd (with activate command).
  2. Change to the folder that contains the Python file that you want (assume xxx.py) to run.
  3. Run
    1
    python xxx.py

Case study

With Anaconda-3 (integrated with Python v3.7), installing OpenCV+CUDA+CUDNN+Torch on my laptop (with NVIDIA GeForce GTX 1050) will be like:

1
2
3
4
5
6
7
8
conda install --use-local "<_lib_folder_>\opencv-3.4.2-py37h6fd60c2_0.tar.bz2"
conda install --use-local "<_lib_folder_>\py-opencv-3.4.2-py37hc319ecb_0.tar.bz2"
conda install --use-local "<_lib_folder_>\libopencv-3.4.2-h20b85fd_0.tar.bz2"
conda install --use-local "<_lib_folder_>\cudatoolkit-10.0.130-0.tar.bz2"
conda install --use-local "<_lib_folder_>\cudnn-7.6.5-cuda10.0_0.tar.bz2"
conda install --use-local "<_lib_folder_>\pytorch-1.2.0-py3.7_cuda100_cudnn7_1.tar.bz2"
conda install --use-local "<_lib_folder_>\pytorch-gpu-1.3.1-0.tar.bz2"
conda install --use-local "<_lib_folder_>\torchvision-0.4.0-py37_cu100.tar.bz2"

1. Conda install 本地压缩包文件tar.bz2