How to Set Up a Virtual Environment for Python?

Estimated read time 1 min read

To set up a virtual environment for Python, you can follow these steps:

  1. Open your command prompt or terminal.
  2. Install the virtual environment package by typing the following command: pip install virtualenv
  3. Create a directory where you want to store your virtual environment by typing: mkdir myenv (replace “myenv” with the name you want to give to your virtual environment).
  4. Navigate to the directory you just created: cd myenv
  5. Create a virtual environment by typing the following command: virtualenv venv
  6. Activate the virtual environment by typing the following command:
    • For Windows: venv\Scripts\activate
    • For Linux/Mac: source venv/bin/activate
  7. You should now see the name of your virtual environment in the command prompt or terminal, indicating that you are now working inside the virtual environment.
  8. You can now install any Python packages or libraries that you need for your project using pip, and they will be installed only in the virtual environment, keeping your system’s Python installation clean.

To deactivate the virtual environment, simply type deactivate in the command prompt or terminal.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply