How to Set Up a Python Virtual Environment and Get Project-Specific pip list
If you're working on a Python project and want to isolate your dependencies — and generate a list of installed packages only for that project — follow this simple guide. This is especially helpful if you have .py files in a folder (like app.py, travel_engine.py) and want a clean setup.
๐ Project Folder Example
Let’s say your project is located at:
✅ Step 1: Open Command Prompt
-
Press
Win + R, typecmd, and press Enter. -
Navigate to your project folder:
✅ Step 2: Create a Virtual Environment
This creates a venv/ folder with an isolated Python environment.
✅ Step 3: Activate the Virtual Environment
Once activated, your terminal will show the environment name like this:
✅ Step 4: Install pipreqs (to auto-detect dependencies)
✅ Step 5: Generate requirements.txt
This scans your .py files (like app.py, travel_engine.py) and writes a requirements.txt file with only the third-party libraries actually used.
✅ Step 6: Install Required Packages
This installs everything your project needs inside the virtual environment.
✅ Step 7: List Installed Packages (Project-Specific)
This gives you a clean list of packages installed only in this environment, not globally.
✅ (Optional) Freeze Package Versions
If you want an exact versioned list (great for sharing or deployment):
๐งน Tip: To Deactivate the Virtual Environment
Just run:
๐ง Final Thoughts
Using a virtual environment keeps your project clean and avoids "dependency hell" with conflicting packages. Tools like pipreqs make it even easier by auto-generating requirements.txt from your code.
Let me know if you’d like to automate this setup even more or troubleshoot anything!
Linux networking tips boost real-time performance just like rsl helper enhances real-time efficiency for users.
ReplyDeleteThanks for sharing this article.
ReplyDeleteLearn Python, Power BI, SQL, Tableau and Jira with the best trainers by joining a guided data analyst course in hyderabad and also get placement opportunities
ReplyDeleteExcellent guide. The distinction between workflows and projects is a standout feature here—it’s a nuance that’s often missed but is vital for real-world application. Truly an intuitive deep dive into the Linux lifecycle!
Nice post! The details provided are easy to understand and valuable. If anyone is looking to upgrade their skills, Velgrow Academy Chennai is worth exploring. Helpful information about best guest posting sites.
ReplyDelete