Setting Python 3 Virtual Environment - nodesign/weioIDE GitHub Wiki

Python 3 is used in WeIO IDE project for backend server. As version 3 is not yet default version in the most of operating systems it's tricky to install and use modules for one specific version of the language. That's why when we want to switch to version 3 and still keep 2.7 we need to create virtual environnement to keep dependencies separated. This is short tutorial of how to setup environment on Unix/Linux systems to avoid collision between versions. More about : http://docs.python-guide.org/en/latest/dev/virtualenvs/

Install Virtual environments

$ pip install virtualenv
$ cd yourProject
$ virtualenv venv

It will create venv folder in ./ Now you have to choose your Python version that you wanna use

$ type python3
python3 is hashed (/usr/local/bin/python3)
$ virtualenv -p /usr/local/bin/python3 venv
Using base prefix '/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5'
New python executable in /Users/ukicar/workNow/nodesign/WeIO/weio/weioIDE/pythonDependencies/venv/bin/python3.5
Not overwriting existing python script /Users/ukicar/workNow/nodesign/WeIO/weio/weioIDE/pythonDependencies/venv/bin/python (you must use /Users/ukicar/workNow/nodesign/WeIO/weio/weioIDE/pythonDependencies/venv/bin/python3.5)
Installing setuptools, pip, wheel...done.

To begin using the virtual environment, it needs to be activated:

$ source venv/bin/activate
(venv) MacBook-Pro-de-Uros-2:pythonDependencies ukicar$

Now in the shell you have (venv) prefix that tells you that you are using virtual environment and it's safe to do all installations that are required.

$ pip install someModule

Keeping all that is needed in only one folder is extremely useful for developing and embedding modules in hardware. Virtual environment is desactivated by :

$ deactivate