virtual env

Python virtual environment keeps separate package installations for different projects.

It's a bit like a virtual machine that can has it's own libraries.

E.g. a python3 environment with xgboost 0.67 for project A, and another environment with

xgboost 0.8 for project B. 

To install virtual environment, run:

  pip install virtualenv

  

Create a new environment call env_new:

  python -m venv env_new

if using pythong2.x, the module is called virtualenv, so the command is

  python -m virtualenv env_new

After creating a virtual environment, a new folder env_new is created under /scripts/

The new folder keeps:

  Include

  Lib

  Scripts

  pyvenv.cfg

  

In command line, execute the ./env_new/Scripts/activate

Then it enters the virtual environment. In linux it would be 'source ./env_new/Scripts/activate'.

Then do whatever it needs to in the virtual environment ...

new versions of bla...

And it only impacts the virtual environment

Finally when work is done, quit 

    execute the ./env_new/Scripts/deactivate

In linux, simply run 'deactivate'

To point Spyder to a virtual environment, go to tools->preferences->python interpreters and point to to the env_new/Scripts/python.exe


Sometimes, python has strange bugs with virtual environment and lose the pip.

So when run 'pip install' from venv, it says the pip command is not found.

Run the below to fix it, but it will roll back to the original pip version.

python -m ensurepip --default-pip