To create and activate a virtual environment in Python, you can follow these steps:
Install virtualenv (if you haven't already):
pip install virtualenv
Create a virtual environment:
virtualenv myenv
This command will create a new directory named
myenv
which will contain the virtual environment files.Activate the virtual environment:
- On Windows:
myenv\Scripts\activate
- On Unix or MacOS:b
source myenv/bin/activate
After activation, you should see the name of your virtual environment
(myenv)
in the terminal prompt.- On Windows:
To deactivate the virtual environment and return to the global Python environment, simply type deactivate
in the command prompt or terminal.