Installing Python on Windows
Since Python doesn’t come installed on Windows by default, we need to download and install it. To do that visit https://www.python.org/ and then just go to the download section and then download the latest version of Python 3.
And here the latest version is this Python three series is Python 3.8.0 by the time I am writing this tutorial. Click the download button, and when that’s done downloading launch the installer and accept all the defaults. One important thing to do is check the box where it says add Python to path. We want to do that so we can run Python programs from the command line if you wish.
When you click install now if you get a pop-up asking you if you want this program to make changes to your computer, select yes.
Now that Python has been installed successfully on your Windows computer, we will just go ahead and close it out here and you are ready to go.
Installing Python on Mac
At this I am writing this tutorial Mac operating system ships with Python 2. In order to use the latest version of Python you’ll need to download and install it. To do this visit Python.org and click on the download section. Next download the latest version of Python.
Once you have it downloaded you can launch the installer and then simply accept the defaults. This consists of mainly just clicking the continue button. If you are prompted to enter in your username and password go ahead and do that.
Once Python is installed you should see a Python folder in your applications folder. Inside the Python folder you’ll see an IDLE application. If you can launch that just know that you’ve installed Python successfully. I will be going over the IDLE application and a coming lessons.
Installing Python on Linux
Some Linux distributions ship with just Python 2 installed. However it’s becoming more more common to see by Python 2 and Python 3 installed by default. To determine if you have Python installed just open up a terminal and type:
In many cases the just the python ––version command will actually be Python 2 and the python3 ––version command will be for running Python 3. Here’s an example of that:
[email protected]:-$ python ––version Python 2.7.9 [email protected]:-$
This is the Python 2.7 series and we’ll try;
[email protected]:-$ python3 ––version -bash: python3: command not found [email protected]:-$
In some cases like we just said Python 3 is not installed by default. In this case you will get a command not found message like shown above. So in order to install Python 3 on a Debian-based distribution such as Debian, Ubuntu and Linux Mint, we will need to run,
Installing software requires root privileges. We can do that with ‘sudo’ in front of the command.
And just note that sudo has to be configured before it can work and sometimes it is configured by the distribution, sometimes you have to do it yourself or sometimes a system administrator has configured it for you. If it’s not configured you’ll have to switch to the root user and do the install which also you next.
Run the command;
It’ll download the necessary packages and perform the install.
Now let’s test the Python 3 version;
python3 --version Python 3.8.1Code language: CSS (css)
and we can see that indeed Python 3 did get installed. If you get an error something about sudo not configured then you’ll want to type,
and hit enter and then enter the root password. And from here you can run the apt-get install command. So this is exactly how you could install Python 3 on a Debian-based distribution.
For RPM-based Linux distribution such as CentOS, Fedora, Red Hat and Scientific Linux, you can attempt to install Python 3 using the
sudo yum install -y python3 python3-tools
command. Again be sure to run the command as root or proceed it with sudo as installing software requires root privileges. Here is an example of me trying to install Python 3 on a CentOS system.
sudo yum install -y python3 python3-tools
In this example it didn’t work. There isn’t a Python 3 or Python 3 tools package available. If this was Fedora that would’ve worked. So in this particular case we need to install Python using the source code. Before installing Python 3 from source code we are going to have to install some dependencies.
So the first thing we need to do is run the following command.
Now if that’s complete we need to install a couple additional dependencies. We’ll run,
sudo yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel tk-devel
Now that we have all the dependencies installed we’ll visit Python.org and download the Python source code. By the time I am writing this tutorial the latest version was Python 3.8.1.
Download the latest source code available and go ahead and save that file. Back at the command line I’m just going to navigate to the directory that I saved the file And then I’m going to run the following command.
tar xf Python*
That’ll extract the contents of that archive that we downloaded from Python.org. Now that we’ve extracted the contents will just change into the directory and then from here what we need to do is run the configure command.
cd Python* ./configure
Next we run the make command
The make command will probably take several minutes to run so it’s normal if it takes a while. the next command we want to run is,
sudo make install
This gives us root privileges to do the installation. If sudo is not configured what you want to do is switch to the root user with su- command. And then what you’re going to need to do is come back to the directory where you have downloaded and extracted the Python source code. But since we have sudo configured already I’m going to take advantage of that and just run,
sudo make install
Now when I run the command,
it should return,
Python 3.8.1Code language: CSS (css)
You have successfully installed Python 3 from source code.
You must be logged in to post a comment.