When you create a Python application then there is a need to create virtual environment. Virtual environment helps you to maintain your dependencies in an isolated location. This doesn't effect the global system dependencies. Also, using virtual environment you can have python application that supports different version of Python
In this post we will be creating Python3.8 virtual environment
- Python3.8 must be installed
- pip must be installed
Step 1 : Find the location of Python Interpreter
- You need to find the path of Python3.8 interpreter
- This will depend upon the operating system that you are using
Find Python3.8 Interpreter Path in Linux/Mac Operating System
- Open you terminal and use below command
- You may get multiple paths, but you have to consider the path that contains bin and python3.8
Find Python3.8 Interpreter Path in Windows Operating System
- Open the Command Promt and use below commnd
- You will get the python Interpreter path. Copy the path of interpreter as it will be needed in subsequent steps.
Step 2 : Install virutalenv python package
pip install virtutalenv
Step 3 : Create Virtual environment
- Goto the directory where you want to create Python3.8 virtutalenv
- Use below command and replace [path-of-python-3.8-interpreter] with the value obtained in step 1
virtutalenv -p [path-of-python-3.8-interpreter] venv
- This will create a folder with name venv. All your python packages for a particular application will be installed in their respective venv folder.
Step 4 : Activating the virtual environment
- Before installing any python package or library you have to activate the virtual environment.
Activate Virtual Environment in Linux/Mac Operating System
Activate Virtual Environment in Windows Operating System
Check Python Version
- You can also check the Python version using below command
- You will get below output
Step 5 : Deactivate virtual environment
- use the below command to deactivate the virtual environment
Step 6 : Deleting the virtual environment
- Just remove all the contents from venv folder, and your virtual environment will be deleted.