host python/java to run script within singularity image

208 views
Skip to first unread message

M Noon

unread,
Jun 7, 2018, 7:45:49 PM6/7/18
to singularity
Hi Vanessa, 

It is obvious that we can install a specific version of python inside an image and use that to run a script within or on host system e.g.

singularity exec test.simg python somescript.py                 ## where somescript.py could be located inside this very image or somewhere on the host system

but I am wondering if there is any way of using host system python or java to run a script within the image??

e.g. 

java -jar singularity exec test.simg /scripts/somescript.jar

or 

python singularity exec test.simg /scripts/somescript.py

is it somehow possible??

Regards,
Muhammad

v

unread,
Jun 7, 2018, 10:37:54 PM6/7/18
to singu...@lbl.gov
Hey Muhammad,

The pythons that are available to you are the ones that the container can see. This is based on finding the executable called "python" on your $PATH. So if your container binds a path on your host (somewhere in $HOME) where python is installed, you can run that python from the container. If you don't bind a location (for example, /opt/python on your host) then you cannot use it. Once you have "hit" a particular executable, the modules are then found based on the $PYTHONPATH. So, if you want to do this:

java -jar singularity exec test.simg /scripts/somescript.jar

What (I think) you really want to do is execute the command to the container using some java within the container, or on the host? Remember, if the path on the host with java is not see-able by the container, or if the container doesn't have its own java, this won't work.

singularity exec test.simg java -jar /scripts/somescript.jar

If you have java on the host AND container then you likely want to be sure you are hitting the right one:

singularity exec test.simg which java

The same goes for python. You need to execute the command to the container to run python, python executing a singularity container doesn't make sense.

singularity exec test.simg python /scripts/somescript.py
singularity exec test.simg which python

Does the help?

Best,

Vanessa







--
You received this message because you are subscribed to the Google Groups "singularity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to singularity+unsubscribe@lbl.gov.



--
Vanessa Villamia Sochat
Stanford University '16

Rémy Dernat

unread,
Jun 8, 2018, 6:10:53 AM6/8/18
to singu...@lbl.gov
Hi,

You can use linux pipe to transfer result between host and your singularity container; eg: singularity exec test.simg cat /scripts/somescript.py | python3.5

Kind regards,
Rémy

To unsubscribe from this group and stop receiving emails from it, send an email to singularity...@lbl.gov.



--
Vanessa Villamia Sochat
Stanford University '16
Reply all
Reply to author
Forward
0 new messages