A common question for beginning python programmers is how to set up and activate a virtual environment using virtualenv with a different python version. Fortunate for us the answers is pretty simple. First, let’s fire up a command line terminal and type this command:
virtualenv -p |
1.) The virtualenv command is used to create a python virtual environment.
2.) The -p <path-to-python-version> switch allows you to point to the path for the python installation you want to use. And 3.) the path where you want the environment installed.
On my local machine this is what it looks like:
Once this is done you now must activate the virtual environment by using the command below:
source test_env/bin/activate |
Once the environment is installed you can now install packages/modules for you environment using pip install <package>. Once you have finished working in your environment you can simply deactivate as so:
deactivate |
And that’s pretty much all there is to it. If you have any questions please feel free to comment below, thanks.