Dev Note: Tips on building environments, venv or conda?
Questions
It is suffering to build a virtual environment sometime
I could like to record two of the most common approach to build virtual environment under Ubuntu (precisely the Linux subsystem built on Windows)
The reason why I choose to write this memo is “I ALWAYS forget the prompts, lol”
with venv
venv is the most recommended way of managing virtual environment since Python 3.5, it is a module within the Python Standard Library, so you don’t have to install a third party package.
Install another version of Python you need
By using the following prompt, anyone could install python with a specific version. 3.x means the specific version of python.
1
sudo apt install python3.x
Create a new directory and build the venv
In the following prompt, [project dir] is the directory where stores your project, and [venvname] is an arbitrary virtual environment name you would like to give.
1 2
cd [project dir] python3.x -m venv [venvname]
Activate the virtual environment
NOTE: In fact, when creating a virtual environment with venv, it has created a folder in project directory in order to store the packages. So the folder structure should be like:
Make sure that you have already in the project directory [project dir], then prompting as the following:
1
source [venvname]/bin/activate
Deactivate and delete virtual environment
You can deactivate the virtual env with a single prompt.
1
deactivate
You can also simply delete it with Linux delete prompt (still, make sure you are already in the project directory and deactivated the virtual env). All the files including .bin will be deleted.