Reputation: 3365
I have a python program, which should run in Jenkins job
. But I got below error:
Started by user admin
Building in workspace /var/lib/jenkins/workspace/automatic_test
[automatic_test] $ /bin/sh -xe /tmp/jenkins257763233971180370.sh
+ cd /ext/data/nlu_test/ifly/job123
+ python3 bleu.py Zh ref_zh.txt translation_zh.txt
Traceback (most recent call last):
File "bleu.py", line 5, in <module>
import jieba
ImportError: No module named 'jieba'
Build step 'Execute shell' marked build as failure
Finished: FAILURE
While I run the same commands on Linux shell
, then it runs normally as below. Why?
[jenkins@localhost ~]$ cd /ext/data/nlu_test/ifly/job123
[jenkins@localhost job123]$ ls
bleu.py input.orig.txt input.trans.txt input.txt ref_zh.txt splitText.py translation_zh.txt
[jenkins@localhost job123]$ python3 bleu.py Zh ref_zh.txt translation_zh.txt
W0310 00:06:37.430938 295363 init.cc:157] AVX is available, Please re-compile on local machine
Paddle enabled successfully......
reference 1: 3615
candidate: 3493
score: 31.8288254543782
[jenkins@localhost job123]$
And I installed the python package jieba
already as below.
[root@localhost ~]# pip3 install jieba
Requirement already satisfied: jieba in /usr/local/lib/python3.7/site-packages (0.42.1)
[root@localhost ~]# pip install jieba
Requirement already satisfied: jieba in /usr/local/lib/python3.7/site-packages (0.42.1)
Upvotes: 1
Views: 152
Reputation: 2157
You should check how your Jenkins agent is set up. Usually, Jenkins agents run under a separate user ID than the one you are using. This means that they use different environments than the one where you are doing your testing. In your example, your python script fails to import a package. You should see if this package exists and is available in the the environment used by the Jenkins agent.
Upvotes: 1
Reputation: 663
You can use absolute path of Python for executing the script in Jenkins.
Example: /usr/bin/python3 bleu.py Zh ref_zh.txt translation_zh.txt
Upvotes: 1