To create a virtual environment in Python:
Here is an example of how to create a virtual environment named "myenv" in a directory named "python_project":
python3 -m venv python_project/myenv
If you want to create the virtual environment in the current directory then you can execute the following command.
python3 -m venv env
Where env is the environment name. You can change it as per your wish.
You can also use pipenv or conda to create virtual environment.
pipenv --python 3.8
conda create --name myenv python=3.8
Once you have created the virtual environment, you can activate it by running the activate script.
source env/bin/activate
conda activate myenv
You can deactivate it by using
deactivate
conda deactivate
This will change your shell's prompt to indicate that you are now working in the virtual environment and you can install packages without affecting the system-wide packages.
0 Comments