While considering the development rules in Python, I learned how to build a virtual environment in Python, so I will write it down for myself. A Python virtual environment is an environment that is separated by installed modules, packages, and versions. I've been developing locally or on a virtual machine so far, but it seems that I can prepare a clean Python environment without using a virtual machine. Build a Python virtual environment using software called venv.
First of all, create a virtual environment. You can easily create a virtual environment by executing the following command on the terminal. When this command is executed, a directory called'environment name'is created under the executed directory, and that is the virtual environment. However, just entering the directory will not work and you will need to activate it.
Terminal
Uesr$ python3 -m venv 'The name of the environment'
You can activate the virtual environment by actually moving to the directory and entering the following command. When enabled, the terminal $ and computer name will be preceded by ('environment name').
Terminal
User$ cd 'The name of the environment'
User$ source bin/activate
('The name of the environment') User$
Enter the following command to end the virtual environment. Doing this will revert to the display before activation.
Terminal
('The name of the environment') User$ deactivate
User$
I often install various libraries when developing Python, but if I do it locally, it will be difficult to manage the libraries, so I will actively use the virtual environment from now on. It's easy to create an environment, so please try it out.
Recommended Posts