Python with docker rootproject/root-ubuntu16

Same as (an issue)[ROOT docker with python support?] but as far as I can tell hasn’t been solved. I’ve tried both with the latest tag and the snapshot

The container has root and python installed such that the following commands work fine:

$ docker run -it rootproject/root-ubuntu16 bash
$ root -b
$ python

but…

$docker run -it rootproject/root-ubuntu16 bash
$ python
>>> import ROOT

gives the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ROOT 

if I first run source /usr/local/bin/thisroot.sh then this all goes away but this suggests that the python path hasn’t been set correctly in the installation.

###############################################

for completeness I’d like to run simple examples like

$ cat Dockerfile
FROM rootproject/root-ubuntu16
USER root
RUN mkdir /code
ADD generate.py /code
WORKDIR /code

Such that inside this container the generate.py script (which is just some simple pyroot examples) can be run without any other setups needed.

1 Like

Hi,

If you start the container normally, some things are already setup for you. If you start with bash by hand, you will have to setup PYTHONPATH yourself:

$ docker run --rm -it rootproject/root-ubuntu16 bash
builder@c2b75ef54d23:/$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ROOT
>>> [Ctrl-d]
builder@c2b75ef54d23:/$ export PYTHONPATH=/usr/local/lib/root
builder@c2b75ef54d23:/$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> 
builder@c2b75ef54d23:/$

Would it make sense to put source /usr/local/bin/thisroot.sh in the docker user’s .bashrc?

Hi Guilherme,
Could this not be set using the ENV variable when building the image?

As pointed out before there are several possible workarounds but ideally this should form the base image for more complex projects rather than just restrict people to the ‘normal’ running. In this case I’d much prefer to have all of the variables set before continuing.

Thanks,
~/Vince

Hi Enrico,
Wouldn’t this then screw up if you try to log in with different users. E.g. in the docker file I give above I change to root in order to make a code directory and in the base examples on the dockerhub page it tells you to log in using the --user $(id -u) tag…

I could be wrong but wouldn’t any of these options negate the usefulness of the .bashrc fix.

Also as pointed out in that dockerfile. I don’t necessarily want to run bash but python (as in the previous thread about this) with pyROOT doesn’t seem to work out of the box in this image.

Thanks!
~/Vince

Yes of course it would only work for the default user. Otherwise there’s always /etc/rc.local. But if setting docker environment variables works just as well and is more robust why not :smile:

Yes, I will set it up on the environment when I get the chance.

2 Likes

Thanks that would be great. Please keep me updated so I can update my examples!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.