Setting up a Virtual Environment
I’ve been gradually upskilling my Python abilities, mostly through some small scale projects that focus on particular skills. However, I am also trying to work more like a developer (rather than a careless amateur) and part of that means paying attention to my development environment and the libraries and packages that I use there.
A virtual environment allows developers to work on specific projects and install packages and libraries for that particular project without worrying about what effect those packages will have on other projects. So, for each of my projects, I wanted to get in the habit of setting up a virtual environment and working in that environment for any tasks related to that project.
Fortunately, this is pretty straightforward to do.
- Set up the environment in the project directory
This creates a virtual environment called my_env.
python3.7 -m venv my_env
- Activate the environment
source my_env/bin/activate
- Deactivate the environment
deactivate