This tutorial will show you how to install the latest version of Python 2 and Python 3 on CentOS by compiling from source. The examples below are for Python 2.7.14 and Python 3.6.3, but the procedure is the same for any modern version of Python.
If you are using CentOS 6 you can use this tutorial to install both Python 2.7.x and Python 3.6.x. For CentOS 7 only the Python 3.6.x instructions below are applicable. Warning! Do not install Python 2.7.14 on CentOS 7 using these instructions. Your system will end up having two different python2.7
binaries, each with its own package directory. This will likely cause difficult-to-diagnose problems.
This tutorial should work for all versions of CentOS 6 and CentOS 7, and it will probably work on the corresponding RHEL distributions as well. I have verified it on CentOS 6.9 64 bit and CentOS 7 (1611) 64 bit.
This tutorial is meant for people that are comfortable with compiling and installing applications from source.
What is the problem?
CentOS ships with Python as a critical part of the base system. Because it is a critical part it is not getting updated, other than to plug security vulnerabilities. The lack of updates means that CentOS 6 users are stuck with Python 2.6.6 released in August 2010, and CentOS 7 users are stuck with Python 2.7.5 released in May 2013.
Solving the problem
Utilities such as yum
will break if the default Python interpreter is upgraded or replaced. The trick is to install new versions of Python in /usr/local
(or some other non-standard location) so that they can live side-by-side with the system version.
Things to consider
Before you compile and install Python there are a few things you should know and/or consider:
Unicode
Python has a long and complicated history when it comes to Unicode support. Unless you have very specific reasons you should configure Python 2.7 to enable UTF-32 support. This increases memory usage but improves compatibility. In Python 3.3+ the Unicode support has been completely rewritten and strings are automatically stored using the most efficient encoding possible.
You enable UTF-32 in Python 2.7 by passing --enable-unicode=ucs4
to the configure command.
Shared library
You should compile Python as a shared library by passing --enable-shared
to the configure command. All modern Linux distros ship with Python compiled as a shared library. It reduces memory usage if more than one Python process is running, and there are third-party tools that might not work properly without it. To make sure the executable can find its shared library you also need to pass some additional flags to the configure command (LDFLAGS="-Wl,-rpath /usr/local/lib"
).
If you do not have sudo or root access you will probably not be able to compile Python as a shared library. If someone knows how to solve this please leave a comment below and I will update this text with instructions.
Use “make altinstall” to prevent problems
It is critical that you use make altinstall
when you install your custom version of Python. If you use the normal make install
you will end up with two different versions of Python in the filesystem both named python
. This can lead to problems that are very hard to diagnose.
Preparations – install prerequisites
In order to compile Python you must first install the development tools and a few extra libs. The extra libs are not strictly needed to compile Python but without them your new Python interpreter will be quite useless.
Execute all the commands below as root either by temporarily logging in as root or by using sudo
.
1 2 3 4 5 6 7 8 |
# Start by making sure your system is up-to-date: yum update # Compilers and related tools: yum groupinstall -y "development tools" # Libraries needed during compilation to enable all features of Python: yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel # If you are on a clean "minimal" install of CentOS you also need the wget tool: yum install -y wget |
Download, compile and install Python
Here are the commands to download, compile and install Python.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Python 2.7.14: wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz tar xf Python-2.7.14.tar.xz cd Python-2.7.14 ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make && make altinstall # Python 3.6.3: wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz tar xf Python-3.6.3.tar.xz cd Python-3.6.3 ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make && make altinstall |
After running the commands above your newly installed Python interpreter will be available as /usr/local/bin/python2.7
or /usr/local/bin/python3.6
. The system version of Python 2.6.6 will continue to be available as /usr/bin/python
, /usr/bin/python2
and /usr/bin/python2.6
.
You might also want to strip symbols from the shared library to reduce the memory footprint.
1 2 3 4 |
# Strip the Python 2.7 binary: strip /usr/local/lib/libpython2.7.so.1.0 # Strip the Python 3.6 binary: strip /usr/local/lib/libpython3.6m.so.1.0 |
Install/upgrade pip, setuptools and wheel
Each Python interpreter on your system needs its own install of pip, setuptools and wheel. The easiest way to install or upgrade these packages is by using the get-pip.py
script.
1 2 3 4 5 6 7 8 9 10 11 |
# First get the script: wget https://bootstrap.pypa.io/get-pip.py # Then execute it using Python 2.7 and/or Python 3.6: python2.7 get-pip.py python3.6 get-pip.py # With pip installed you can now do things like this: pip2.7 install [packagename] pip2.7 install --upgrade [packagename] pip2.7 uninstall [packagename] |
The packages will end up in /usr/local/lib/pythonX.Y/site-packages/
(where X.Y
is the Python version).
What’s next?
If you are using Python 2.7 I strongly recommend that you install virtualenv and learn how to use it. Virtualenv makes it possible to create isolated Python environments. If you are using Python 3.3+ then you don’t need virtualenv because that functionality is already built in.
Each isolated Python environment (also called sandbox) can have its own Python version and packages. This is very useful when you work on multiple projects or on different versions of the same project.
Create your first isolated Python environment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Install virtualenv for Python 2.7 and create a sandbox called my27project: pip2.7 install virtualenv virtualenv my27project # Use the built-in functionality in Python 3.6 to create a sandbox called my36project: python3.6 -m venv my36project # Check the system Python interpreter version: python --version # This will show Python 2.6.6 # Activate the my27project sandbox: source my27project/bin/activate # Check the Python version in the sandbox (it should be Python 2.7.14): python --version # Deactivate the sandbox: deactivate # Activate the my36project sandbox: source my36project/bin/activate # Check the Python version in the sandbox (it should be Python 3.6.3): python --version # Deactivate the sandbox: deactivate |
Changelog
2017-11-22
- Updated the shared library paragraph with some extra information.
2017-10-08
- Examples updated with Python 2.7.14 and 3.6.3.
2017-07-20
- Examples updated with Python 3.6.2.
2017-05-24
- Examples updated with Python 3.6.1.
2017-02-08
- Add warning about not installing Python 2.7 on CentOS 7 (since it already has 2.7 in the base system).
2017-02-07
- Examples updated with Python 2.7.13 and Python 3.6.0.
- Mention that this also works for installing Python 3.6 on CentOS 7.
- Added expat-devel to the list of prerequisites.
- Removed ldconfig instructions.
- Added instructions for stripping the shared libraries.
- Changed the instructions for pip/setuptools to use the get-pip.py script.
2014-03-15
- Examples updated with Python 3.3.5.
2014-02-16
- The Python versions used in the examples have been updated to 2.7.6 and 3.3.4.
- The list of library prerequisites has been extended so that more features are compiled into Python.
- New parameters for compiling Python with a shared library and for enabling Unicode UTF-32 support in Python 2.7 and Python 3.2 have been added.
- Instructions for installing and using setuptools, pip, virtualenv and pyvenv have been added/updated.
Thanks a lot, it worked like a charm!
Glad I could help.
Thanks for the help / worked great
Hey Daniel.
Is there anyway you could look into how to create a 3.7.x Python RPM from scratch on CentOS 7?
I work in an environment where everything needs to be compiled from scratch, or purchased CotS.
The only Python RPMs are in public repositories built by who knows whom.
I’ve tried so many times, but it fails for one reason, or another, or another, or another.
Thanks.
~ Dale ~
In order to compile Python you must first install the development tools and a few extra libs. The extra libs are not strictly needed to compile Python but without them your new Python interpreter will be quite useless
sudo yum groupinstall “Development tools”
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Here are the commands to download, compile and install Python
cd /usr/local/src
sudo wget http://python.org/ftp/python/3.2.2/Python-3.2.2.tar.xz –no-check-certificate
sudo tar xf Python-3.2.2.tar.xz
cd Python-3.2.2
sudo ./configure –prefix=/usr/local –enable-shared LDFLAGS=”-Wl,-rpath /usr/local/lib”
sudo make && sudo make altinstall
After running the commands above your newly installed Python interpreter will be available as /usr/local/bin/python3.2
/usr/local/bin/python3.2
Download and install Setuptools + pip
cd /usr/local/src
sudo wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo /usr/local/bin/python3.2 ez_setup.py
sudo /usr/local/bin/easy_install-3.2 pip
Create your isolated Python 3.2 environment
sudo /usr/local/bin/pip3.2 install virtualenv
sudo /usr/local/bin/virtualenv /usr/local/virtenv3.2
cd /usr/local/virtenv3.2
source bin/activate
python –version # (To check version)
Awesome work Daniel ! worked smoothly.
Not working for me. I have followed exactly same steps on CentOS 7.9 and installed Python 3.9.2 but it did not worked
Thanks Daniel. I second Onur.
I have two serpents now 🙂
Excellent post Daniel, thanks so much.
Excellent Post! Solved my big headache of vim compilation error..
hello,
after all this steps
i got this error when i use yum
No module named yum
how to fix it
thank you
Are you sure you installed your new python version using the command “make altinstall”. If you just used “make install” then you have replaced the system version (/usr/bin/python).
I think you can fix your problem simply by copying or linking /usr/bin/python2.6 to /usr/bin/python
Ran into the same issue when trying, of all things, to update bash against the Bourne shell vulnerability. It took me about 12 hours to figure out that the system python was using the wrong libraries (for Fedora 19, the system python is at 2.7.5, and every time I ran python or did a python -V I got the wrong version).
I ended up commenting out the reference to /usr/local/lib in ld.so.conf, and everything was good.
Greg–
I can confirm this in Scientific Linux 6.4 as well. Took me more than 12 hours to figure out the problem though as I had installed new versions of Python and gcc. Removed /usr/local/lib from /etc/ld.so.conf, ran ldconfig, and my system is back to normal now.
Agreed. Adding python to ldconfig is a bad idea, that will normally manifest itself later on. Rather than removing /usr/local/lib, I would either put python in a different prefix (/usr/local/python for example) or replace /usr/local/lib with more explicit /usr/local/lib/ in the ldconf. After all, you’re probably going to need access to some libraries in /usr/local…
Thanks for this comment. It helped me figure out why yum wasn’t working after I compiled Python 2.7.8 with /usr/local/lib in ld.so.conf on a Red Hat 7.2 system whose system-wide default is Python 2.7.5. (I had executed sudo ./configure followed by sudo make. Hadn’t got to the sudo make altinstall step).
However, if I try the other option
$sudo ./configure –prefix=/usr/local/python –enable-unicode=ucs4 –enable-shared LDFLAGS=”-W1,-rpath /usr/local/python/lib” I encounter the error:
configure: error: C compiler cannot create executables
See `config.log’ for more details
config.log contains the error message:
gcc: error: unrecognized command line option ‘-W1,-rpath’
How do I work around/fix this issue?
My mistake – I had a typo in LDFLAGS. It should be -Wl and not -W1 (lower case L instead of digit 1). It worked fine with the correction.
To me send me error in Python, how to replace from python27 to python?
I don’t understand your question. Please clarify!
how do add something to the pythonpath of python2.7
beautiful. worked perfect. Thanks for publishing. got me out of zlib error hell for a parallel python 2.7 install.
Pingback:Backing up to Amazon Glacier | Jacob Allred
Very nice work! thanks
How to fix no module name _sqlite3 ?
You need to have the sqlite-devel package installed before you configure and make python. Install it with “yum install sqlite-devel”.
Very nice, but how about throwing in a # yum install readline-devel? Makes the python interpreter easier to work with later (not to mention ipython).
Good suggestion! I’ll add it to the updated guide that I will post shortly.
Thanks Erik, after installing readline-devel, config detects the readline libs automatically, and compile in the support by default… the command line is way better!
I see failure when installing Tkinter using “easy_install-2.7 Tkinter”. How can I make it work?
error: Could not find suitable distribution for Requirement.parse(‘Tkinter’)
I needed another module ‘pexpect’ and “easy_install-2.7 pexpect” worked fine.
Issue fixed: After ‘yum install tk-devel’ and then reinstall python “make && make altinstall” I was able to import Tkinter properly. Didnt have to install Tkinter explicitly using “easy_install-2.7 Tkinter”
Thank you for the information! I will include this in the updated guide that I will post shortly.
Thanks Sanjay! That fixed a persistent problem that I had. I’m so glad you took the trouble to post. I had tkinter working in the (default) Python2.6, so I knew that all the necessary .so files were installed, but I forgot/didn’t realize that the tk-devel files would be necessary during the compilation of Python2.7.
after following all above steps, it istalled python 2.7(i checked directory where it install, its ok) but when i check python -V. it show python 2.6.6 instead of python 2.7. please help me how to change default python 2.6 to 2.7.
You do NOT want to change default python version because that breaks some system services (like yum for example). You have two options:
1. Always use “python2.7” instead of “python” when you start python scripts.
2. Set up a virtualenv with python 2.7 and run everything from inside that virtualenv.
i got this error “-bash: python2.7: command not found” after typing python2.7 setup.py install on your instruction in Download and install Distribute for Python 2.7, how can i overcome this wall? thanks in advance
I have same error. How to fix this issue?
This is fantastic. Thank you!
Thank you for doing this! I am having one problem…When I run:
python2.7 setup.py install
I get:
bash: python2.7: command not found
Do you have an executable named /usr/local/bin/python2.7? Is /usr/local/bin on your PATH?
Thanks a lot it worked ,fine !!!!
Works great! Thanks a lot 🙂
Many thanks! Work great and fine.
Very great! Works.
Thank you.
Pingback:Broken python installation on CentOS 5.8 | UmeedainTimes.com
I get this error after I attempt to run Python for the first time:
/usr/local/python2.7/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
What options did you pass to configure? It doesn’t look like you used my suggestions.
Your suggestions didnt include –enable-shared … that’s why he got the error he did.
My update of the instructions with LD_LIBRARY_PATH and –enable-shared is here – http://www.livingcosmos.org/2013/04/how-to-install-python-2-7-and-3-3-on-centos-6-too-much-data/
admittedly a very garbage looking post, but it gets the job done
Hi had a similar problem to install mod_wsgi – need to enable-shared and now can’t find libpython2.7
Unfortunately your blog article seems down. Can you bring it back up?
Many thanks
I had similar problem, with mod_wsgi requires –enable-shared
This command solved the problem:
./configure –prefix=/usr/local -–enable-shared LDFLAGS=”-Wl,-rpath /usr/local/lib”
and then when building mod_wsgi using:
./configure –with-python=/usr/local/bin/python2.7
See also: http://koansys.com/tech/building-python-with-enable-shared-in-non-standard-location)
If you typed
include ld.so.conf.d/*.conf
/usr/local/lib
when you installed, you may be getting this error because you forgot to run
/sbin/ldconfig
Just running that command fixed it for me
It works like a charm on my VPS 😀
Thank you very much
Pingback:Хостинг WSGI з nic.ua | Roman Yepishev
You made this process so easy, thanks for the detailed steps! CentOS is too “stable” to be upgraded…. Only got python24 on my server.
Works on Centos 5.8 as well.
Thanks for the tutorial. How come there aren’t any easily obtainable RPMs for this kind of thing? It’s baffling to me that EPEL has PyPy 1.9 but no CPython 2.7.
hey thanks for the tutorial. How do we point django’s default python to this python ?
The best way is to run your Django app from inside a virtualenv. Look at the last steps in the article above for info on how to properly install virtualenv.
Thanks very much. It all worked until I saw this:
————————————————————————————–
Python build finished, but the necessary bits to build these modules were not found:
bsddb185 dl gdbm
imageop sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
running build_scripts
creating build/scripts-2.7
copying and adjusting /disk2/software/Python-2.7.3/Tools/scripts/pydoc -> build/scripts-2.7
copying and adjusting /disk2/software/Python-2.7.3/Tools/scripts/idle -> build/scripts-2.7
copying and adjusting /disk2/software/Python-2.7.3/Tools/scripts/2to3 -> build/scripts-2.7
copying and adjusting /disk2/software/Python-2.7.3/Lib/smtpd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/pydoc from 644 to 755
changing mode of build/scripts-2.7/idle from 644 to 755
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
make: stat: Modules/config.c.in: Permission denied
make: *** No rule to make target
Modules/config.c.in', needed by
Makefile’. Stop.—————————————————————————————
There is nothing at all in my /usr/local/bin.
Any suggestions?
I’m far from an expert, but the Python readme contains this:
Unix platforms: If your vendor still ships (and you still use) Berkeley DB
1.85 you will need to edit Modules/Setup to build the bsddb185
module and add a line to sitecustomize.py which makes it the
default. In Modules/Setup a line like
bsddb185 bsddbmodule.c
should work. (You may need to add -I, -L or -l flags to direct the
compiler and linker to your include files and libraries.)
XXX I think this next bit is out of date:
64-bit platforms: The modules audioop, and imageop don’t work.
The setup.py script disables them on 64-bit installations.
Don’t try to enable them in the Modules/Setup file. They
contain code that is quite wordsize sensitive. (If you have a
fix, let us know!)
That all suggests to me that you can edit the configuration, but there may be more information lower down in the readme. For example, I had to dig to find –enable-shared, which I needed.
Thanks for replying. I think I’ve got it now. It turned out to be a file protection problem. I’ve been trying to install using “sudo make && make altinstall” but apparently sudo doesn’t let me cd to directories that I don’t have rights too. So at first I started changing all the directories I needed in the source tree to 755. I still ran into a problem installing files into /usr/local/bin – I didn’t want to change the protection there. Fortunately, I could just do “sudo su” and do the install as root.
Good to hear you solved it!
Thanks, Dave. That did the trick for me. And thank you, Daniel, for such a useful guide.
You want to do sudo make && sudo make altinstall — need to sudo on both commands.
Something that can be easy forgotten due to the first ‘sudo’ and ‘&&’.
Thank you!!! I was not adding the second sudo
First I want to thank Daniel Eriksson and all others who have posted their experience and solutions. I don’t have any knowledge about building packages at this level on *nix…
I’ve simply been following instructions listed on this page to install python-2.7.9, things went so well I’ll try 3.4.2 also…
I encountered similar error to Dave.
I too was using ” sudo ” to run commands to perform installs.
After reading Dave’s post above I went back and ran everything as ” root ” ( su root ),
./configure –prefix=/usr/local –enable-unicode=ucs4 –enable-shared
make && make altinstall
ls -l /usr/local/bin/py*
-rwxr-xr-x 1 root root 84 Dec 23 17:16 /usr/local/bin/pydoc*
-rwxr-xr-x 1 root root 9760 Dec 23 17:47 /usr/local/bin/python2.7*
-rwxr-xr-x 1 root root 1687 Dec 23 17:47 /usr/local/bin/python2.7-config*
Thanks Dave, for posting complete message which I searched for and found. My issue appears to be resolved after running as ” root ” and not ” sudo ”
Python build finished, but the necessary bits to build these modules were not found:
bsddb185 dl imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
running build_scripts
creating build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/pydoc -> build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/idle -> build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/2to3 -> build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Lib/smtpd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/pydoc from 644 to 755
changing mode of build/scripts-2.7/idle from 644 to 755
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
/usr/bin/install -c python /usr/local/bin/python2.7
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.7′: Permission denied
make: *** [altbininstall] Error 1
Excellent post Daniel !!
Another way to fix is “sudo make && sudo make altinstall”
Thank you! Most helpful.
Pingback:Run in a CentOS server
Thanks a lot Daniel.
The build was very clean and works like a charm.
I managed to install python 2.7.3 without breaking yum.
How to make a specific user to use python 2.7.3 as virtual env ?
Each virtualenv has its own Python version that is set when the virtualenv is first created. It is up to the user to decide what Python version he/she wants in each virtualenv.
Smooth as silk, thanks very much for taking the time to put this together
Pingback:Installing Python 2.7 on CentOS 5 | My Blog
Thanks a bunch. Was having a hard time getting python to install with many other resource I found on google. 10*
Thanks for the tutorial. I did everything you said, so if I understand correctly, now I have to install
1) python 2.7 once again
2) Will this virtualenv become default or how do I control it ?
I dont know much about python and vertualenv, hence the silly questions.
If you followed the tutorial you already have everything you need. When you create a new virtualenv you will automatically get a copy of the proper version of python inside that folder structure.
A virtualenv is never “default”, you have to manually activate it. Once activated your default python interpreter will change from the system default to the one in that particular virtualenv.
You can have as many virtualenv as you like on a machine, and each virtualenv can have a different default python interpreter, and different installed packages.
This is really useful when you develop multiple applications, each with different requirements. I do Django development myself and it is really useful to have one virtualenv for each project because one website might run Django 1.4, another might run 1.2 and yet another one might run 1.5 beta. I do most of my development in Eclipse with the pydev plugin, and that plugin knows about virtualenv so I just configure one interpreter for each project and point it at the python executable inside that particular virtualenv.
Maybe I should clarify that activating a virtualenv only affects your current session/shell.
I Want to run twissted protocol inside python 2.7 as it is working with python 2.6.6 . Please suggest
thanks a lot 🙂 it works! 🙂
Thank you. Worked perfect.
Regards
Santosh
Thanks buddy , easiest but best routine. I’m going to check your other posts.
Very useful post, you can update some version numbers that also worked for me: Centos 6.3 and distribute 0.6.35
Thank you, update done!
I have now updated the tutorial with additional information provided here in the comments, plus updated versions, plus more information about virtualenv. Enjoy!
i have intsall python using altinstall command, but still it show version 2.4
how to resolve it
The system default Python interpreter does not change, that is the whole point of this tutorial. To start your new Python interpreter you must issue the command /usr/local/bin/python2.7 (or simply python2.7 if /usr/local/bin is in your PATH which it usually is).
Hi there!
I have problem while running “make && make altinstall”. It overlap and non-stop, i mean the installation never finished. It showing:
By default, distutils will build C++ extension modules with “g++”.
If this is not intended, then set CXX on the configure command line.
And then restart the installation process.
Unfortunately I don’t know what could be causing that problem. Maybe you have installed something that messes around with your C/C++ toolchain. My only advice is to google the error message and see how others have solved it.
Works! Thanks!
Dear Colleagues,
I tried to install Python 2.7.3 and Python 3.3.0 following the method published in this blog.
My yum is now broken and after I requested the centos forum, I was advised to uninstall these 2 versions of python. How do I uninstall them, is there a command to do this?
With best regards,
Philip
Are you sure you followed the instructions? Especially the part where you use ALTINSTALL instead of INSTALL? I doubt you did, because if you used ALTINSTALL then the system version of Python would still be 2.6.6.
What is the output of the following commands:
# python –version
# /usr/bin/python –version
The Python makefile does not provide an uninstall target so you will have to remove the files manually if you want that.
I did the same thing.. I thought I needed 2.7.3 along with 3.3 so I installed both.. I did do it with altinstall though.. so my yum works fine…
How do I uninstall 3.3? I see you wrote just remove the files.. but can you be more specific as there are a ton of files?
Dear Daniel,
Thank you for replying back. Please find the required information below.
$ python -V
Python 2.7
$ yum
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
Can we change the defauly version of python to the original 2.6.6?
With best regards,
Philip
Please check the version of /usr/bin/python.
If it is 2.6.6 then your PATH is most likely in the wrong order (/usr/bin should be before /usr/local/bin).
If it is 2.7.3 then you didn’t follow the steps in this guide. You can still salvage the situation by doing this:
rm /usr/bin/python
ln -s /usr/bin/python2.6 /usr/bin/python
Thanks a lot! This article really helps me.
Dear Daniel,
You are right, I may have done a lot of more than what the guide says (I have a 64 bit system). Please kindly help me resolve this error, as most of my work is pending because I am not able to use yum. We could connect via webex/ teamviewer, please let me know when you are free and I will send you my teamviewer login details.
I have tried out your suggestions, but the error with yum remains. Please find the below log-
==============================
$rm /usr/bin/python
rm: remove symbolic link `/usr/bin/python’? y
$ln -s /usr/bin/python2.6 /usr/bin/python
$yum
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
$python -V
Python 2.7
===============================
Thanking you and with best regards,
Philip
Verify that /usr/bin/python2.6 really is version 2.6. If it is then you have another binary called python somewhere else in your filesystem, in a location that is searched before /usr/bin. Check the order of your PATH variable.
Thanks Daniel for the great tutorial. I’ve installed PyCrypto, and it fails with the following:
Running pycrypto-2.6/setup.py -q bdist_egg –dist-dir /tmp/easy_install-wQetbc/pycrypto-2.6/egg-dist-tmp-FPHtu0
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
zip_safe flag not set; analyzing archive contents…
Then, I ran yum install mpir, and I got:
Package mpir-1.3.1-4.el6.x86_64 already installed and latest version .
Similarly, it said gmp was installed and latest.
I’ve been told I need python2.7.3-devel to get PyCrypto to build. I can get it from an RPM I found but I don’t think it’s a great idea (I have to symlink all kinds of things everywhere and then install the RPM — maybe not great.)
Any idea how I can solve this? Also, if I want to remove Python 2.7.3: Any specific instructions?
Thanks again!
Not sure I can help you with PyCrypto, at least not right now, but I can tell you that you already have what is included in the devel package (libs and headers).
Removing Python is pretty easy, all the files you need to delete are located under /usr/local and fairly easy to spot. This should get you going:
/usr/local/bin/python2.7
/usr/local/include/python2.7 (dir)
/usr/local/lib/libpython2.7.a
/usr/local/lib/python2.7 (dir)
There are a few more executables under /usr/local/bin that you can remove also (pydoc, idle, 2to3, …). List the dir in chronological order to see what other (if any) files were installed there at the same time as python2.7.
Worked on centos 5.8; I was upgrading python to 2.7.3…thanks!!
very useful article, great work, thanks!
Thanks! Worked perfectly on CentOS 6.4. I have 2.6.6, 2.7.3 and 3.3 all living in peaceful harmony.
Pingback:Living Cosmos
Hi Daniel,
This is by far the best tutorial I have found for installing python 3.3 on Centos. After running into some permission errors, I successfully ran the make && make altinstall. The folder created is /usr/local/bin/python3.3m as opposed to /usr/local/bin/python3.3.
When I try to run the command python3.3 setup.py install, I receive the error: “-bash: python3.3: command not found”. Any ideas on how to fix this?
Pingback:CentOS6にpython2.7を入れる | ちいさな創々
Daniel, thanks for the tutorial. This worked like a charm on Cent OS 5.7, which ships with Python 2.4.
FYI, the newest versions are 2.7.4 and 3.3.1, released yesterday and today, respectively. I installed 2.7.4 no problem by just replacing the release version number in your instructions. (Didn’t try 3.3.1.)
It’s great to have these straight-forward instructions for those of us who know enough about linux to easily understand & follow your tutorial, but don’t perform these actions regularly enough for them to be intuitive. (I would never have thought to install the development tools first, for example.) Thank you very much.
Thanks a lot man, It worked find! 🙂
Worked like a charm .. Thanx Daniel
Pingback:linux tips linux命令锦集
Echoing everyone else – thanks for the quickie.
Sweet !!!…This worked like a charm, not even a single hiccup.
Hi Daniel,
I am new to Linux, I am following your steps to install python3.3 on cent0s 6, all the steps works until when I get to “make && make altinstall”.
Ithrows the following error: make: *** No targets specified and no makefile found. Stop.
it seems that, I am not getting something right. Could you please help. Many thanks
no answer yet
I haven’t done 3.3, but this sound like you’re running the command in the wrong directory. Are you in the directory containing the makefile (probably actually named Makefile) ?
Thanks for the reply Dave, yes I was in the Makefile directory. All the steps from Daniel worked until when I go to “make && make altinstall” Cheers.
Most strange. Does “make –file=Makefile” behave any better ? Or “make –file=./Makefile” ? If not, I’d suggest showing us the output of “pwd; ls -l; alias make ; env |grep -i make” (all just grasping at straws.)
Did anyone answer the question about setting the PYTHONPATH in the virtual environment or is that not necessary?
Just a philosophical question: what’s the point of the centos package management, if you have to install packages manually?
In this case, it’s because the CentOS repositories do not have Python 2.7 and 3 in them and the versions that they do contain are rather obsolete.
Hello,
I’ve just updated to python3-3.3.1 as rpm packages on:
http://jur-linux.org/download/el-updates/6/
This is based on the newest Fedora rpm to compile on RHEL6, any additional
testing more than welcome for people who don’t want to recompile themselves.
best regards,
Florian La Roche
hello, i’m trying to install anki 2.0.3 on my cent 6.x box, followed instructions, but anki rpm still says that it needs 2.7 to install? halp?
Following the instructions to build 2.7.4 on CentOS 6.4 I get
‘WARNING: old charecter set or encoding…’ message and a garbaged screen only starting /usr/local/bin/python2.7 but not Python
Pingback:How to install Python 2.7 – On Windows, Ubuntu and CentOS | Buzz Atom - Your Way Into The Core of Nimbuzz
Thanks a lott, really helpful
Fix: I think you’re missing a j in
tar xf Python-2.7.3.tar.bz2
should be
tar jxf Python-2.7.3.tar.bz2
You are so awesome. THANKS!!!!!!!!!!!!!!!
Worked perfectly with 2.7.4 and 3.3.1 on Fedora 18. I prefer to have my installations more self-contained, so I added the –prefix and –exec-prefix options to the configure command line.
thanks, worked really well
Thank you so much. This is very helpful!
Pingback:Not RSS 2 Email — Half-Elf on Tech
Thank you all very much guys! (Dave T and Daniel). I installed GCC and after that, the “make && make altinstall” ran perfectly. Python is now upgraded to 3.3. I have been away, hence the late response, pardon. Much appreciations for your expert advice.
Pingback:How to install Python 2.7 and 3.3 on CentOS 6 |...
Very good instructions. It got me half of the way there, but… Do you happen to know how to get the rest of the package (2.7)? The whole point of installing 2.7 in my case was one function: to run a Cython conversion, which requires the -devel package/headers. The CentOS (version 2.6) -devel files were installed with 2.6 but could never be found found by Cython, and apparently the 2.7 from python.org. does not include -devel files at all?? I have been all over python.org’s site, but if the -devel package is there, I cannot find it. Is it available anywhere else? Obviously CentOS won’t have it, since they did not have version 2.7.
Maybe it is in the python-kitchen package, available from the Epel repo
thank you. It’s good.
This was clear, concise, and accurate. Thank you for taking the time to put this together– I greatly appreciate it! This saved me hours putting together the steps on my own.
Pingback:Instalar Python 2.7 en CentOS 6 con mod_wsgi de forma segura | Hello, IT.
Pingback:Comment on How to install Python 2.7 and 3.3 on...
The above instructions worked great. I am tyring to install mininet from rpm and it is complaining that it requires /usr/bin/python2.7. /usr/bin/python is 2.6.6 and /usr/bin/python2.7 is 2.7.5. Any thoughts on how to get around this dependency on /usr/bin/python being version 2.6?
This worked fantastically on CentOS 6.XX. Thank you very much!
Hello, thanks for the post, worked fine.
In you guide you recommend to install “Distribute” but now on their website it’s written that it’s a deprecated fork of “Setuptools”. Maybe a small upgrade to your guide?
Thanks
Distribute is not deprecated, it is actively being developed. Where exactly did you read this?
https://pypi.python.org/pypi/distribute :
Distribute
is a now deprecated fork of the
Setuptools` project.Ooops, I had no idea this was taking place. I wonder if Setuptools 0.7.2 is “production ready” yet? Time to go run some tests. Thanks a lot for the heads-up!
Worked perfectly first time on CentOS 6.4 (though I used the updated versions of each).
Much appreciated!
Pingback:Installing and compiling Python 2.7 on Centos 6.3 | Information Assurance
Great post! I also added the following dependencies: gdbm-devel and db4-devel
This allows for gdbm, dbm, and _bsddb to build.
My final unsupported modules (after running make) for python 2.7 on x64 were:
bsddb185 dl imageop sunaudiodev
All of which are obsolete.
I also second the previous poster about installing setuptools over distribute.
Pingback:By: Walt | Centos 6 RHEL Linux | Scoop.it
aha,thank you very very much~it works well
Thanks for this guide. However, I do not have root privileges on this computer. I wanted to install python 2.7 since all the codes I have written are optimized for 2.7. I also want this to be the default version and wanted to know if this was possible?
Daniel, your procedure is awesome! Thanks. I successfully installed Python 2.7.5 and distribute 0.7.3 on CentOS 6.4. I ran into an issue using wget to download distribute 0.7.3 (seems to be a certificate error), so I downloaded it directly from https://pypi.python.org/pypi/distribute/0.7.3 using http.
Daniel, Thanks for putting this up! However I’m getting:
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.7′: Permission denied
When running “make && make altinstall” even if I run sudo with the command. I’d appreciate any help you could give!
This sounds like the issue Dave M reported on 2012/12/22, above.
If /usr/local/bin is mounted from a remote machine, that could cause problems, too; remote root write access is often disabled on exported filesystems. Does /usr/local/bin/python2.7 already exist ? If so, who owns it, and what are the permissions ? If not, then same questions for /usr/local/bin, then /usr/local.
As ever, I’m just grasping at straws.
I appreciate it Dave! I actually figured it out, but forgot to post back here. For whatever reason running “sudo make && make altinstall” with my sudo user didn’t work. Even if I changed the owner of the bin/python2.7 Yet then I tried running “sudo bash” then “make && make altinstall” and it work perfectly!
You should have instead done this:
make && sudo make altinstall
The way you did it, sudo only applies to the first make – which doesn’t even need to be done by root. Only “make altinstall” needs to run as root, because that is when files are created in /usr directories.
Worked for me using “sudo make altinstall”. If that doesnt work try “chmod 744 /usr/local/bin” (depending on your security situation). Note that if you use sudo then python2.7 will only be available to the root user.
Pingback:CentOS 6.4 PYPI本地源制作 » 陈沙克日志
It’s now available in vagrant. Check this out: https://github.com/ardydedase/vagrant-python-centos63.
Pingback:Instalar Python | Blog de Mario Javier
Hello,
Thanks a lot by the tutorial…
I need to install python-devel now for version 2.7.
I tried “easy_install-2.7 python-devel” and got the following:
Reading http://pypi.python.org/simple/python-devel/
Couldn’t find index page for ‘python-devel’ (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for python-devel
error: Could not find suitable distribution for Requirement.parse(‘python-devel’)
Any ideas?
Regards,
Camps
Hi,
I did exactly as you mentioned but how do I install python abi for 2.7 can you let me know. One of the packages I am trying to install depends on python abi 2.7 !!
Thanks 🙂
Hi friends!
# virtualenv-2.7 –distribute someproject
Could anybody tell me one example of ‘someproject’ ?
The domain folder root? Is this correct?
# virtualenv-2.7 –distribute /var/www/vhosts/mydomain.es
Thanks
“someproject” is the aliase you choose for your python. for example, you could use py273 for Python2.7.3 and the system will create a directory py273 under the ../distribute-0.7.3
Great work!
Pingback:Python 2.7 on Centos
Hello,
I have installed Python 2.7 by on centos 5 from source code. Python 2.4 is already there in centos 5. Could you please help me to uninstall Python 2.7 so that I can reinstall it with yum.
Pingback:Sudoer statement syntax to source virtualenv activate file | BlogoSfera
Any advice on installing scipy/numpy/matplotlib this way? I’m using centos 6 and was able to get python2.7 and distribute installed using the great instructions above. But “easy_install2.7 scipy” fails (even after numpy is installed).
Hi python27,
I have the same issues as your. Did you manage to get rid of it ?
Thanks
rhu
My too. How do I install Numpy for Python 2.7 being installed as altinstall?
This is one of the clearest how-to articles I have encountered in years! You completely covered the steps required from A-Z. I didn’t know how much was missing from other articles until I read this. Thank you so much.
Hi I followed the steps to install python2.7 but still I run into following errors:
http://pastebin.com/gAPLRLc2
I guess it might be because ssl is not getting configured for my python2.7 install, am not able to get past it
Can somebody plz help.
Pingback:CentOS | Pearltrees
Hi, thanks for these great and clear instructions! I only had one problem when I got to the portion of installing Distribute. The setup for Distribute would not work unless I added the option “-with-zlib=/usr/include” to the configure script line. So, like this:
./configure –prefix=/usr/local -with-zlib=/usr/include
if it helps, I was on Centos 6.4, trying to install Python 2.7.5 and distribute 0.6.49.
“someproject” is the aliase you choose for your python. for example, you could use py273 for Python2.7.3 and the system will create a directory py273 under the ../distribute-0.7.3
Thanks very much, Python 3.3.2 worked very well on my CentOS 5.10 Server!
I used setuptools instead of distribute, as it is deprecated and merged back to setup tools.
However I got this issue, which is done by just installing it without ez_install 😀
http://serverfault.com/questions/537862/install-python-setuptools-on-centos-6
I should have compiled Python with
./configure –prefix=/usr/local –enable-shared
This will make a shared library: libpython2.7.so
You will need it if you ever want to compile mod_wsgi. I found that in the hard way as mine failed to compile….
http://code.google.com/p/modwsgi/wiki/InstallationIssues#Lack_Of_Python_Shared_Library
Very awesome work Daniel. The extra tips on installing distribute and virtualenv were well worth coming here, thanks a lot.
Also, I don’t know if anyone else pointed it out, but it is unfortunate that CentOS 6 repos don’t have a python2.7 rpm on them. I will see if they have a bug about this already, and file one if they don’t.
Works nice !
I installed it in /usr/local/python-2.7/
When build your python, be sure to put
“–enable-uncode=ucs4”
Otherwise it will be built in UCS2 model, leading “undefined symbol: PyUnicodeUCS2_GetSize” errors in package matplotlib. Thanks.
Sorry, “–enable-uncode=ucs4″ should be “–enable-unicode=ucs4″, a typo.
Help im getting
ERROR: certificate common name “*.a.ssl.fastly.net” doesn’t match requested host name “pypi.python.org”.
Add
–no-check-certificate
to the request, either just after the wget or at the end of the line.
after reading so many articals about easy_install,pip and virtualenv,this one is most usefull and clearly.Thank you very much~
To install and get working the actual Python version 3.3.2 @ up-to-date CentOS 6.4,
you need to modify the step “Download and install Python 3.3.x”
by adding –with-ssl:
./configure –with-ssl –prefix=/usr/local
Otherwise you end up with numerous ssl related errors and stuff not working.
(e.g. :
/usr/local/bin/easy_install-3.3 virtualenv
Searching for virtualenv
Reading http://pypi.python.org/simple/virtualenv/
Download error on http://pypi.python.org/simple/virtualenv/: unknown url type: https — Some packages may not be found!
…
or
# pip -V
…
ImportError: No module named ‘_ssl’ )
This also happen if you do not have openssl-devel package:
yum install openssl-devel
Thanks Cupy,
thats the exact thing i was looking for.
thank you first.
And i have another question,since when we use virtualenv,we always use it like this way:/usr/local/bin/virtualenv-XXXX or /usr/local/bin/virtualenv-yyyy rather than simply use /usr/local/bin/virtualenv,why not remove or rename /usr/local/virtualenv?
this file may bring some confusion because of the version information.
Running perfectly well.
Thanks a lot, Daniel.
Pingback:I ran into Python | Private Dock
Pingback:Monday, December 2nd, 2013 | DayByDayFindings
Hello,
where does distribute download? in /usr/local/?
After install distribute, Can I delete distribute folder?
Thanks
thanks a lot! you rock
Pingback:How to install Python 2.7.3 on CentOS 6.2 | yetaocloud
Hi Daniel,
I have got an HTTPSHandler error while installing packages using pip as with the following stacktrack,
on ubuntu10.04 with python2.7
———————————desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File “/home/gaurav/.genv/bin/pip”, line 9, in
load_entry_point(‘pip==1.4.1’, ‘console_scripts’, ‘pip’)()
.
.
.
. from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler
Help to come out from this error, will be thankful to you 🙂
http://namhuy.net/908/how-to-install-iftop-bandwidth-monitoring-tool-in-rhel-centos-fedora.html
Requirements:
libpcap: module provides a user-level network packet capture information and statistics.
libncurses: is a API programming library that enables programmers to provide text-based interfaces in a terminal.
gcc: GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages.
Install libpcap, libnurses, gcc via yum
yum -y install libpcap libpcap-devel ncurses ncurses-devel gcc
Download and Install iftop
wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
./configure
make
make install
Pingback:Bruteforce Facebook Login with Python Script | franx47
Excellent and very helpful article, thank you!
BTW, tried to follow the procedure Today on CentOS 6.4 64bi and encountered error “… OSError: Command /home/swamydkv/py_virenv/test/bin/python3 -c “import sys, pip; pip…ll”] + sys.argv[1:])” setuptools pip failed with error code 1″ described at following URL:
http://askubuntu.com/questions/400343/trying-to-create-a-python-virtual-environment-but-getting-oserror
It looks we have a bug in current version of setuptools, so fix was to downgrade virtualenv to 1.10.1 using following command:
easy_install “virtualenv<1.11"
Hope this info will be helpful if someone runs in the same issue I had Today J.
Thanks for the post… and for the update to the recently-released python 3.3.4. I have used this page as reference a few times in the past and today, while showing it to a friend that wanted to upgrade python on an older server, I saw you had the updated instructions for 3.3.4, which got released just 3 days ago.
I will update the post with info about installing Setuptools later tonight. Distribute is deprecated.
If this is only for development, isn’t it better to avoid system wide installation by using –prefix=$HOME/.fakeroot/usr?
I think that is a personal preference thing. If I have root access I usually install things like this system-wide even if it is only used for development. One reason to do this is that I want to keep my development/staging environment as close as possible to the deployment environment.
When I don’t have root access I usually install in $HOME/Python-x.y.z to keep it fully separated from other user-installed apps. I don’t even add that bin dir to the path because I just need it once when I set up a new isolated environment with virtualenv or pyvenv.
Hi Daniel,
Many, many thanks for what has to be the best tutorial on the web for installing Python 2.7 and 3.3 on CentOS 6. I tried it and it worked fine.
I don’t know if you’ve run into this, however, and if you did I’d appreciate any insight you have to it. After installing Python 3.3 according to your instructions, then doing pip install’s of the following within the virtualenv of my33project:
numpy
scipy
matplotlib
ipython
pandas
sympy
nose
I get the following error when I run “ipython3 –pylab”:
[TerminalIPythonApp] WARNING | GUI event loop or pylab initialization failed
Here are the errors pointed to with the warning:
TclError Traceback (most recent call last)
/usr/local/lib/python3.3/site-packages/IPython/core/shellapp.py in (key)
221 shell = self.shell
222 if self.pylab:
–> 223 enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
224 key = self.pylab
225 elif self.matplotlib:
/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
2918 from IPython.core.pylabtools import import_pylab
2919
-> 2920 gui, backend = self.enable_matplotlib(gui)
2921
2922 # We want to prevent the loading of pylab to pollute the user’s
/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
2884 # Now we must activate the gui pylab wants to use, and fix %run to take
2885 # plot updates into account
-> 2886 self.enable_gui(gui)
2887 self.magics_manager.registry[‘ExecutionMagics’].default_runner =
2888 pt.mpl_runner(self.safe_execfile)
/usr/local/lib/python3.3/site-packages/IPython/terminal/interactiveshell.py in enable_gui(gui, app)
306 from IPython.lib.inputhook import enable_gui as real_enable_gui
307 try:
–> 308 return real_enable_gui(gui, app)
309 except ValueError as e:
310 raise UsageError(“%s” % e)
/usr/local/lib/python3.3/site-packages/IPython/lib/inputhook.py in enable_gui(gui, app)
526 e = “Invalid GUI request %r, valid ones are:%s” % (gui, list(guis.keys()))
527 raise ValueError(e)
–> 528 return gui_hook(app)
529
/usr/local/lib/python3.3/site-packages/IPython/lib/inputhook.py in enable_tk(self, app)
322 if app is None:
323 import tkinter
–> 324 app = tkinter.Tk()
325 app.withdraw()
326 self._apps[GUI_TK] = app
/usr/local/lib/python3.3/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
1798 baseName = baseName + ext
1799 interactive = 0
-> 1800 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1801 if useTk:
1802 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
Would you know how to fix this?
These look like standard messages from an X-enabled application unable to open the display. I don’t use ipython, but I believe it has a command-line option to run in the terminal.
If you ssh’d to the machine where you’re running ipython, you may have forgotten to use the ssh option -X or -Y.
Hi Dave, and thanks for the reply.
X11 Forwarding is already enabled through the sshd_config file. I don’t see what starting the shell session with the -X or -Y option would do above that.
Daniel, you don’t have any insight into the problem I am experiencing above?
No, not really. Have you tried to launch any other X applications to verify that forwarding works?
Another blind stab: it looks like ipython3 is doing its work in subprocesses. Perhaps those are running login shells which unset or otherwise disturb the DISPLAY setting ? But clearly Daniel’s question is the key.
Can xclock, xlogo, xload, or any other X application run ?
before i could successfully do:
python2.7 ez_setup.py
i had to:
yum install zlib-devel
then redo the python install:
make&&make altinstall
then it works
That is part of the preparations step of the guide. Are my instructions wrong or did you not follow the guide?
Hi,
In Python 3.3, can you add installation of the xz-devel package? It is needed for lzma module
Thank you, I tried this and it works just fine for both 3.3 and the recently released 3.4. I’ll include your recommendation in my next update.
If you’re getting permission errors when running easy_install and pip, but sudo’ing gives you ‘command not found’ errors, the path for the superuser is different from yours. Wrap the command in a $(which commandname) before passing into sudo so it looks on the absolute path:
sudo $(which pip2.7) install virtualenv
Thanks, it has been clear and accurate, and has helped me.
Pingback:my emacs and linux engineering note. | nova0302
Pingback:How to install python 2.7 on CentOS 6.5 | nova0302
Tahnks!, It’s very useful article
what happens if python is upgraded to 2.7 and 2.7 has to be run the same time as yum. That is:
/usr/bin/yum -d 0 -e 0 -y install openstack-keystone
This command also checks that the package openstack-keystone needs python 2.7 libraries
and throws error if they are not found, but on the same time yum needs python2.6.x
Can these 2 demands live together ?
First of all you don’t actually upgrade Python by following the instructions in this guide, you merely install a new version side-by-side. I have no idea what happens if Python 2.7 is called from a script running under Python 2.6. If PYTHONPATH is mangled then all sorts of (not so) funny things might happen. Why not do a quick test in a VM (or on a VPS that charges by the minute or hour)? I don’t know enough about OpenStack to verify if Keystone works if I could get it to install, so I would just be wasting my time doing it.
Sweet. Ure a hero!
Awesome !! thanks for a terrific blog !! helped alot..
Dear Daniel,
Why do i get this error when trying to execute this command
python3.4 ez_setup.py
”
File “/usr/local/lib/python3.4/zipfile.py”, line 614, in _get_decompressor
return zlib.decompressobj(-15)
AttributeError: ‘NoneType’ object has no attribute ‘decompressobj’
”
?
Best regards
Did you install zlib-devel before you ran configure and make?
Hi, I have the same problem. I installed zlib-devel AFTER building python. How can I proceed now with the pip installation?
Thanks for the post Daniel! Very helpful
Pingback:Quora
hi all, I am trying to install PySide on Python3.3 (CentOS) – have tried either pip install PySide or easyinstall-3.3 PySide but both fails with error message – Failed to find cmake. Please specify the path to cmake with –cmake parameter.
if i used yum, install seems to work but Python3.3 can’t detect it.
any advice? thank you!
Ok i gotten further. installed cmake via yum and that got me further.
however, now pyside fails install with error compiling shiboken – make: *** [all] Error 2
still googling trying to figure out whats wrong
Pingback:Python 2.7 and Python 3.3 on CentOS 6 Reliable Penguin - Blog
Great contribution. My CentOS box is now running Python 3.3.5. Thanks.
For 64 bit systems, add the line:
/usr/local/lib64
to /etc/ld.so.conf to make it look like the following.
include ld.so.conf.d/*.conf
/usr/local/lib
/usr/local/lib64
This solves the potential error of:
problem loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
Installed correctly.
When I run Python will work —> /usr/local/bin/python2.7
” Python 2.7.6 (default, Jun 6 2014, 11:02:54)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
”
More so when I run, does not work -> /usr/bin/python2.7
” -bash: /usr/bin/python2.7: No such file or directory ”
How do I run the 2 commands? For I have a server that works.
Help me please.
I had a hard time interpreting what you meant about whether or not to install unicode support. I would like to recommend that you change:
“Unless you have very specific reasons you should configure Python 3.2 and earlier to enable UTF-32 support.”
to
“Unless you have very specific reasons, you should configure Python 3.2 and earlier to enable UTF-32 support.”
I think the comma will make a mental pause that can help separate the if/then structure.
A straightforward review of that process (for Python 3.2.2!)…
—————————————————————————-
* Install Python 3.2.2 (CentOS 6.5):
[Ref.: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/%5D
————————–
– In order to compile Python you must first install the development tools and a few
extra libs. The extra libs are not strictly needed to compile Python but without
them your new Python interpreter will be quite useless
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
————————–
– Here are the commands to download, compile and install Python
wget http://python.org/ftp/python/3.2.2/Python-3.2.2.tar.xz –no-check-certificate
tar xf Python-3.2.2.tar.xz
cd Python-3.2.2
./configure –prefix=/usr/local –enable-shared LDFLAGS=”-Wl,-rpath /usr/local/lib”
make && sudo make altinstall
————————–
– After running the commands above your newly installed Python interpreter will
be available as /usr/local/bin/python3.2
/usr/local/bin/python3.2
————————–
– Download and install Setuptools + pip
cd ~/Downloads
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo /usr/local/bin/python3.2 ez_setup.py
sudo /usr/local/bin/easy_install-3.2 pip
————————–
– Create your isolated Python 3.2 environment
sudo /usr/local/bin/pip3.2 install virtualenv
sudo /usr/local/bin/virtualenv ~/virtenv3.2 (maybe /usr/local/bin/virtualenv-3.2)
cd ~/virtenv3.2
source bin/activate
python –version (To check version)
—————————————————————————-
Many thanks Daniel Eriksson! You awesome!
—————————————————————————-
https://github.com/eduardolucioac/groovim
GrooVim – Vi IMproved’n’GrooVIed!
I could not use matplotlib after I install python 2.7. All the other packages work well. And matplotlib works well with python 2.6 (the system default one). When I import gtk or import pygtk, it shows I don’t have those modules. Have any solution?
Python.org now forces https, and that wget command no longer works as-is:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
–2014-07-03 19:10:25– http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
Resolving python.org… 140.211.10.69
Connecting to python.org|140.211.10.69|:80… connected.
HTTP request sent, awaiting response… 301 Moved Permanently
Location: https://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz [following]
–2014-07-03 19:10:30– https://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
Connecting to python.org|140.211.10.69|:443… connected.
ERROR: certificate common name “*.python.org” doesn’t match requested host name “python.org”.
To connect to python.org insecurely, use ‘–no-check-certificate’.
Suggest adding “–no-check-certificate” to the instructions.
Pingback:Python, Flask, WSGI 설정 삽질 ㅠ on CentOS 6 | I'm Nova.
Great Post Extremely Helpful !!!!
Thanks
Cheryl
Instead of adding a line to /etc/ld.so.conf, I think it’s a better idea to create a separate .conf file into the /etc/ld.so.conf.d.
That would make possible to do it easier (with just one command), it can be done several times without worrying about duplicate lines and it’s more clean. For instance:
echo “/usr/local/lib” > /etc/ld.so.conf.d/python-alt.conf
And it’s also easier to revert:
rm /etc/ld.so.conf.d/python-alt.conf
Pingback:Linux tricks | Pearltrees
Thank you so very much!
Hi this looks like a perfect solution to my problem but for some reason when trying to extract either of the pre compiled downloads i get the following error :/
root@pancakes [~]# tar xf Python-2.7.6.tar.xz
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Archive contains obsolescent base-64 headers
tar: Read 6968 bytes from Python-2.7.6.tar.xz
tar: Error exit delayed from previous errors
Fixed, Just had an old version or tar.
Yes, new version of tar knows how to unpack both gzip, bzip2 and xz archives without having to pass it as a command line option.
Pingback:Installing Grunt on CentOS 5.10 | Josh's Blog
Hello All,
I’m new to python world and getting some error while installing python 2.7.6, please refer below for more details
Error Log :-
===============
checking whether the C compiler works… no
configure: error: in `/home/hadoop/hadoop/Python-3.3.5′:
configure: error: C compiler cannot create executables
—————————–
After saw the above error I had install C compilar and try again, but the result is same
command used for installation —> yum install compat-gcc-34-g77
Version information
==================
hostname = localhost.localdomain
uname -m = i686
uname -r = 2.6.32-358.el6.i686
uname -s = Linux
uname -v = #1 SMP Thu Feb 21 21:50:49 UTC 2013
/usr/bin/uname -p = unknown
/bin/uname -X = unknown
/bin/arch = i686
/usr/bin/arch -k = unknown
Please help me to solve this problem.
Thanks & Regards,
Satz.
How many comments?? Thanks for this. I used this to help me install Python 2.7 on and AWS instance as the new S3 tools need 2.7 and yum needs 2.6.
I am running into the following error while executing “python2.7 ez_setup.py”
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-6.1.zip
Traceback (most recent call last):
File “ez_setup.py”, line 332, in
sys.exit(main())
File “ez_setup.py”, line 327, in main
downloader_factory=options.downloader_factory,
File “ez_setup.py”, line 287, in download_setuptools
downloader(url, saveto)
File “ez_setup.py”, line 224, in download_file_wget
_clean_check(cmd, target)
File “ez_setup.py”, line 169, in _clean_check
subprocess.check_call(cmd)
File “/usr/local/lib/python2.7/subprocess.py”, line 504, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘wget’, ‘https://pypi.python.org/packages/source/s/setuptools/setuptools-6.1.zip’, ‘–quiet’, ‘–output-document’, ‘/root/setuptools-6.1.zip’]’ returned non-zero exit status 1
Any suggestions ?
Figured out the issue, apparently we need to pass –insecure option to the script at the time of execution:
python2.7 ez_setup.py –insecure
Thank you so much for this info. very useful!!
I followed your step to do a new python install in centos7 but ran into trouble at group install step and make step.
at the group install step:
No such command: Development tools. Please use /bin/yum –help
[chizzo@localhost ~]$ sudo yum groupinstall “Development Tools”
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirror.pac-12.org
* extras: centos.tcpdiag.net
* updates: mirrors.sonic.net
Warning: Group development does not have any packages to install.
Maybe run: yum groups mark install (see man yum)
No packages in any requested group available to install or update
I just moved on and ran the next command and it installed a bunch of stuff.
But then at the make step:
[chizzo@localhost Python-3.3.5]$ sudo make && make altinstall
[sudo] password for chizzo:
running build
running build_ext
running build_scripts
copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/pydoc3 -> build/scripts-3.3
copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/idle3 -> build/scripts-3.3
copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/2to3 -> build/scripts-3.3
copying and adjusting /home/chizzo/tmp/Python-3.3.5/Tools/scripts/pyvenv -> build/scripts-3.3
changing mode of build/scripts-3.3/pydoc3 from 644 to 755
changing mode of build/scripts-3.3/idle3 from 644 to 755
changing mode of build/scripts-3.3/2to3 from 644 to 755
changing mode of build/scripts-3.3/pyvenv from 644 to 755
renaming build/scripts-3.3/pydoc3 to build/scripts-3.3/pydoc3.3
renaming build/scripts-3.3/idle3 to build/scripts-3.3/idle3.3
renaming build/scripts-3.3/2to3 to build/scripts-3.3/2to3-3.3
renaming build/scripts-3.3/pyvenv to build/scripts-3.3/pyvenv-3.3
/usr/bin/install -c python /usr/local/bin/python3.3m
/usr/bin/install: cannot create regular file ‘/usr/local/bin/python3.3m’: Permission denied
make: *** [altbininstall] Error 1
[chizzo@localhost Python-3.3.5]
The contents of /usr/local/ do not show any install.
not sure what to do other than google around…
Running separate sudos seemed to work for me:
sudo make
sudo make altinstall
mc,
Did you ever resolve issue you mentioned above.
I would recommend running following as root instead of using sudo. That solved my issue…
sudo su
add ” /usr/local/lib ” to /etc/ld.so.conf
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
ldconfig
cd /home/chizzo/tmp/Python-3.3.5
./configure –prefix=/usr/local –enable-unicode=ucs4
make && make altinstall
Nice..! Helpful for the cent os new bee..
You deserves a lot of cookies and kudos. Thanks !
Pingback:Fix Ez_setup Syntax Error Windows XP, Vista, 7, 8 [Solved]
Pingback:Fix Python Ez_setup.py Error Windows XP, Vista, 7, 8 [Solved]
Pingback:Fix Blender Error Python Auto-execution Disabled Windows XP, Vista, 7, 8 [Solved]
Excellent howto! Thank you for sharing these easy steps to have more version of python running on the same box.
Pingback:How to get W3af 1.6 running on a CentOS 6.5 system with Python 2.7.6 | Tim Blog
To run pydoc with correct python version, I found this works:
/usr/local/bin/python2.7 -m pydoc
$ type pydoc
pydoc is aliased to `python -m pydoc’
So I guess could re-alias pydoc to use python2.7.
Pingback:Fix Configure Error Zlib Not Installed Centos Windows XP, Vista, 7, 8 [Solved]
Hi
Great stuff man!
I’m trying to run django in the virtualenv and that’s what I’m getting
Traceback (most recent call last):
File “manage.py”, line 8, in
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
any thoughts?
TIA
Pingback:Fix Ez Setup Py Error Windows XP, Vista, 7, 8 [Solved]
I followed instructions as listed. I choose second option for compiling Python as a shared library:
added ” /usr/local/lib ” to /etc/ld.so.conf
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
sudo ldconfig
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd ( to go to my home directory )
sudo mkdir Downloads
cd Downloads
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sudo wget http://python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz
sudo wget http://python.org/ftp/python/3.4.2/Python-3.4.2.tar.xz
tar xf Python-2.7.9.tar.xz
tar xf Python-3.4.2.tar.xz
ls -ld Python*
drwxr-xr-x 18 sgadmn sgadmn 4096 Dec 23 17:47 Python-2.7.9/
-rw-rw-r– 1 sgadmn sgadmn 12164712 Dec 10 09:08 Python-2.7.9.tar.xz
drwxr-xr-x 16 sgadmn sgadmn 4096 Dec 23 18:08 Python-3.4.2/
-rw-rw-r– 1 sgadmn sgadmn 14223804 Oct 8 01:25 Python-3.4.2.tar.xz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd Python-2.7.9
sudo ./configure –prefix=/usr/local –enable-unicode=ucs4
sudo make && make altinstall
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd ../Python-3.4.2
sudo ./configure –prefix=/usr/local –enable-unicode=ucs4
sudo make && make altinstall
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I got following error when running ” sudo make && make altinstall ”
Python build finished, but the necessary bits to build these modules were not found:
bsddb185 dl imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
running build_scripts
creating build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/pydoc -> build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/idle -> build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Tools/scripts/2to3 -> build/scripts-2.7
copying and adjusting /home/sgadmn/Downloads/Python-2.7.9/Lib/smtpd.py -> build/scripts-2.7
changing mode of build/scripts-2.7/pydoc from 644 to 755
changing mode of build/scripts-2.7/idle from 644 to 755
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
/usr/bin/install -c python /usr/local/bin/python2.7
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.7′: Permission denied
make: *** [altbininstall] Error 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So I went back and ran everything again as root:
sudo su
cd /home/my-homedir/Downloads/Python-2.7.9
./configure –prefix=/usr/local –enable-unicode=ucs4
make && make altinstall
cd /home/my-homedir/Downloads/Python-3.4.2
./configure –prefix=/usr/local –enable-unicode=ucs4
make && make altinstall
cd /usr/local/bin
ls -ld py*
-rwxr-xr-x 1 root root 84 Dec 23 17:16 pydoc*
-rwxr-xr-x 1 root root 84 Dec 23 18:09 pydoc3.4*
-rwxr-xr-x 1 root root 9760 Dec 23 17:47 python2.7*
-rwxr-xr-x 1 root root 1687 Dec 23 17:47 python2.7-config*
-rwxr-xr-x 2 root root 12618 Dec 23 18:08 python3.4*
-rwxr-xr-x 2 root root 12618 Dec 23 18:08 python3.4m*
-rwxr-xr-x 1 root root 3011 Dec 23 18:09 python3.4m-config*
-rwxr-xr-x 1 root root 236 Dec 23 18:09 pyvenv-3.4*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I got following errors when running python:
> python2.7
python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
> python3.4
python3.4: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ran following as root, not use sudo ldconfig to ensure /usr/local/lib path is recognized
ldconfig
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd /usr/local/bin
ldd python2.7
linux-vdso.so.1 => (0x00007fff9a151000)
libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x00007fb77d4d0000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb77d2b3000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb77d0ae000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007fb77ceab000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb77cc27000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb77c892000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb77d8bd000)
ldd python3.4
linux-vdso.so.1 => (0x00007fff799d9000)
libpython3.4m.so.1.0 => /usr/local/lib/libpython3.4m.so.1.0 (0x00007f2fa84a8000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2fa828b000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f2fa8086000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f2fa7e83000)
libm.so.6 => /lib64/libm.so.6 (0x00007f2fa7bff000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2fa786a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2fa895e000)
Both paths are now seen:
libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so.1.0 (0x00007fb77d4d0000)
libpython3.4m.so.1.0 => /usr/local/lib/libpython3.4m.so.1.0 (0x00007f2fa84a8000)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Everything working as expected:
python2.7
Python 2.7.9 (default, Dec 23 2014, 17:47:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
python3.4
Python 3.4.2 (default, Dec 23 2014, 18:07:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks Daniel Eriksson for creating this document.
Thanks everyone else for your posts.
-sg
+1 on cent 6.6
Pingback:How to install Python 3.4 on CentOS |
Thanks for the informative write up. I just installed python3.4 on my CentOS 6.4 server and your steps worked perfectly except I used newer versions of coarse.
Thanks, Again
thank you
Great explanation! Thank you Daniel…
Thanks a Lot it worked and saved me 2 days of digging on Centos 7.
Pingback:Amazon Linuxにpipをインストール(pip3は失敗でyumで環境作るのが良いらしい)-はじめてのAWS | kazsoga(曽我一弘)ブログ
This is how instructions should be. They are complete, they are precise, and they explain why I am going through all of these steps. They even talk about alternatives. Thanks, Daniel!
This is an extremely straightforward and easy to follow explanation. I’m a python newbie and I was up and running within minutes of reading this. It’s much appreciated. Thank you!
If LDFLAGS appears to be confusing ./configure as so:
configure: error: C compiler cannot create executables
See `config.log’ for more details
an alternate way to communicate the Python library path to the run-time linker worked for me:
./configure –prefix=/usr/local –enable-shared
LD_RUN_PATH=/usr/local/lib make
sudo make install
The LDFLAGS=’Wl,-rpath /usr/local/lib’ method given in the tutorial worked for me until very recently (though I had to create /usr/local/lib first, as pointed out in a page linked to in a comment above), but with a recent CentOS 6 update that stopped working
This was for Python-3.4.3 on CentOS 6.
Pingback:CentOS 6.5にPython 2.7をインストールしApacheで使用 | Akashic Records
hi daniel,
i got python2.7 installed on my fedora core 3 machine as alternative python using your doc
But i m still getting same error yum module is not present
System python version is still 2.3.4
please help
Thanks,
cedraj
Pingback:How to install Python 2.7 and Python 3.3 on CentOS 6 | 小狐濡尾
Pingback:Installation of python 2.7 on RHEL CentOS | millionzeros
Pingback:Setup of Development environment for Python 2.7 on Centos/Redhat 6 | ifconfigblog
I carefully followed the instructions and have a good install of the two versions 2.7.6 and 3.4.3 – and I installed. I chose not to edit the so.conf file. I can get the version of each using the python3.4 -V and python2.7 -V. I installed PIP and even then installed Django with a succesful install. I installed virtualenv without error, as in here:
pip2.7 install virtualenv
virtualenv-2.7 my27project
But when I type virtualenv-2.7 my27project I get that virtualenv-2.7 is not found. What do I do?
Also – pyenv-3.4 is not found and pyenv without the suffix is not found.
What can I do to correct these so I can test my django installation?
Thanks
For the my27project I ran into the same issue as you… try this :
virtualenv my27project
Note a typo in my comment – pyvenv-3.4 is found and works but I don’t know how to activate the django package I installed with pip3.4.
Made this work by using pyvenv-3.4 and activating the virtual environment before installing django. That’s all well and good. I do have one remaing question – when I want to publish and use my django application how do I apply this virtual environemnt so at runtime apache uses this virtual environemnt to find my python 3.4 and use that?
Pingback:给CentOS 6.5上的Python 2.6.6通过easy install安装argparse模块 | sw32技术博客
Pingback:零一积流 | 学习知识 分享经验 » CentOS上安装Django
Hi –
Is it fair to expect this instructions to work well on RHEL 6.x
Best
I did this first on Fedora22 then on Centos6.6 and it worked like a charm.
Probably, yes.
I’m a noob so I’ve been doing my fair share of install/reinstall lately , and now that I’ve come across this tutorial it won’t be because I broke Python the next time! This is excellent, thank you very much. Well explained, well guided, and complete. I changed a few things like 2.7.10 and 3.4.3 , and using dnf instead of yum, and it still went perfect.
In the Shared Library section, the line with LDFLAGS=”-Wl,-rpath /usr/local/lib” can be rendered to include a dash. For me it appeared as “LD- FLAGS=”. Copy in firefox actually puts the correct text into the clipboard, but that’s just confusing! Perhaps put it in a
block?
Editing ld.so.conf gives me nightmares.
Regarding another comment above, I'm not sure that setting LD_RUN_PATH= gets recorded in the compiled binary the way -rpath does.
The markup engine ate part of my comments: There was a newline in the middle of LDFLAGS, and I suggested putting the mis-rendered line in a “code block”.
That is strange. I tried viewing the article in both IE, Chrome and Firefox and for me it looks OK in all three. I have just updated the guide and completely removed the ldconfig instructions. Most people should probably compile the search path into the executable anyway, so no need to include an optional method here. I assume anyone that needs the path to not be hardcoded also knows how to properly set up ldconfig search paths.
I would add a step to ‘strip’ the shared library which makes it much smaller and matches the vendor implementation (at least RedHat). ie
strip /usr/local/lib/libpython2.7.so.1.0
Thank you for the suggestion. I have updated the guide to include instructions for stripping out the symbols.
Pingback:» Python:Install python 2.6 in CentOS
Thanks for posting this it has been extremely useful. Can any of the initial yum installs be safely removed once the compile is complete?
Pingback:Python:building Python from source with zlib support – IT Sprite
Pingback:Python:ImportError: No module named psycopg2 – IT Sprite
Pingback:Python:How to ignore local python when building python from source – IT Sprite
Pingback:Let’s Encrypt on VestaCP with CentOS 6 » Kodiak’s Korner - My Little Corner of the Net
Pingback:GStreamer编译 – 突围
This is a brilliant article. Very helpful.
Hi Daniel, Your blog was very helpful and I had followed these steps to install Django 1.7 inside a virtualenv (using Python 2.7.8) on CentOS 6.7. However, I recently tried to upgrade Django to version 1.8.8 using pip2.7 install –upgrade django==1.8.8 and consistently hit a segmentation fault after the package is downloaded. Any ideas as to what might be going wrong?
Pingback:python套件 pbh5tools: PacBio rawdata 格式轉換 | Gene
Pingback:Linux系统:Python2.6和Python2.7同时存在 | Gene
Useful instructions that are still being used. Thanks!
Pingback:Use Vagrant to Manage an OEL6 Virtual Machine | Connor Johnson
Thanks Daniel! This is very useful and detail explanation. It saves me a lot of time.
Thank you, it works for py2.7.11 & py3.5.1 on CentOS Minimal 6.6. Well, except that py3.5.1 ships with
setuptools
andpip
already.Here are the last few lines of
sudo make && sudo make altinstall
(of py3.5.1) ‘s output:……
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-7.1.2 setuptools-18.2
You are absolutely right. I have now updated the guide to use get-pip.py script that installs/upgrades pip, setuptools and wheel.
Pingback:Centos 6.4 安装 Python 2.7 | 勇气
setuptools has moved:
Setuptools can now be found at https://github.com/pypa/setuptools
So the URL needs updating.
I have now updated the guide to use get-pip.py script that installs/upgrades pip, setuptools and wheel.
Pingback:CENTOS 6.5 安装 Python 2.7 总结 – 赵浮云的blog
Daniel, thank you for such great guide … well explained and all commands worked as expected. Not like other guides out there that only half the commands work. The only issue I found is the location of the ez_install.py file which is in another location on bitbucket. But everything else worked perfectly !!! I wish there was a guide like this to install QIIME on a Centos based HPC.
I have now updated the guide to use get-pip.py script that installs/upgrades pip, setuptools and wheel.
Pingback:CENTOS 6.5 安装 Python 2.7 总结 – 赵浮云的blog-
Pingback:centos 6x install the Python | 我心依旧
THANK YOU SO SO SO MUCH!!
BY THE WAY, THE LINK FOR WGET SETTOOLS SHOULD BE “https://bootstrap.pypa.io/ez_setup.py”, WHICH IS SHOWN ON THE PYTHON OFFICAL WEBSITE. AND IT WORKS.
THANK YOU!! I was stuck here
I have now updated the guide to use get-pip.py script that installs/upgrades pip, setuptools and wheel.
Excellent write-up. You saved my day! Thanks a lot
Excellent work ,Pretty easy to understand,,Thanks a lot…
Note: setuptools has moved from bitbucket to github, so the link in the article
“wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py”
needs to be updated to
“wget https://github.com/pypa/setuptools/raw/bootstrap/ez_setup.py“
I have now updated the guide to use get-pip.py script that installs/upgrades pip, setuptools and wheel.
How can I get the python2.7-devel package after I successfully installed python2.7 as you described
Is there a way to install using yum?
Yes, there are third party repos that provides binary packages.
Wonderful site. Plenty of useful info here. I’m sending it to several pals ans also sharing in delicious. And naturally, thank you for your effort!
Thank you so much Daniel. I cannot express my gratitude enough.
in get-pip.py there is a script mentioned.
tasks/generate.py
Do you know where that can be found?
I assume it is this: https://github.com/pypa/get-pip/blob/master/tasks/generate.py
Upon installation and executing python2.7, I got the following error
“error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory”
during –configure, I tried giving in -Wl and -rpath options but got errors so skipped those and just did LDFLAGS -L/……/lib
Most likely this is the source of this error. How to get around it?
Just few notes,
1. the lib.so file is present at the /xxx/yyy/lib location
2. Error I got with -Wl, -rpath xxx/yyy/lib option – “C compiler cannot create executables”
If you compile Python to use a shared library then you also need to tell it how to find the shared library. You do that either by adding proper LDFLAGS to the configure command, or by adding the lib folder to the ld.so.conf file.
Are you running the commands as root (or with sudo)?
I updated the CentOS 6.5 to 6.8. ‘Yum’ is worked fine in CentOS 6.5. After update it shows following error.
yum
‘import site’ failed; use -v for traceback
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It’s possible that the above module doesn’t match the
current version of Python, which is:
2.6.6 (r266:84292, Aug 18 2016, 14:53:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
#!/usr/bin/python is not working for me.
I read your post above and tried to install python 2.7. but i cant use yum as you said in “Preparations – install prerequisites”
Please help me to fix this………… Thanks in Advance
Thank you very much for your guide.
It has solved my problem.
Dan – this an awesome work. For the first time, I had to deal with a custom Python installation on RHEL v7.2. I followed these steps and accomplished the setup. Thanks for this.
-Ravi Itha
I have very serious question. The Lego Cassette-Desk on the top — is it your creation. It’s absolutely wonderful. The accuracy! Even holes in the tape!
It is one of the models included in this box: https://www.lego.com/en-us/classic/products/creative-building-set-10702
My 5-year old daughter built it with a little help from me.
Hey Daniel, thanks for sharing this! And also big thanks for staying with your comments and do some enhancements to the original post – very appreciated; not many people care so much for what was published a while ago already.
I have one question:
In you article, you warn about to not try to install Python 2.7 on CentOS 7, since it might break the system.
I do not see a reason this should happen following your instructions, since the default Python should not be changed. Could you please share and specify in what kind of issues you ran?
Thanks a lot!
My fear is that you will end up with multiple executables called “python2.7” in your path, each having a different set of installed packages. Depending on the order of your path you might get strange behaviour. At least that is why I put the warning in there. I have no firm evidence that it will actually break the system, that is why I prefixed my assertion with “might”.
Also, if you follow my suggestions you will use /usr/local as the prefix, which means that the new python executables will be in /usr/local/bin that by default is part of a users path. If you use a different prefix then the risk of problems will be much lower.
One way to completely remove the risk of problems is by building and installing Python 2.7.13 as a regular user, with your home directory as the prefix, or even “/home/[username]/Python-2.7.13” as the prefix. Presumably you want to use a virtualenv, and as soon as you have created that you no longer need easy access to the original python executable. This is how I personally run python for a couple of Django websites that I manage. The drawback is that you cannot compile python as a shared executable (at least I don’t know how to do that).
Python 3.6.1 came out. This is is the first maintenance release of Python 3.6. The download URL is:
https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
Thank you for the great tutorial.
Thank you for the reminder! I have now updated the examples with 3.6.1.
Your tutorial works fine with 3.6.1!
If i did install Python 2.7.12 previously using the option … LDFLAGS=”-Wl,-rpath /usr/local/lib”, won’t i have a problem if i want to install Python 3.6.1 using the same parameter as mentioned in this blog? Does it mean that i need to specify LDFLAGS=”-Wl,-rpath /usr/local/Python3.6/lib” instead to prevent a conflict of more than 1 python sharing the same /usr/local/lib ?
It is perfectly safe to have both Python 2 and Python 3 share the same /usr/local/lib location for their shared library. The shared library does not have the same name. Good luck!
Thanx a lot Daniel. Helped a lot.
Glad I found this.
Daniel, would you possibly add an instruction to install virtualenvwrapper for 2.7.x and to use it?
I think installation went well but I can make the following working:
$export PROJECT_HOME=~/dev
$export WORKON_HOME=~/envs
$ source /usr/local/bin/virtualenvwrapper.sh (this part is throwing errors. It seems like it is confused with the system installed python2.7.5.
This is the error message:
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
I don’t use virtualenvwrapper myself, but did you try setting VIRTUALENVWRAPPER_PYTHON to your custom python executable?
Maybe something like this:
$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
Daniel, It worked! For those who want to use virtualenvwrapper, I will leave what I did. I assume that you have virtualenv installed using pip2.7 on CentOS 6.
$pip2.7 install virtualenvwrapper
$export PROJECT_HOME=~/dev
$export WORKON_HOME=~/envs
$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
$ source /usr/local/bin/virtualenvwrapper.sh
Here is the link to the How-to guide about using Virtual Environments:
http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/
Thank you again for the wonderful guide.
The above link for using Virtual Environment is dead. Here is a better resource for it:
http://docs.python-guide.org/en/latest/dev/virtualenvs/
Here is a standalone chef recipe that can be called to handles the install 3.6.1 on centos6 to /usr/local/python – in case anybody wants to automate this –python_alt_install.rb – i left your comments in.
1 # This installs python 3.6 in an alt location so as not to break yum
2
3 # Install Compilers and related tools:
4 execute ‘yum groupinstall -y “development tools”‘ do
5 command ‘yum groupinstall -y “development tools –disableexcludes=all”‘
6 end
7
8 # Install Libraries needed during compilation to enable all features of Python:
9 %w{zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel}.each do |pkg|
10 package pkg do
11 action :install
12 end
13 end
14
15 #create the install dir for python 3.6
16 directory ‘/usr/local/python/lib’ do
17 owner ‘root’
18 group ‘root’
19 mode ‘0755’
20 recursive true
21 action :create
22 end
23
24 # Install Python 3.6.1 to /usr/local/python
25 bash ‘install-python3.6.1’ do
26 user ‘root’
27 cwd ‘/opt’
28 code <<-EOH
29 wget http://python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
30 tar xf Python-3.6.1.tar.xz
31 cd Python-3.6.1
32 ./configure –prefix=/usr/local/python –enable-shared LDFLAGS="-Wl,-rpath /usr/local/python/lib"
33 make && make altinstall
34 EOH
35 not_if { ::File::exists?("/opt/Python-3.6.1.tar.xz")}
36 end
37
38 # strip symbols after install from the shared library to reduce the memory footprint
39 execute 'strip-symbols' do
40 command 'strip /usr/local/python/lib/libpython3.6m.so.1.0'
41 end
42
43 #Install/upgrade pip, setuptools and wheel
44 bash 'Install-Setup-tools' do
45 user 'root'
46 cwd '/opt'
47 code <<-EOH
48 wget https://bootstrap.pypa.io/get-pip.py
49 python3.6 get-pip.py
50 EOH
51 not_if { ::File::exists?("/opt/get-pip.py")}
52 end
added a section for roots bash profile – since we manage that in chef
1 # This installs python 3.6 in an alt location so as not to break the yum
2
3 # Install Compilers and related tools:
4 execute ‘yum groupinstall -y “development tools”‘ do
5 command ‘yum groupinstall -y “development tools –disableexcludes=all”‘
6 end
7
8 # Install Libraries needed during compilation to enable all features of Python:
9 %w{zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel}.each do |pkg|
10 package pkg do
11 action :install
12 end
13 end
14
15 #create the install dir for python 3.6
16 directory ‘/usr/local/python/lib’ do
17 owner ‘root’
18 group ‘root’
19 mode ‘0755’
20 recursive true
21 action :create
22 end
23
24 # Install Python 3.6.1 to /usr/local/python
25 bash ‘install-python3.6.1’ do
26 user ‘root’
27 cwd ‘/opt’
28 code <<-EOH
29 wget http://python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
30 tar xf Python-3.6.1.tar.xz
31 cd Python-3.6.1
32 ./configure –prefix=/usr/local/python –enable-shared LDFLAGS="-Wl,-rpath /usr/local/python/lib"
33 make && make altinstall
34 EOH
35 not_if { ::File::exists?("/opt/Python-3.6.1.tar.xz")}
36 end
37
38 #Bash_profile needs the new path – chef prefers to manage whole files
39
40 cookbook_file '/root/.bash_profile' do
41 source 'root_bash_profile'
42 action :create
43 end
44
45 # strip symbols after install from the shared library to reduce the memory footprint
46 execute 'strip-symbols' do
47 command 'strip /usr/local/python/lib/libpython3.6m.so.1.0'
48 end
49
50 #Install/upgrade pip, setuptools and wheel
51 bash 'Install-Setup-tools' do
52 user 'root'
53 cwd '/opt'
54 code <<-EOH
55 wget https://bootstrap.pypa.io/get-pip.py
56 python3.6 get-pip.py
57 EOH
58 not_if { ::File::exists?("/opt/get-pip.py")}
59 end
Great job in automating this! How can you run this? Sorry for the novice question.
I followed the instructions for Python 2.7 in CentOs 6.9 (Final)
Dependencies and python 2.7 , make && make altinstall, and the files were created, but I cannot use it!?
Error: python2.7:command not found
—-cmd line—–
[root@mail Python-2.7.13]# ls -l /usr/local/bin/py*
-rwxr-xr-x 1 root root 84 Jun 29 21:20 /usr/local/bin/pydoc
-rwxr-xr-x 1 root root 9784 Jun 29 21:27 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root 1687 Jun 29 21:28 /usr/local/bin/python2.7-config
[root@mail Python-2.7.13]# python2.7 get-pip.py
-bash: python2.7: command not found
Do you have /usr/local/bin in your PATH?
Dear Daniel
I installed Python 2.7.13 on CentOS 6.9 as following your guide above. but when I type the command “$ Python -V” it is still the previous version of 2.6 which does not support the program I want to install using “pip” command. how can I replace the old version of Python with the new installed?
thanks
Please read the guide again. It clearly states that you cannot replace the default python version.
Pingback:PyNSXv-Powerful tool for NSX Automation – Virtual Reality
Thanks so much for posting this and keeping it updated! Love the detail. It’s helped me a ton!
I installed the version 2.7.5 but I don’t find the file “python2.7”. I don’t understand.
Can you help me ?
Did you follow the instructions?
Worked like a charm… excellent reference. Much appreciated that you took the time to write this up. Thank you!
I have problem with django (only on centos).
Pervious version of python in centos 7: 2.7.5
I did everything in the instruction – step by step.
After “source my27project/bin/activate” : 2.7.13 (There is 2.7.14, but I checked for 2.7.14).
Django work for me fine on ubuntu environment, but not on centos.
Even after activating (source my27project …) and do pip install django – same thing.
What I mean about not working:
In browser (Even firewall is setting fine):
192.168.0.10 refused to connect.
Search Google for 192 168 8000
ERR_CONNECTION_REFUSED
====
(Other programs work with no problem – it’s not firewall problem. Also work in ubuntu fine – I see the default page of django web site. The only problem is on centos7).
The installation process for django:
pip2.7 install django (after activating 2.7.13)
python django-admin.py startproject hello
cd hello
python manage.py migrate
python manage.py runserver
(There is 2.7.14, but I checked for … 2.7.13)
Your local LAN IP address (192.168.0.10) is not the same as the loopback address that Django uses (127.0.0.1).
What happens if you connect to http://127.0.0.1:8000
Thanks for letting me know there is a new Python version out. I’ll update the text as soon as I have some spare time.
Thank you.
I need to access from another computer in the farm.
The localhost (127.0.0.1) is equivalent to 192.168.0.1 – How can I change that?
Thanks.
Read the Django docs.
As to why it works in Ubuntu but not in CentOS I have no idea. The Django development server usually only responds on the loopback interface, but you can change that in settings.py. Don’t remember the variably name off the top of my head.
Hello,
I am using the python as server side, where client side is angular4.
For some reason I got the message:
CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
As I investigate this issue, I need to install the django-cors-headers, as in
https://github.com/ottoyiu/django-cors-headers/
The steps:
I create my project on virtual environment, also implemented rest by:
pip install virtualenv
virtualenv myproject
cd myproject
source bin/activate
and in virtual enviornment:
pip install djangorestframework
pip install django-cors-headers
in settings.py:
INSTALLED_APPS = [
…
‘rest_framework’,
‘companies’,
‘corsheaders’,
]
REST_FRAMEWORK = {
‘DEFAULT_PERMISSION_CLASSES’: [
‘rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly’
]
}
MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10
…
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
…
]
CORS_ORIGIN_ALLOW_ALL=TRUE
All of above done (I don't know why in python it's too complicated, and need several pip installations, but let it be. REST-FULL in C# windows is much simple. Even I can do tricky with apache for Access-Control-Allow-Origin, just add the header by print command in python before sent to client:
print "Access-Control-Allow-Origin: *"
).
Here is my view code:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from .models import PartObject
from .serializers import PartSerializer
class PartList(APIView):
def get(self, request):
parts = PartObject.objects.all()
serializer = PartSerializer(parts, many=True)
response = Response(serializer.data)
# response.headers['Access-Control-Allow-Origin'] = '*' — this doesn't work
return response
# return Response(serializer.data)
def post(self):
pass # pass: do nothing
What may be wrong and how can I pass a header?
I have tried your instructions, but after starting /usr/local/bin/python2.7, python starts up and reports Python 2.7.13, which is the pre-installed python version in Tumbleweed.
The python version that I compiled and installed with make altinstall was 2.7.14.
What did I do wrong?
What is Tumbleweed? Also, I explicitly warn against installing 2.7.14 on a machine that already has an older version of 2.7.
Hi,
nice tutorial. However, why not use the method proposed at https://stackoverflow.com/questions/23215535/how-to-install-python27-devel-on-centos-6-5
i.e.
# yum update
# yum install centos-release-SCL
# yum install python27
and additionnally you can get the devel package which is useful !!
# yum install python27-python-devel.x86_64
That is absolutely an option!
thx worked nicely !
I performed the steps and they worked great and I have an available python2.7 in my /usr/bin folder.
A problem I’m having is that there are missing system python libs. For instance…
[vagrant@localhost ~]$ python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import yum
>>>
This works fine, but if I use python2.7
[vagrant@localhost ~]$ python2.7
Python 2.7.14 (default, Nov 1 2017, 19:16:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import yum
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named yum
>>>
My understanding is that there are additional system level modules that are handled by the distribution. I was wondering if you can provide any guidance on how to find and get these compiled in as well?
Perfect instructions, thanks!
Hello… I have a question.
I am trying to install Odoo 11 which requires Python 3.5+. By following your instructions, I installed Python 3.6. Then, I have activated my36project environment. When I did it, I verified that the Python version is correct, so I used the Odoo RPM to try to install it, however, a lot of dependencies are missing. I don’t want my CentOS 6.9 system to get corrupted, so, how can I install these dependencies only for Python 3.6? I tried using PIP3.6 but it did not work. I hope you can advice what to do next.
Thanks a lot in advance.
These are the missing dependencies:
babel is needed by odoo-11.0.post20171108-1.noarch
libxslt-python is needed by odoo-11.0.post20171108-1.noarch
nodejs-less is needed by odoo-11.0.post20171108-1.noarch
pychart is needed by odoo-11.0.post20171108-1.noarch
pyparsing is needed by odoo-11.0.post20171108-1.noarch
python(abi) = 3.6 is needed by odoo-11.0.post20171108-1.noarch
python3-PyPDF2 is needed by odoo-11.0.post20171108-1.noarch
python3-PyYAML is needed by odoo-11.0.post20171108-1.noarch
python3-babel is needed by odoo-11.0.post20171108-1.noarch
python3-dateutil is needed by odoo-11.0.post20171108-1.noarch
python3-decorator is needed by odoo-11.0.post20171108-1.noarch
python3-docutils is needed by odoo-11.0.post20171108-1.noarch
python3-feedparser is needed by odoo-11.0.post20171108-1.noarch
python3-gevent is needed by odoo-11.0.post20171108-1.noarch
python3-greenlet is needed by odoo-11.0.post20171108-1.noarch
python3-html2text is needed by odoo-11.0.post20171108-1.noarch
python3-jinja2 is needed by odoo-11.0.post20171108-1.noarch
python3-lxml is needed by odoo-11.0.post20171108-1.noarch
python3-mako is needed by odoo-11.0.post20171108-1.noarch
python3-markupsafe is needed by odoo-11.0.post20171108-1.noarch
python3-mock is needed by odoo-11.0.post20171108-1.noarch
python3-num2words is needed by odoo-11.0.post20171108-1.noarch
python3-ofxparse is needed by odoo-11.0.post20171108-1.noarch
python3-passlib is needed by odoo-11.0.post20171108-1.noarch
python3-pillow is needed by odoo-11.0.post20171108-1.noarch
python3-psutil is needed by odoo-11.0.post20171108-1.noarch
python3-psycopg2 is needed by odoo-11.0.post20171108-1.noarch
python3-pydot is needed by odoo-11.0.post20171108-1.noarch
python3-pyldap is needed by odoo-11.0.post20171108-1.noarch
python3-pyparsing is needed by odoo-11.0.post20171108-1.noarch
python3-pyserial is needed by odoo-11.0.post20171108-1.noarch
python3-pytz is needed by odoo-11.0.post20171108-1.noarch
python3-pyusb is needed by odoo-11.0.post20171108-1.noarch
python3-qrcode is needed by odoo-11.0.post20171108-1.noarch
python3-reportlab is needed by odoo-11.0.post20171108-1.noarch
python3-requests is needed by odoo-11.0.post20171108-1.noarch
python3-six is needed by odoo-11.0.post20171108-1.noarch
python3-stdnum is needed by odoo-11.0.post20171108-1.noarch
python3-suds is needed by odoo-11.0.post20171108-1.noarch
python3-vatnumber is needed by odoo-11.0.post20171108-1.noarch
python3-vobject is needed by odoo-11.0.post20171108-1.noarch
python3-werkzeug is needed by odoo-11.0.post20171108-1.noarch
python3-xlrd is needed by odoo-11.0.post20171108-1.noarch
python3-xlwt is needed by odoo-11.0.post20171108-1.noarch
I don’t have any good suggestions for how to solve this.
You say that using pip3.6 did not work. What did not work?
PS! If you are using a sandbox then you need to run Odoo from inside it also.
Pingback:升级python而不会破坏yum | CODE问答
Hello.. thanks for your reply.
Before installing odoo, I run:
# source my36project/bin/activate
# python –version
With last command, I can realize that I am in python 3.6 sandbox.
Then I run:
# rpm -ivh odoo_11.0.latest.noarch.rpm
After that, a report of a lot of dependencies are displayed.
First one is called “babel”. I don’t know what is it, however, I tried to install it using pip3.6, this way, without leaving 3.6 sandbox:
# pip3.6 install babel
After that, this response is shown:
Requirement already satisfied: babel in ./my36project/lib/python3.6/site-packages
Requirement already satisfied: pytz>=0a in ./my36project/lib/python3.6/site-packages (from babel)
however, Odoo RPM is still not detetecting even when I am inside the sandbox.
I proceed the same way with all dependencies, and pip3.6 shows that packages are installed successfully, but ODOO does not recognize.
Maybe I need to install dependencies outside of 3.6 sandbox? I don’t want to do it without knowing because I can corrupt the system.
Unfortunately I don’t think you will have much success installing Odoo on CentOS 6.9. I don’t think you will be able to get rpm to install the dependencies in the right location even if you are inside the sandbox (and outside the sandbox you will have even less of a chance I guess).
I’m afraid I cannot help you with this.
Great article. By far the best I’ve found so far. Two suggestions/requests:
1. Add “–enable-optimizations” to the list of recommended ./configure arguments.
2. Can you elaborate a bit on installing an updated Python2.7 with CentOS 7? I’m trying to do it because I need SNI support (new in 2.7.9, but CentOS7 default is 2.7.5). Your comment reply here: https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/#comment-532 gets me 80% of the way there, but I’m uncertain about the consequences of “cannot compile python as a shared executable”. Is that the same as the “Shared Library” section in the article? will it prevent use with mod_wsgi?
1. Are you sure that it is safe even for the old toolchain in CentOS 6.9? Even if it is safe I don’t think I want to include it by default, but I could certainly add it as a suggestion in the text.
2. You are right that shared executable is the same as shared library in this case. Sloppy use of words on my part. I don’t think it will give you problems with mod_wsgi, but I don’t have time to try it out so I cannot make any promises. What you might end up with is higher memory usage if you run multiple instances.
Really nice, it’s just working. Awesome!
I’ve been looking around for this information for a while and these instructions are great, but maybe you don’t need this?
The article below was posted 17th of Dec 2015. Odd it hasn’t caught on. Maybe I am missing something? I’ve followed it and yum is functional after upgrading to Python 3.4
https://lists.centos.org/pipermail/centos-announce/2015-December/021555.html
That is absolutely an option. See comment 872 above for an alternative link to a guide on how to do that: https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/#comment-872
Hello Daniel,
I previously installed Python version 2.7.9 on a Centos system using something similar to your method. So I have both python 2.6 and 2.7 on the system working fine. What would I do to update the 2.7.9 python to 2.7.14. If I used yum, that would update the 2.6.6 version which I don’t want to do.
Thx
If you installed it in its own folder it is trivial – just delete the folder. This would be the case if you set prefix to /usr/local/Python-2.7.9 or something similar.
If you used /usr/local as prefix (like in my article) the process of removing it becomes a little harder. I searched the net for instructions and found this article that I think does a good job of explaining it:
https://unix.stackexchange.com/questions/190794/uninstall-python-installed-by-compiling-source
I need to update the article for Python 3.6.4 that was just released, so I will consider adding a link to that article in a paragraph about uninstalling.
Pingback:More recent Python in Enterprise Linux like CentOS and RHEL - Marc Richter's personal site
It can’t be clearer than this. Thanks for the info.
Hi:Daniel
Thank your great post.
everything goes well, but I suck on the step “Install/upgrade pip, setuptools and wheel”.
my current python is 2.75, willing to 3.6.3
———–
# python2.7 get-pip.py
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
# python3.6 get-pip.py
bash: python3.6: command not found
————–
Pingback:Adding Route 53 records using Terraform | geekdudes
Excellent !
Pingback:compile and install python 2.7.14 from source on CentOS 7 – CSJ's b!og
GREAT!!! Thanks so much for details!!!
thank you!
THANKS ¡¡¡¡¡¡
Hi Daniel,
Thanks for help.
I ran your commands in Cloudera to upgrade python2.6.6 to 2.7
I stuck with the error with install pandas as not able to install pandas with 2.6.6
[cloudera@quickstart Desktop]$ pip2.7 install pandas
/usr/local/bin/pip2.7: line 4: import: command not found
/usr/local/bin/pip2.7: line 5: import: command not found
/usr/local/bin/pip2.7: line 7: from: command not found
/usr/local/bin/pip2.7: line 10: syntax error near unexpected token
('
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$’, ”, sys.argv[0])’/usr/local/bin/pip2.7: line 10:
Pingback:CentOS Administration | Ernani.me
Hi,
thanks for help! It works with current version of python 2.7.15, also. Only one question:
Can I delete the folder created by unpacking with this command tar xf Python-2.7.15.tar.xz or is it still needed?
I’m new to it and don’t want to destroy it.
Thanks a lot
Johannes
It is perfectly safe to delete that folder.
Pingback:Python3をソースからインストール – 春の日の日差しのように
Hi Daniel , thanks, really good post!
非常感谢
Great Workflow.
Even though, I have sudo rights, I receive permission denied (see below). I can create files in /usr/local/bin.
Thank you soo much
>sudo make && make altinstall
….
if test
uname -s
= Darwin; then \cp python-config.py python-config; \
fi
if test “no-framework” = “no-framework” ; then \
/bin/install -c python /usr/local/bin/python3.6m; \
else \
/bin/install -c -s Mac/pythonw /usr/local/bin/python3.6m; \
fi
/bin/install: cannot create regular file ‘/usr/local/bin/python3.6m’: Permission denied
make: *** [altbininstall] Error 1
If you execute “sudo make && make altinstall” only the first command (make) will be executed with root privs. Try “sudo make && sudo make altinstall” instead.
Thank you very much. A bit embarrassing, I did not find the solution myself.
THANK YOU !!!
Thank you for taking the time to put this information it was very helpful and saved me a lot of time!!!
Hi Daniel…
I’m facing issue with my yum server. Yum is not working on my server , I had tried to rebuild the rpm package but does not work for me. Please help me out how to fix this issue ..??
See the below error which I’m getting
# yum update
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named sqlite
Please install a package which provides this module, or
verify that the module is installed correctly.
It’s possible that the above module doesn’t match the
current version of Python, which is:
2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
# python -V
Python 2.6.6
Anaconda is a very good alternative for CentOS — it is an environment that’s completely contained in a certain directory. Miniconda is a smaller distribution of Anaconda that’s also easy to install.
Hi Daniel;
Thanks for the excellent info. Just a quick update for Python 3.7.1 on CentOS7.
There’s one extra package needed to compile it:
sudo yum install libffi-devel
Thank you for the information! I will make sure to include that information next time I edit the article.
Hello,
I get the following errors:
[root@host1 ~]# python3.7 get-pip.py
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pip
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/pip/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/pip/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/pip/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/pip/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) – skipping
Could not find a version that satisfies the requirement pip (from versions: )
No matching distribution found for pip
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) – skipping
Thank you, it worked great!
Pingback:TERRAFORM – Jagadish Goswami
Worked great installing Python 3.6. Thank you very much!
Thanks a lot it works perfectly, good job !
Thanks a ton. Saved a lot of time 🙂
Gracias por aportar tu experiencia y conocimientos, funciona muy bien .
Saludos
Thank you for contributing your experience and knowledge, it works very well.
regards
Thanks Daniel.
I followed the steps as mentioned.
One problem I faced ‘Error _ctypes……..’
So I installed libffi-devel
Then no error and worked like a charm.
Thanks again.
But there is a problem. when I need a package which should use yum to install, like python-qt4. but now when I use my new python on centos, I could not import it.
Hi,
I’m installing python 2.7.16 on /home/user/python without sudo privileges
it works fine except for an issue with sqlite3
I also get “no module name _sqlite3” when trying to import sqlite3
If I use the default python2.7 (2.7.4), I am able to import sqlite3. Is this an indication that
sqlite-devel
was installed ?I’ve added to the ./configure the options: –with-sqlite3 –enable-loadable-sqlite3-extensions
but this does not seams to be helping
any suggestions?
The error is:
>>> import sqlite3
Traceback (most recent call last):
File “”, line 1, in
File “/home/user/python/Python-2.7.16/lib/python2.7/sqlite3/__init__.py”, line 24, in
from dbapi2 import *
File “/home/user/python/Python-2.7.16/lib/python2.7/sqlite3/dbapi2.py”, line 28, in
from _sqlite3 import *
ImportError: No module named _sqlite3
this :
yum install sqlite-devel
did help
Thanks
(base) [root@localhost etc]# yum -h
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
/lib64/librt.so.1: symbol __pthread_get_minstack, version GLIBC_PRIVATE not defined in file libpthread.so.0 with link time reference
Please install a package which provides this module, or
verify that the module is installed correctly.
It’s possible that the above module doesn’t match the
current version of Python, which is:
2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
To compile Pyhton 7.* on Centos 7 there is a need for an additional library.
The errror: ModuleNotFoundError: No module named ‘_ctypes’ can be resolved by bringing in libffi-devel.
# yum install -y libffi-devel
Thanks to Victor Stinner, who helped me out.
Pingback:Upgrade python without breaking yum – Config9.com
Yes, If we are using CentOS 6 we can use this tutorial to install both Python 2.7.x and Python 3.6.x.
I was advised to uninstall versions of python. How do I uninstall them, is there a command to do this? So I recommend the same
Your blog is a blessing. Very well explained and very through. I am not a python developer and I was sick all the errors. Your blog really helped me with my first python installation. Thank you very much.
Great article, thanks for your help
If you do this on Centos8 with gcc8, you will need this patch from https://github.com/python/cpython/commit/0b91f8a668201fc58fa732b8acc496caedfdbae0.patch, otherwise the build will fail. See https://bugs.python.org/issue33374
Just apply that patch before running the
configure
step.Pingback:「Python」- 安装(CentOS) – k4nz.com – K4NZ.COM
finally something that worked!
Hello, Daniel:
Wanted to let you know how helpful your post has been. I am a Compliance/Reliability engineer at Nokia. We have a variety of Linux servers CentOS, Fedora, openSUSE, PCLinuxOS, Debian, Mandriva, Ubuntu, and others) each on a different, and older version of python. Most are no more recent than 2.6.6. Many of these servers were used for other non-python things in a previous life, and were recommissioned, wiped clean, with a bare-bones version of Linux installed with whatever version of python that was available with the original product, and in varying degrees of operation/partial installation as people have tried to get a new version python installed that will run our tools. As part of our work, we needed a way for users to be able to upgrade their versions of python using a procedure that would be reasonably easy for employees of various levels of Linux experience, and at the same time would work across a wide variety of servers. Your post has enabled us to generate training that allows users to create a python environment that will operate our tools and applications, and in doing so, bring these servers back into useful service. Thank you for taking the time to put this information together. Very much appreciated! We have included a link to your page in our training. One last thing; I have not seen a recent posts… have you moved your website to a different location? If so, please pass the new link on to me.
Hello Daniel,
I have a Centos 6 .10 final version .
I try to install Python 3.6.3 us You described but in the end of installation I have these error messages :
Collecting setuptools
Exception:
Traceback (most recent call last):
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py”, line 324, in run
requirement_set.prepare_files(finder)
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py”, line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py”, line 554, in _prepare_file
require_hashes
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py”, line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/index.py”, line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/index.py”, line 386, in find_all_candidates
self.find_links, expand_dir=True)
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/index.py”, line 236, in _sort_locations
sort_path(os.path.join(path, item))
File “/tmp/tmp6rz9gfw0/pip-9.0.1-py2.py3-none-any.whl/pip/index.py”, line 217, in sort_path
if mimetypes.guess_type(url, strict=False)[0] == ‘text/html’:
File “/usr/Python-3.6.3/Lib/mimetypes.py”, line 290, in guess_type
init()
File “/usr/Python-3.6.3/Lib/mimetypes.py”, line 355, in init
db.read(file)
File “/usr/Python-3.6.3/Lib/mimetypes.py”, line 205, in read
self.readfp(fp, strict)
File “/usr/Python-3.6.3/Lib/mimetypes.py”, line 216, in readfp
line = fp.readline()
File “/usr/Python-3.6.3/Lib/codecs.py”, line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa2 in position 198: invalid start byte
Please help me to resolve this problem .
Pingback:Server Bug Fix: Error when trying install mod_wsgi using pip - TECHPRPR
Thanks to you we solved it well.
Pingback:Upgrade python without breaking yum - iZZiSwift
Pingback:CentOS 7 Python 2.7 Upgrade Deprecation Message - End Of Life January 1st, 2020 - CentminMod Blog
You are an amazing guy,You did the trick for me.Really helpful.
Thanks a Lot
Pingback:「Python」- 安装(CentOS、Debian、Ubuntu、源码) - K4NZ BLOG
Pingback:Upgrade python without breaking yum
Pingback:Upgrade python without breaking yum - PhotoLens
Gonna have to comment and say this blog helped immensely in getting me to a solution – thanks Daniel!
Pingback:Upgrade python without breaking yum – w3toppers.com
Pingback:Upgrade python without breaking yum – Row Coding