Prerequisites

You must have the following packages installed on your system.

Python 3 PIP

Install Virtualenv with Python 3

You must have Python 3 and PIP installed on your system. We use virtualenv package to create virtual environment for the Python applications. So first install virtualenv Python module using command:

Create Virtual Environment

Search for the Python3 binary location on your system. Use the following command to find the Python 3 binary file location on your system. As per the above command, Python 3 binary is available at /usr/bin/python3. Next, switch to your Python application directory Then, create a separate environment for your Application. You can change the environment directory name (isoEnv used in below example) as per your choice. You can also define the environment directory on a different location. The above command will creates a separate environment for the Python binary file. You can access it by typing python only.

Activate Virtual Environment

You need to activate virtual environment before using it. This will insure to install all modules and configurations to virtual environment only. To activate the virtual environment, execute: The name of the current virtual environment appears to the left of the prompt. Your prompt will be look like (isoEnv) [email protected]$ To verify the correct Python version, run the following: Any package that you install using pip is now placed in the virtual environments project folder, isolated from the global Python installation. Use pip3 to install a module: You can use ‘nose’ if you’re going to work with openstack. For example:

Deactivate virtualenv Environment

After finishing your work inside the virtual environment, simply exit from this by typing deactivate command. You will get the users to default shell.

Delete virtualenv Environment

If your application no more required the virtual environment, You can delete this. To delete the environment simply delete the environment directory.

Conclusion

In this tutorial, you have learned about configuration of the Python virtual environment on Linux system.