Difference between revisions of "Python Environment Setup"

From rbachwiki
Jump to navigation Jump to search
(Created page with "==Create the Environment with a Unique Name== *Instead of the generic .venv, give your Windows environment a name that clearly identifies it. In your project's root terminal, run: python -m venv .venv_pc *This creates a new folder named .venv_pc in your project. Your existing Mac folder (e.g., .venv or .venv_mac) will remain completely untouched.")
 
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Create the Environment with a Unique Name==
==Create the Environment with a Unique Name==
*Instead of the generic .venv, give your Windows environment a name that clearly identifies it. In your project's root terminal, run:
*Instead of the generic .venv, give your Windows environment a name that clearly identifies it. In your project's root terminal, run:
python -m venv .venv_pc  
python -m venv .venv_pc  
*This creates a new folder named .venv_pc in your project. Your existing Mac folder (e.g., .venv or .venv_mac) will remain completely untouched.
*This creates a new folder named <code>.venv_pc </code>in your project. Your existing Mac folder <code>(e.g., .venv or .venv_mac) </code>will remain completely untouched.
==Set VS Code to Use the New PC Environment==
* You must tell VS Code on your PC to use this specific folder instead of the one from your Mac:
**Press<code> Ctrl + Shift + P</code> to open the Command Palette.
*Type and select Python: Select Interpreter.
*Choose the one that points to your new folder: <code>('.venv_pc': venv).</code>
*If it doesn't appear, select Enter interpreter path... and browse to .venv_pc\Scripts\python.exe.
= Sync Libraries via requirements.txt =
*Since you have a new, empty environment, you need to install your project's dependencies:
* On your Mac (before switching): <code>Run pip freeze > requirements.txt</code> to save a list of your current libraries.
* On your PC: Activate the new environment with <code>.venv_pc\Scripts\activate </code> and then run
pip install -r requirements.txt.
= Prevent Future Sync Issues =
*To ensure your Mac environment doesn't accidentally get messed up by your PC (or vice versa), add both environment names to your project's <code>.gitignore</code> file:
<pre>
.venv/
.venv_pc/
.venv_mac/
 
</pre>

Latest revision as of 16:52, 5 January 2026

Create the Environment with a Unique Name

  • Instead of the generic .venv, give your Windows environment a name that clearly identifies it. In your project's root terminal, run:
python -m venv .venv_pc 
  • This creates a new folder named .venv_pc in your project. Your existing Mac folder (e.g., .venv or .venv_mac) will remain completely untouched.

Set VS Code to Use the New PC Environment

  • You must tell VS Code on your PC to use this specific folder instead of the one from your Mac:
    • Press Ctrl + Shift + P to open the Command Palette.
  • Type and select Python: Select Interpreter.
  • Choose the one that points to your new folder: ('.venv_pc': venv).
  • If it doesn't appear, select Enter interpreter path... and browse to .venv_pc\Scripts\python.exe.

Sync Libraries via requirements.txt

  • Since you have a new, empty environment, you need to install your project's dependencies:
  • On your Mac (before switching): Run pip freeze > requirements.txt to save a list of your current libraries.
  • On your PC: Activate the new environment with .venv_pc\Scripts\activate and then run
pip install -r requirements.txt.

Prevent Future Sync Issues

  • To ensure your Mac environment doesn't accidentally get messed up by your PC (or vice versa), add both environment names to your project's .gitignore file:
.venv/
.venv_pc/
.venv_mac/