Creating a Python virtual environment in Linux:
1. If you don't have pip (Python package installer) installed, you can
install it using:
sudo apt-get install python-pip
2. Next, install virtualenv, a tool for creating virtual environments:
pip install virtualenv
3. Check your virtualenv installation:
virtualenv --version
4. Create a new virtual environment:
virtualenv myenv
Replace `myenv` with the name you want for your virtual environment.
If you want to use a specific Python version, you can specify it:
virtualenv -p /usr/bin/python3 myenv
5. Activate the virtual environment:
source myenv/bin/activate
Your command prompt should now show the name of your virtual environment,
indicating that you are working inside it.
6. To deactivate the virtual environment and return to your regular system
environment, simply type:
deactivate
This way, you can create and manage isolated Python environments for
different projects on your Linux system.
Creating a Python virtual environment in Windows:
1. If you already have Python installed, you can use pip to install
virtualenv:
pip install virtualenv
2. Navigate to the directory where you want to create your virtual
environment. To create a virtual environment named `myenv` in that
directory, run:
python -m venv myenv
You can name your virtual environment anything you want.
3. To activate the virtual environment, run:
myenv\Scripts\activate
Your command prompt should now show the name of your virtual environment,
indicating that you are working inside it.
4. To deactivate the virtual environment and return to your regular system
environment, simply type:
deactivate
This way, you can create and manage isolated Python environments for
different projects on your Windows system.