~ 9 min read

Installing Python on Windows and macOS: A No-Fuss Terminal Guide

Building a linear regression model from scratch using python
Image of Nizar Haider

Nizar Haider

Installing Python: A No-Fuss Terminal Guide

Tired of 100 different ways to install python? Here is the best way to get it done.

  1. First we install pyenv on whatever your OS is.

  2. Then use pyenv to install and manage python versions.

Windows Installation

  1. 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"
  1. Reopen PowerShell

  2. Run pyenv --version to check if the installation was successful.

  3. Run pyenv install -l to check a list of Python versions supported by pyenv-win

  4. Run pyenv install <version> to install the supported version

  5. Run pyenv global <version> to set a Python version as the global version

  6. Run pyenv version to see which Python version you are using and its path

Click here to check pyenv-win commands

macOS Installation

  1. Install pyenv through Homebrew:
brew update
brew install pyenv
  1. 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
  1. Run pyenv --version to check if the installation was successful.

  2. Run pyenv install -l to check a list of Python versions supported by pyenv

  3. Run pyenv install <version> to install the supported version

  4. Run pyenv global <version> to set a Python version as the global version

  5. 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, try python3
  • 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!

Phone

Office: +94 777 33 9761

Email

Office: nizarhaider@gmail.com

Site: https://dsacademy.lk

Social