This is just a short post to document the required commands to build Python 3 on a CentOS 7.
First we need to install the Development tools and some required sources: e.g. bzip, to support compression in python
yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Next we are downloading and compiling Python 3 as shared library. Compiling Python as shared library is afaik quite common and necessary for third-party tools such as mod_wsgi.
wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz tar xf Python-3.4.1.tgz cd Python-3.4.1 ./configure --prefix=/usr/local --enable-shared make make install
Before we can use Python we need to make the library findable:
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf ldconfig
Finally you should be able to launch python:
python3 --version Python 3.4.1
If you want to remove all the packages we required to compile python, including its dependencies, use the parameter “–remove-leaves” which I also described here.
yum groupremove "Development tools" --remove-leaves yum remove zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --remove-leaves
Thanks. Just what I needed!
Hi,
I’m new to linux and python and getting an error while installing.
I’m getting this error:
bash: syntax error near unexpected token `;&’
after this line:
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
Any help would be great thanks.
Try this instead. I think he meant to say use the “greater than” symbols
[root@linuxbox Python-3.4.2]# echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
[root@linuxbox Python-3.4.2]# ldconfig
[root@linuxbox Python-3.4.2]# python3 -V
Python 3.4.2
I used <> /etc/ld.so.conf” >> to get it working in Centos 7. Maybe this helps.
http://askubuntu.com/questions/279853/permission-denied-error-when-editing-etc-ld-so-conf
I just copied and pasted and it worked nice for me too, no problem.
Thanks
Dentiny
When I follow your instructions and execute pythin I get to:
./python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
Very helpful. Worked almost perfectly.
make install did not work as regular user, permission issue, so I used
sudo make install
Similar when trying to execute this command
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
I switched to root to execute this one.
Otherwise, it worked very smoothly.
gary
Thank you so much! I was looking for hours for this and only this tutorial helped me. All the best
Will this replace the system python version ?
Very concise and accurate. Thanks!
merci, worked !