Python virtual environment is like a mini, isolated Python installation inside your project folder. This means you can install and manage packages just for that project without messing up other projects.
virtual environment in python
A virtual environment in Python is like a separate, isolated workspace for your projects.
It allows you to manage dependencies and packages for different projects without them interfering with each other.
There will some steps
- Install virtualenv (if you don’t have it).
- Create a virtual environment.
- Activate the virtual environment:- On Windows.
- Deactivate the virtual environment.
When you activate the virtual environment, any Python packages you install will only be available in that environment, keeping your main Python installation clean and avoiding conflicts between projects.
1. Install virtualenv
virtualenv is a tool to create isolated Python environments.
pip install virtualenv
2.Create a Virtual Environment
You can create a virtual environment using the venv module, which is included in Python 3.3 and later.python -m venv myenv Replace myenv with the name you want for your environment.
3.Activate the Virtual Environment
To start using the virtual environment, you need to activate it myenv\Scripts\activate
On macOS/Linux:source myenv/bin/activate
When the virtual environment is activated, you’ll see the name of the environment in your terminal prompt, indicating that you are now working inside the virtual environment.
4.Install Packages
With the virtual environment activated, you can install packages using pip. These packages will only be available within this environment.
pip install package_name
5.Deactivate the Virtual Environment
When you’re done working, you can deactivate the virtual environment to return to the global Python environment.
deactivate