Python Virtual Environments with Anaconda Distribution:

Virtual environment is a way you can separate different python environment for different project, so why you will do like this for example you have multiple project and they all relay on a single package flask or django each of this project may be using different version of django and flask. Then if you upgrade that package then it could break couple of web site, it will be better if each of this project had an isolated environment where they had only dependency and packages they need and specific version they need that’s what virtual environment do.

  1. Create new environment:
    1. With default python version:
      conda create -n yourenvname
    2. With specific python version:
      conda create -n yourenvname python=x.x
    3. With specific python version and 3rd party python library:
      conda create -n yourenvname python=x.x packagename
  2. Activate environment:
    1. Windows:
      activate yourenvname
    2. Linux:
      source activate yourenvname
  3. Deactivate environment:
    1. Windows:
      deactivate
    2. Linux:
      source deactivate
  4. check list of environments:
    conda info –envs
  5. Install 3rd party packages:
    conda install packagename
    if package is not found check in google for other channels
    conda install -c conda-forge opencv=3.2.0
  6. Deploy in other system or production system:
    1. Activate the environment in development system and execute below command
      conda env export > environment.yml
      it will create a environment.yml file in current folder
    2. Copy the environment.yml in Production system and go to respective folder and execute below
      conda env create -f environment.yml
  7. Remove the environment
    conda remove –name yourenvname –all
  8. If your machine is under proxy use below:
    Setup proxy:
    Linux:
    a) Open terminal
    b) sudo gedit ~/.bashrc
    c) add below line in bashrc file
    export https_proxy=”http://username:password@proxyurl:portnumber”
    d) Close terminal
    Windows:
    a) Open command line
    b) Execute below command
    set https_proxy=http://username:password@proxyurl:portnumber
    If you logged in Non-Admin this will work until closed the command line
    if any special characters are in password should be converted to hexadecimal
    ex:
    @ ->%40
    # ->%23
    $ ->%24
    Ref: http://www.asciitohex.com/
Advertisements