Links: ubuntu16.04 under installation python3+ Create a virtual PYTHON3 development environment
1. Why create a Python3 virtual development environment?
/* ********************************************************************1. The virtual environment is used to create a standalone Python environment, Allows us to use different Python modules and versions without confusion. 2. A virtual environment enables you to set up a separate space on your computer for a Python project, ensuring that each of your projects has its own set of dependencies and does not disrupt any other projects. 3. Creating a programming environment gives us more control over our Python projects and how to handle different versions of packages. This is especially important when using third-party packages. 4. You can set up many Python programming environments as needed. Each environment is basically a directory or folder on your computer that contains scripts to act as the environment. *********************************************************************/
2. Steps to create a virtual environment
(1) In order to create a virtual environment, we first need to install the Venv module, which is part of the standard Python3 library,
Enter the following command to install Venv:
$ sudo apt-get install-y python3-venv
(2) with this installation above, we are ready to create the environment. let's choose which directory to put our Python programming environment in, or we can use mkdir to create a new directory, as shown here:
environments$ cd environments
(3) Once you have entered the directory where you want the environment to reside, you can create an environment by running the following command:
My_env
(4) above (3), Essentially, this creates a new directory that contains some items that we can view with the LS command:
$ ls my_env
Outputbin include Lib lib64 pyvenv.cfg Share
Ps:
/* **************************************************************** These files work together to ensure that your project is isolated from the broader context of your local computer, So that system files and project files are not mixed. This is a good habit of versioning and ensures that each of your projects has access to the specific packages it needs. Python wheels is a python built-in format that can speed up the production of software by reducing compilation times, and it will be in the Ubuntu 16.04 shared directory. *****************************************************************/
3. Activating the virtual Environment
To use this environment, you need to activate it, and you can activate the activation script by entering the following command:
$ source my_env/bin/activate
At this point, the tip of the terminal now takes the name of the environment as a prefix, in which case it is called my_env, as shown in:
This prefix lets us know that the MY_ENV environment is currently active, which means that when we create the program here, they will only use the settings and packages for that particular environment.
4. Exiting the virtual environment
If you want to exit this environment, you can exit by running the following command:
(my_env) [Email protected]:~/environments$ Deactivate
5. Summary
At this point, the virtual environment is created, you can use it, open the learning journey
Create a virtual PYTHON3 development environment under Ubuntu