~ 9 min read
Installing Python on Windows and macOS: A No-Fuss Terminal Guide
Installing Python: A No-Fuss Terminal Guide
Tired of 100 different ways to install python? Here is the best way to get it done.
-
First we install pyenv on whatever your OS is.
-
Then use pyenv to install and manage python versions.
Windows Installation
- Open PowerShell or Command Prompt and run:
Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
-
Reopen PowerShell
-
Run
pyenv --version
to check if the installation was successful. -
Run
pyenv install -l
to check a list of Python versions supported by pyenv-win -
Run
pyenv install <version>
to install the supported version -
Run
pyenv global <version>
to set a Python version as the global version -
Run
pyenv version
to see which Python version you are using and its path
Click here to check pyenv-win commands
macOS Installation
- Install pyenv through Homebrew:
brew update
brew install pyenv
- Add pyenv to your shell (add this to your
~/.zshrc
or~/.bash_profile
):
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
-
Run
pyenv --version
to check if the installation was successful. -
Run
pyenv install -l
to check a list of Python versions supported by pyenv -
Run
pyenv install <version>
to install the supported version -
Run
pyenv global <version>
to set a Python version as the global version -
Run
pyenv version
to see which Python version you are using and its path
You can verify that Python is installed correctly by opening a new terminal window and running:
python version
You should see something like Python 3.12.0
(or whatever version you installed).
Troubleshooting Tips
Having issues? Here are some common fixes:
- If
python
doesn't work, trypython3
- If commands aren't found, try closing and reopening your terminal
- For macOS users, if Homebrew commands fail, run
brew doctor
Wrapping Up
That's all there is to it! You've now got Python installed and ready to go. The terminal might seem intimidating at first, but it's actually pretty friendly once you get to know it. Happy coding! 🚀
P.S. If you run into any issues, the Python community is super helpful - don't be afraid to reach out on forums like Stack Overflow or Reddit's r/learnpython!