bugSavannah Static web pages of project:

bugbugs #98486: -->How to configure ROOT to use python 3 on Ubuntu?

Submitted by:  Christoph Deil <cdeil>
Submitted on:  2012-10-26 12:56
Bug / Feature:  * Feature request Category:  Build system
Priority:  5 - Normal Severity:  3 - Normal
Status:  None Privacy:  Public
Assigned to:  Open/Closed:  Open
Release:  *5.34Discussion Lock:  Unlocked
Operating System:  * All
Summary:  *How to configure ROOT to use python 3 on Ubuntu?
* Mandatory Fields

2012-12-04 21:32, comment #5:

I think ROOT 5 will be in use with many experiments for several years, so if ROOT 5.34 can be made more Python 3 compatible easily, I think it's worth it.

Most of the issues that show up with Python 3 are simple to fix in a way that should be compatible with Python 2.5, I think.
The quickest way would be to run one of the autopep8 tools and then check with Python 2.5 and 3.2 before committing.

I did not try this myself yet, maybe you know that some real issue would come up that I am not aware of?
Let me know if you don't have time for this and I'll give it a shot and send patches.



2012-12-04 18:39, comment #4:


how important is it to get genreflex fixed, given that it's going to be gone soon in ROOT6?

For the tutorials and others, I think p2.5 must still be supported, which does not have p3 features in _future_ yet. I'll see what can be done, but can't promise anything.

I'll have a look at what can be done for modding the configure script as suggested.


Wim Lavrijsen <wlav>In charge of this item.

2012-11-05 14:33, comment #3:

About half of the python examples in tutorials/pyroot as well as tmva/test/TMVAClassification.py don't run.
I think it's all trivial stuff like using print("something") instead print "something", so it's trivial to make the examples python2 and 3 compatible at the same time.
Wim, can you fix those or would it help if I attach patches?

Also on Mac at the very end of the make build there are some Python TabError and SyntaxErrors in genreflex:

Install roots wrapper.
bin/rmkdepend -R -fmain/src/h2root.d -Y -w 1000 -- -m64 -pipe -Wshadow -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -Iinclude -pthread -D__cplusplus -- /Users/deil/software/root/root/main/src/h2root.cxx
clang++ -O2 -m64 -pipe -Wshadow -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -Iinclude -pthread -o main/src/h2root.o -c /Users/deil/software/root/root/main/src/h2root.cxx
clang++ -O2 -m64 -mmacosx-version-min=10.8 -o bin/h2root main/src/h2root.o \
-Llib -lRIO -lHist -lGraf -lGraf3d -lGpad -lTree -lMatrix -lNet -lThread -lMathCore -lCore -lCint lib/libminicern.so \
/opt/local/lib/gcc47/gcc/x86_64-apple-darwin12/4.7.2/../../../libgfortran.dylib /opt/local/lib/gcc47/gcc/x86_64-apple-darwin12/4.7.2/../../../libgfortran.a /opt/local/lib/gcc47/gcc/x86_64-apple-darwin12/4.7.2/libgfortranbegin.a -lm -Wl,-rpath,@loader_path/../lib -lpthread -ldl
gfortran -O2 -m64 -std=legacy -o main/src/g2root.o -c /Users/deil/software/root/root/main/src/g2root.f 2>&1 | sed -e s/arning:/arn-Ignore:/ >&2

call toreals(3,pmixt,creals,ncr)
Warn-Ignore: Actual argument contains too few elements for dummy argument 'r' (3/200) at (1)

call toreals(-npar0,dummypars(1),creals,ncr)
Warn-Ignore: Actual argument contains too few elements for dummy argument 'r' (100/200) at (1)

call toreals(npar0,qjv(7),creals,ncr)
Warn-Ignore: Actual argument contains too few elements for dummy argument 'r' (94/200) at (1)
gfortran -O2 -m64 -mmacosx-version-min=10.8 -o bin/g2root main/src/g2root.o \
-Llib lib/libminicern.so \
/opt/local/lib/gcc47/gcc/x86_64-apple-darwin12/4.7.2/../../../libgfortran.dylib /opt/local/lib/gcc47/gcc/x86_64-apple-darwin12/4.7.2/../../../libgfortran.a /opt/local/lib/gcc47/gcc/x86_64-apple-darwin12/4.7.2/libgfortranbegin.a -lm -Wl,-rpath,@loader_path/../lib -lpthread -ldl
cp /Users/deil/software/root/root/cint/reflex/python/genreflex/gccdemangler.py lib/python/genreflex/gccdemangler.py
File "lib/python/genreflex/gccdemangler.py", line 210
if debug : print 'demangle_mangled_name ', name[:50]
SyntaxError: invalid syntax

cp /Users/deil/software/root/root/cint/reflex/python/genreflex/gencapa.py lib/python/genreflex/gencapa.py
cp /Users/deil/software/root/root/cint/reflex/python/genreflex/gendict.py lib/python/genreflex/gendict.py
Sorry: TabError: inconsistent use of tabs and spaces in indentation (gendict.py, line 248)
cp /Users/deil/software/root/root/cint/reflex/python/genreflex/genheader.py lib/python/genreflex/genheader.py
File "lib/python/genreflex/genheader.py", line 18
if id[-1] == u'c' :
SyntaxError: invalid syntax

