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
- Download the latest version from Python’s official website.
- Run the installer and check the box “Add Python to PATH”.
- 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.
- Create a new project folder:
mkdir my_project cd my_project
- Create a virtual environment:
python -m venv env
This will create an
env/
folder inside your project. - Activate the virtual environment:
env\Scripts\activate
Once activated,
(env)
should appear before your command prompt. - 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:
- Install the Python extension from the Extensions Marketplace.
- 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