Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install python 3.7 on MX Linux 18.1

Installing Python 3.7.3 on MX-linux 18.1

I was following this blog to install python 3.7.3 on my MX-linux 18.1 machine. Step by step procedure is as follows

  1. Install the pre-requisites

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 libffi-dev
  1. Download python from the official website like this

cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz

Extract the downloaded package sudo tar xzf Python-3.7.3.tgz

  1. Compile Python from source

cd Python-3.7.3
sudo ./configure --enable-optimizations
sudo make altinstall

Those people who do not install the libffi-dev package will face this error ModuleNotFoundError: No module named '_ctypes'. Hence i have already included the libffi-dev package in the first step

  1. Installing any package through pip3 or pip3.7 you will encounter this error while using it, correct the error.

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.7/site-packages/numpy'
Consider using the `--user` option or check the permissions.

At this point the best option is to use virtualenv or virtualenvwrapper but if you want to get rid of this error then use the --user option. pip3.7 install --user pandas the pandas will be installed but you will not be able to use it. You might see a warning at the end like this(Anyways at this point you should be using virtual environments anyways)

The scripts f2py, f2py3 and f2py3.7 are installed in '/home/someuser/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

If you want to use python and all the modules that you install with pip without any virtual enviroments you will not be able to use it because ~/.local/bin directory is not added in your PATH environement variable. So just add this to the end of your .bashrc file

PATH=$PATH:~/.local/bin/

then do a

source .bashrc
  1. Change python symlink to point to python 3.7.3 rather that 2.7

Since use of python 2.7 is going to be obsolete in the near future we change the default python symlink to point directly to python 3.7. Please navigate to /usr/bin. You should notice the python symlink

 ls -lha /usr/bin/python
lrwxrwxrwx 1 root root 9 Jan 24  2017 /usr/bin/python -> python2.7

Use this command to change it to python 3.7

sudo ln -sfn /usr/local/bin/python3.7 python

Now typing python should open a python 3.7.3 interpreter instead of python 2.7 interpreter

$ python
Python 3.7.3 (default, Apr 18 2019, 11:12:01) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
  1. Install virtualenvwrapper

pip3 install --user virtualenvwrapper

Make a folder called Envs to store all the virtual environments mkdir Envs To make virtualenvwrapper work seamlessly everytime you open a new terminal include these lines at the end of .bashrc

export WORKON_HOME=~/Envs
source ~/.local/bin/virtualenvwrapper.sh

and then do a $ source .bashrc on the terminal

$ mkvirtualenv test
Using base prefix '/usr/local'
New python executable in /home/somename/Envs/test/bin/python3.7
Also creating executable in /home/somename/Envs/test/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /home/somename/Envs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/somename/Envs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/somename/Envs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/somename/Envs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/somename/Envs/test/bin/get_env_details
(test) somename@somename:~/.local/bin
$ python
Python 3.7.3 (default, Apr 18 2019, 11:12:01) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Please leave a comment below if you face any issues. Dont forget to give a star to the gist if you like it.

@apcrcom

This comment has been minimized.

Copy link

@apcrcom apcrcom commented Aug 29, 2019

Thanks for these instructions. They were helpful.

Notes:

the \ in the first section will screw anyone who doesnt understand what its there for and is copy pasting the syntax

For me the instructions worked up until:

sudo ln -sfn /usr/local/bin/python3.7 python

typing python yields 2.7.13

http://i.imgur.com/glb6HOn.png

@agatsoh

This comment has been minimized.

Copy link
Owner Author

@agatsoh agatsoh commented Aug 30, 2019

Sorry for the late reply. My emails are a mess. Have you resolved the issue already ? what do you get for which python ?. It worked for me when I had my machine. Unfortunately I dont have my machine with me right now. I see that you are in folder /usr/src/Python-3.7.3 folder.
May be if you run sudo ln -sfn /usr/local/bin/python3.7 python command from inside the /usr/bin/ folder it might work.

@jasonfigueroa

This comment has been minimized.

Copy link

@jasonfigueroa jasonfigueroa commented Sep 8, 2019

Thanks for this write up. I noticed that on running the following, the terminal seemed to hang.

sudo tar xzf Python-3.7.3.tgz

I added a dash to the flags and it ran fine.

sudo tar -xzf Python-3.7.3.tgz

@apcrcom

This comment has been minimized.

Copy link

@apcrcom apcrcom commented Sep 8, 2019

Excellent work. Thanks :)

@stzhng

This comment has been minimized.

Copy link

@stzhng stzhng commented Sep 12, 2019

this is missing a dependency
sudo apt-get install zlib1g-dev in debian 16.04+

@amad3v

This comment has been minimized.

Copy link

@amad3v amad3v commented Sep 23, 2019

Hi @agatsoh,
Linking python 3.7 to python will break the APT tool giving the following error ImportError: No module named 'ConfigParser' (ConfigParser for python 2, configparser for python 3).
It is better to link it to python3. Also PIP isn't installed by default so it's also a good idea to create a link to it:
sudo ln -sfn /usr/local/bin/pip3.7 /usr/bin/pip3
or
sudo ln -sfn /usr/local/bin/pip3.7 /usr/bin/pip

Can be done for IDLE also...

Good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.