cp /Users/deil/software/root/root/cint/reflex/python/genreflex/genreflex-rootcint.py lib/python/genreflex/genreflex-rootcint.py
File "lib/python/genreflex/genreflex-rootcint.py", line 55
except getopt.GetoptError, e:
SyntaxError: invalid syntax

cp /Users/deil/software/root/root/cint/reflex/python/genreflex/genreflex.py lib/python/genreflex/genreflex.py
File "lib/python/genreflex/genreflex.py", line 34
print 'Usage:'
SyntaxError: invalid syntax

cp /Users/deil/software/root/root/cint/reflex/python/genreflex/genrootmap.py lib/python/genreflex/genrootmap.py
cp /Users/deil/software/root/root/cint/reflex/python/genreflex/selclass.py lib/python/genreflex/selclass.py
File "lib/python/genreflex/selclass.py", line 52
except xml.parsers.expat.ExpatError, e :
SyntaxError: invalid syntax


2012-11-05 14:06, comment #2:

Hi Wim,

this works, thanks for the tip!

I saw that the cmake build has a PYTHON_EXECUTABLE option:

Would it be possible to add a --with-python-executable to the configure & make build matching the cmake build option?

I think there's more and more systems that have python2 and python3 installed and more and more scientific python analysis moves on to python3, so having a simple way to select the PYTHON_EXECUTABLE instead of having to know about an undocumented hack to create a symlink and add it to PATH would be useful.


2012-10-26 18:27, comment #1:


don't relink python3 in /usr/bin, just add a symlink to it somewhere local, such as in $ROOTSYS/bin as you're going to add that to PATH anyway for use of root.

Then it should all work (does for me, anyway).


Wim Lavrijsen <wlav>In charge of this item.

2012-10-26 12:56, original submission:

I would like to use PyROOT with python 3.2, but I can't figure out how to configure the ROOT build for python 3.

travis@ubuntu:~/build/v5-34-03$ ./configure --with-python-incdir=/usr/include/python3.2mu --with-python-libdir=/usr/lib/python3.2/config-3.2mu | grep python
Checking for Python.h ... /usr/include/python3.2mu
Checking for python2.7, libpython2.7, libpython, python, or Python ... no

travis@ubuntu:~/build/v5-34-03$ which python

travis@ubuntu:~/build/v5-34-03$ ls -lh /usr/bin/python*
lrwxrwxrwx 1 root root 18 Oct 26 03:29 /usr/bin/python -> /usr/bin/python2.7
lrwxrwxrwx 1 root root 9 Oct 25 11:23 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 2.7M Jul 31 22:46 /usr/bin/python2.7
-rwxr-xr-x 1 root root 1.7K Jul 31 22:45 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root 16 Apr 17 2012 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 Apr 14 2012 /usr/bin/python3 -> python3.2
lrwxrwxrwx 1 root root 11 Oct 19 13:15 /usr/bin/python3.2 -> python3.2mu
lrwxrwxrwx 1 root root 18 Oct 19 13:15 /usr/bin/python3.2-config -> python3.2mu-config
-rwxr-xr-x 1 root root 2.7M Oct 19 13:15 /usr/bin/python3.2mu
-rwxr-xr-x 1 root root 1.8K Oct 19 13:13 /usr/bin/python3.2mu-config
lrwxrwxrwx 1 root root 16 Apr 14 2012 /usr/bin/python3-config -> python3.2-config
lrwxrwxrwx 1 root root 11 Apr 14 2012 /usr/bin/python3mu -> python3.2mu
lrwxrwxrwx 1 root root 18 Apr 14 2012 /usr/bin/python3mu-config -> python3.2mu-config
lrwxrwxrwx 1 root root 16 Apr 17 2012 /usr/bin/python-config -> python2.7-config

I think the problem is that the first python on the PATH is used by configure (2.7 in my case) and I have no way to tell it to use another python?

Symlinking /usr/bin/python to /usr/bin/python3.2 doesn't work, it gives this error:

travis@ubuntu:~/build/v5-34-03$ sudo ln -sf /usr/bin/python3.2 /usr/bin/python

travis@ubuntu:~/build/v5-34-03$ ./configure
Checking for source directory ... /home/travis/build/v5-34-03
Configuring for linux
File "/usr/bin/lsb_release", line 67
print ':'.join(verinfo)
SyntaxError: invalid syntax
File "/usr/bin/lsb_release", line 67
print ':'.join(verinfo)
SyntaxError: invalid syntax
File "/usr/bin/lsb_release", line 67
print ':'.join(verinfo)
SyntaxError: invalid syntax
Checking for GNU Make version >= 3.80 ... ok
Checking for C compiler ... gcc
Checking for C++ compiler ... g++
Checking for linker (LD) ... g++
Checking for F77 compiler ... no F77 compiler gfortran found
Checking for libX11 ... no
configure: libX11 MUST be installed
See http://root.cern.ch/drupal/content/...

Christoph Deil <cdeil>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • Wim Lavrijsen <wlav> added by (wlav) (Posted a comment)
  • Philippe Canal <pcanal> added by (pcanal) (Updated the item)
  • Christoph Deil <cdeil> added by (cdeil) (Submitted the item)

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    2012-10-26 12:57pcanalAssigned toNone=>wlav
    Show feedback again

    Back to the top