Uncategorized

How to set up a Python venv virtual environment

To set up a Python venv virtual environment, follow these steps:


✅ 1. Check if Python is installed

Open a terminal or command prompt and type:

python3 --version

Or on Windows:

python --version

You should see something like: Python 3.11.8. If not, install Python from python.org.


✅ 2. Create a virtual environment

In your project folder, run:

python3 -m venv venv

Or on Windows:

python -m venv venv
  • This creates a folder called venv/ that contains the isolated environment.

✅ 3. Activate the virtual environment

On Linux/macOS:

source venv/bin/activate

On Windows (cmd.exe):

venv\Scripts\activate.bat

On Windows (PowerShell):

venv\Scripts\Activate.ps1

After activation, your prompt should change to show (venv).


✅ 4. Install packages inside the virtual environment

Now that it’s activated, you can install packages like this:

pip install <package-name>

Example:

pip install numpy

✅ 5. Deactivate the virtual environment

When you’re done, simply run:

deactivate

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.