How to Set Up Python in Linux
Python version 2.x is already
installed in most Linux distributions but as we’re going to be using Python
3.x, there’s a little work we need to do first to get hold of it. Thankfully,
it’s not too difficult.
PYTHON PENGUIN
Linux is such a versatile
operating system that it’s often difficult to nail down just one way of doing
something. Different distributions go about installing software in different
ways, so we will stick to Linux Mint 18.1 for this particular tutorial.
Step 1
First you need to ascertain which
version of Python is currently installed in your Linux system; as we mentioned,
we’re going to be using Linux Mint 18.1 for this section. As with macOS, drop
into a Terminal by pressing Ctrl+Atl+T.
Step 2
Next enter: python - version into the Terminal screen. You should have the output relating to version 2.x of Python in the display. Ours in this case if Python 2.7.12.
Step3
Some Linux distros will
automatically update the installation of Python to the latest versions whenever
the system is updated. To check, first do a system update and upgrade with:
sudo apt-get update &&
sudo apt-get upgrade Enter your password and let the system do any updates.
Step 4
Once the update and upgrade is
complete, you may need to answer ‘Y’ to authorise any upgrades, enter: python3
--version to see if Python 3.x is updated or even installed. In the case of
Linux Mint, the version we have is Python 3.5.2, which is fine for our
purposes.
Step 5
However, if you want the latest
version, 3.6.2 as per the Python website at the time of writing, you need to
build Python from source. Start by entering these commands into the Terminal:
sudo apt-get install
build-essential checkinstall sudo apt-get install libreadline-gplv2-dev libncursesw5-dev
libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Step 6
Open up your Linux web browser
and go to the Python download page: www.python.org/downloads. Click on the
Download Python 3.6.2 (or whichever version it’s on when you look) to download
the source Python-3.6.2.tar.xz file.
Step 7
In the Terminal, go the Downloads
folder by entering: cd Downloads/. Then unzip the contents of the downloaded
Python source code with: tar –xvf Python-3.6.2.tar.xz. Now enter the newly
unzipped folder with cd Python-3.6.2/.
Step 8
Within the Python folder, enter:
./configure sudo make alt install
This could a little while depending on the speed of your computer.
Once finished, enter: python3.6
--version to check the installed latest version.
Step 9
For the GUI IDLE, you need to
enter the following command into the Terminal:
sudo apt-get install idle3 The
IDLE can then be started with the command: idle3. Note, that IDLE runs a
different version from the one you installed from source.
Step 10
You also need PIP (Pip Installs
Packages) which is a tool to help you install more modules and extras.
Enter: sudo apt-get install
python3-pip PIP is then installed;
Check for the latest update with:
pip3 install --upgrade pip When
complete, close the Terminal and Python 3.x will be available
via the Programming section in
your distro’s menu.
0 Response to "How to Set Up Python in Linux"
Post a Comment