Setting up a virtual environment can help you manage dependencies for your Python project. Here's a step-by-step guide to set up and activate a virtual environment using the built-in venv module in Python.
- Python 3.3 or later (check with python --version or python3 --version)
Navigate to your project directory (or wherever you want to create the virtual environment) and run one of the following commands:
python3 -m venv myenv
py -m venv myenv
This will create a directory called myenv (or whatever you named it) that contains the virtual environment (basically a bunch of directories and files).
source myenv/bin/activate
myenv\Scripts\activate
You should see (myenv) at the beginning of your command line prompt, indicating that you are in the virtual environment. Now you can install dependencies and run your project without worrying about dependency conflicts.
When you're done working in the virtual environment, you can deactivate it by running the following command:
deactivate