Python environment
Installing python
MacOS
On MacOS python comes pre-installed but its usually a good idea to also have a system-package manager installed such as
See also Using Python on macOS for more information.
Linux
Congratulations! You are already done.
Windows
To minimize the amount of pain while developing on Windows I recommend using the Windows Subsystem for Linux. Following the instructions there you can pretty much install any Linux you would like, such as Arch or Ubuntu.
You can then either edit the files directly inside the Linux using e.g. vim or nvim or you can open the files in Windows using your preferred editor. You can also couple your VSCode to WSL and edit and develop this way. This is probably the preferred option if you absolutely need to use Windows and already know VSCode and do not want to learn vim.
Basic Python environment
- Install an editor you like or use the one you already have.
- Use
venvto create new environments.
|
|
- To activate the environment (this makes sure
pip,pythonand your$PATHpoints to the correct places) use the correct command according to your shell.
POSIX
| Shell | Command |
|---|---|
| bash/zsh | source <venv>/bin/activate |
| fish | source <venv>/bin/activate.fish |
| csh/tcsh | source <venv>/bin/activate.csh |
| pwsh | <venv>\Scripts\Activate.ps1 |
Windows
| Shell | Command |
|---|---|
| cmd.exe | <venv>\Scripts\activate.bat |
| PowerShell | <venv>\Scripts\Activate.ps1 |
To test what the activation does, first activate the environment, then type which python and pip --version. Then deactivate and try again. You will see that the paths have changed and probably pip is not even an available command any more.
- Then use
pipto install packages.
|
|
- Use
python your_stuff.pyto run code. - Use
deactivateto exit the environment.
Multiple python version
- Install uv to manage python versions.
- Create a new environment with (where
Xis the desired python version, skip--pythonto use default).
|
|
- Activate like before.
- Install new python versions with
uv python install 3.X.
Read the uv docs for more info.