Setting up a local environment helps you manage Python projects efficiently. Follow these steps to create an isolated Python environment on Windows.


Step 1: Install Python

  1. Download the latest version from Python’s official website.
  2. Run the installer and check the box “Add Python to PATH”.
  3. Verify installation in Command Prompt (CMD):
    python --version
    
    pip --version
    

    If Python and pip return their versions, you’re good to go.


Step 2: Install Virtual Environment (venv)

A virtual environment prevents dependency conflicts between projects.

  1. Create a new project folder:
    mkdir my_project
    cd my_project
    
  2. Create a virtual environment:
    python -m venv env
    

    This will create an env/ folder inside your project.

  3. Activate the virtual environment:
    env\Scripts\activate
    

    Once activated, (env) should appear before your command prompt.

  4. Deactivate the environment (when done):
    deactivate
    

Step 3: Install Packages Using pip

Inside your virtual environment, install necessary libraries:

pip install numpy pandas matplotlib

To list installed packages:

pip list

To save dependencies for later:

pip freeze > requirements.txt

To install them on another system:

pip install -r requirements.txt

Step 4: Install an IDE (Optional)

Use an IDE for better coding experience:

For VS Code:

  1. Install the Python extension from the Extensions Marketplace.
  2. Select the correct Python interpreter (Ctrl + Shift + P → Python: Select Interpreter).

Step 5: Running a Python Script

Create a file app.py and write:

print("Hello, Python Environment!")

Run it:

python app.py

You’re all set! Your Python environment is ready to go. 🎉

Would you like help setting up Jupyter Notebook or Conda? 😊


Leave a Reply

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