Written by:
Here is a way to install python on windows, mac or linux (commands vary depending on the operating system):
1# On windows Powershell 2$ choco upgrade python -y 3 4# MacOs homebrew with pipenv 5# you would need to install python first 6$ pyenv install 3.9.2 7 8# linux 9$ sudo add-apt-repository ppa:deadsnakes/ppa 10$ sudo apt update 11$ sudo apt install python3.9
During the rest of the article you want check details on the rest of the installation steps depending on your operating system.
To update Python on a Windows Operating System to the latest, we can choose one of 2 ways, it's up to you which want you want to follow:
Latest Python 3 Release - Python 3.11.1
(if there's a new version when you read this article, it won't be Python 3.11.1)Windows installer (64-bit)
)CMD
or PowerShell
terminal and typing python -V
1$ python -V 2# Output: Python 3.11.0
🖐 For a more in-depth guide regarding this procedure, please head to our step-by-step guide on how to update python on windows where we cover with pictures of every step.
Chocolatey Package Manager has become a favorite among Windows users when handling Python versions or adding other software to our System using PowerShell.
Open the PowerShell as administrator. On your start menu type powershell
and select Run as Administrator
Install Chocolatey using the following command:
1Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Powershell
terminal, type choco
.1$ choco 2# Expected output: 3Chocolatey v1.2.0 4Please run 'choco -?' or 'choco <command> -?' for help menu.
Having Chocolatey installed in our System, upgrading Python is now as simple as typing: choco upgrade python -y
1$ choco upgrade python -y 2 3# expected output: 4 5Chocolatey v1.2.0 6Upgrading the following packages: 7python 8By upgrading, you accept licenses for the packages. 9python is not installed. Installing 10Progress: Downloading python3 3.11.0... 90%
Let's verify that the install and upgrade was successful with the command we used earlier
1$ python -V 2 3# Output: Python 3.11.0
Even if almost the entire Python community has moved to Python 3.X, MacOS still comes with version 2.9. To use the latest Python version you'll need to install it manually.
Let's first check if your System is indeed using the version 2.9 or a later one.
(command + space)
and typing terminal
python
If you receive a message like this:
1WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using 'python3' from within Terminal.
It means that you need to update your python version ASAP, so let´s get into it.
There are 2 options to update Python on MacOs:
Download and install the version from python
Use Homebrew to intall pyenv package manager and then install the Python version(s) you want
Latest Python 3 Release - Python 3.11.1
latest version when writing this article ) or scroll until you find the version you want.python -V
To handle our Python development enviorments and Python version we use Homebrew
, a powerfull package manager for all Mac Operating Systems.
1$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Most probably, you'll be prompted for sudo
(Super User-level access) and to grant it, you´ll need to write your password. Keep in mind, what you write, will not be displayed, not even with *
.
Return
(Enter) or cancel with any other key.Now that we installed Homebrew on our System, we´ll install pyenv
to manage our Python versions more efficiently.
What pyenv
will allow us to do, is to switch between different Python versions (remember, Python 4 will come out soon, yay!)
Open a terminal as we did earlier $ brew install pyenv
It´s done! We now have pyenv installed and now we'll make a new Python installation or upgrade it.
Thanks to pyenv we now can install Python with a simple one liner:
1$ pyenv install 3.9.9
It´s not mandatory to use version 3.9.9, you can instead pass any version you wish to install.
If you receive an error regarding C compiler cannot create executables
most probably is XCode related and if you upgrade your MacOS to Big Sur, then probabilities goes higher.
Fixing this problem ain´t a big problem, but will take as much time as your internet speed will allow it.
pyenv install 3.9.9
and it should work just fineTo use our pyenv we need to update our .bash_profile
with the following commands:
/bin
directory1$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
1$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
/bin
directoryIf your System doesn't have a /bin
directory in the pyenv_root
folder most probably, you only have /shims
directory. If it´s the case, you'll need this commands instead
1$ echo 'export PATH="$PYENV_ROOT/shims:$PATH"' >> ~/.bash_profile
1$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
We need to reset the terminal in order for all this changes to be accesible.
To reset the terminal, just type:
1$ reset
We´ll be using deadsnakes ppa (Personal Package Archives) that'll allows us to have multiple python versions installed on our System at the same time.
1$ sudo add-apt-repository ppa:deadsnakes/ppa 2$ sudo apt-get update
1$ sudo apt install python3.11.1
1$ python3.11.1
If you want to grow as a developer you can check this 4Geeks Lesson titled Learn to Code with Python. Hope you enjoy the reading and keep on the Geek side!