Jenkins Python Job

66 views
Skip to first unread message

Mahryama issifu

unread,
Aug 10, 2023, 11:45:48 AM8/10/23
to jenkins...@googlegroups.com
Hi All,

I have a job running on Jenkins server, which builds python script. The script has to display a bar chart as final output.
The build agent I am using on Jenkins appears to have python installed. I confirmed this by adding a build step as python3 —version and the result was: Python 3.6.8.

Why then do I have this error showing. Do I need to install a plugin? 

Kind regards 
Mari





Traceback (most recent call last)
File "newjenkins.py", line 7, in <module>
import matplotlib.pyplot as plt
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 97, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCAnvasGTK, \
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 13, in <module>
import gtk, gdk = gtk.gdk
File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
_init()
File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
_gtk.init_check()
RuntimeError: could not open display

Mark Waite

unread,
Aug 10, 2023, 11:50:20 AM8/10/23
to Jenkins Users
That output indicates that the program is choosing to run Python 2 packages (like gtk) with Python 3.  You probably need Python 3 packages to run with Python 3.6.8. 

Installing a plugin won't help.  Python 2 reached end of life in 2020, per https://www.python.org/doc/sunset-python-2/

Mahryama issifu

unread,
Aug 10, 2023, 5:35:54 PM8/10/23
to jenkins...@googlegroups.com

Hi Mark
I have checked the Jenkins build agent I am using, and it as python3.6.8 installed. I don’t understand why the program is choosing python 2 packages. Do I have to check which python version or path is being used by the build agent. 

I made some changes to my codes: before importing ‘matplotlib.pyplot’ I set the ‘marplotlib’ backend to non interractive one, such as ‘Agg’.
Like this: 
import matplotlib
matplotlib.use('Agg') # This line should be before importing pyplot
import matplotlib.pyplot as plt

I then proceeded to build on jenkins and that worked out. 

However, there is a new error code on Jenkins again.
image0.jpeg

Kind regards 
Mari

--
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/74a3b800-028f-47ce-b915-086046be13ecn%40googlegroups.com.

Mark Waite

unread,
Aug 10, 2023, 5:50:52 PM8/10/23
to Jenkins Users
On Thursday, August 10, 2023 at 3:35:54 PM UTC-6 Mari wrote:

Hi Mark
I have checked the Jenkins build agent I am using, and it as python3.6.8 installed. I don’t understand why the program is choosing python 2 packages. Do I have to check which python version or path is being used by the build agent. 

I made some changes to my codes: before importing ‘matplotlib.pyplot’ I set the ‘marplotlib’ backend to non interractive one, such as ‘Agg’.
Like this: 
import matplotlib
matplotlib.use('Agg') # This line should be before importing pyplot
import matplotlib.pyplot as plt

I then proceeded to build on jenkins and that worked out. 

However, there is a new error code on Jenkins again.
image0.jpeg


That's not a Jenkins error.  That's a configuration error on your agent.  If you login on that agent as the same user that is running the Jenkins agent, you'll see the same message.

The operating system on that agent is configured to provide Python 2 libraries from the system directories (/usr/lib64/python2.7) but is executing Python 3 code.  You'll need to fix the operating system configuration on the agent.

Talk to your local experts that understand how your chosen operating system is configured.  Remote debugging of an operating system configuration error will be too painful and slow for you.

Mark Waite
 

Mahryama issifu

unread,
Aug 11, 2023, 3:59:00 AM8/11/23
to jenkins...@googlegroups.com
Thank you Mark. 
That was very helpful

BW
Mari

On 10 Aug 2023, at 22:50, Mark Waite <mark.ea...@gmail.com> wrote:

On Thursday, August 10, 2023 at 3:35:54 PM UTC-6 Mari wrote:

Hi Mark
I have checked the Jenkins build agent I am using, and it as python3.6.8 installed. I don’t understand why the program is choosing python 2 packages. Do I have to check which python version or path is being used by the build agent. 

I made some changes to my codes: before importing ‘matplotlib.pyplot’ I set the ‘marplotlib’ backend to non interractive one, such as ‘Agg’.
Like this: 
import matplotlib
matplotlib.use('Agg') # This line should be before importing pyplot
import matplotlib.pyplot as plt

I then proceeded to build on jenkins and that worked out. 

However, there is a new error code on Jenkins again.
<image0.jpeg>


That's not a Jenkins error.  That's a configuration error on your agent.  If you login on that agent as the same user that is running the Jenkins agent, you'll see the same message.

The operating system on that agent is configured to provide Python 2 libraries from the system directories (/usr/lib64/python2.7) but is executing Python 3 code.  You'll need to fix the operating system configuration on the agent.

Talk to your local experts that understand how your chosen operating system is configured.  Remote debugging of an operating system configuration error will be too painful and slow for you.

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.
Reply all
Reply to author
Forward
0 new messages