ImportError No module named Image in Jenkins

2,457 views
Skip to first unread message

Cherry Tsai

unread,
May 23, 2016, 1:43:55 AM5/23/16
to Jenkins Users

Hi guys,


I had python trouble. I want to compare two images using python in Jenkins.

When I added "import Image" or "from PIL import Image" in my script, it will show error message "ImportError: No module named Image".

But use "import os, time", it was working.



Basic environment:

  1. use docker official jenkins

  2. python 2.7

  3. PYTHONPATH is /usr/lib/python2.7/dist-packages/PIL
    /usr/lib/python2.7/dist-packages/PIL

  4. Sys.path is ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']


Please help me how to solve it?


Mark Waite

unread,
May 23, 2016, 8:35:44 AM5/23/16
to Jenkins Users
I would guess that the official Jenkins docker image does not include the Python imaging library by default.  You probably need to install the python imaging library by adding an entry to your Dockerfile:

RUN apt-get update && apt-get install -y python-imaging


Mark Waite


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/83a816a4-d55d-42ad-8e09-84657d85b4a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cherry Tsai

unread,
May 24, 2016, 6:25:21 PM5/24/16
to Jenkins Users
Must be use Dockerfile install? I used manually install in Jenkins container.

I tried to run command in Jenkins container:

$ python
$
from PIL import Image

It's working for me.

Then I checked Python2.7 path, it has PIL and Image folder in /usr/local/lib/python2.7.

But only Jenkins couldn't use Python PIL and Image. I'm very confused.

Mark Waite

unread,
May 24, 2016, 6:47:08 PM5/24/16
to Jenkins Users
Your results seem different from mine.  The commands I executed:

$ docker run -i --rm -p 8080:8080 -p 50000:50000 jenkins /bin/bash
python
print 1 + 1
print 2 + 2
from PIL import Image
^D
2
4
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
ImportError: No module named PIL

As far as I can tell, that means the PIL module is not available in the docker image named "jenkins".

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Cherry Tsai

unread,
Jun 9, 2016, 3:07:22 AM6/9/16
to Jenkins Users
Hi Mark,

I found the other solution. First, I install "Python Plugin" in Jenkins platform. And I can write the script in Jenkins configuration -> Execute Python script.


Now I can use Python package "Image", compare two images.
Reply all
Reply to author
Forward
0 new messages