[英]Unable to run python script during Jenkins build
The problem: 问题:
I have a Jenkins build step that executes a shell script. 我有一个执行Shell脚本的Jenkins构建步骤。 This script in turn calls a python script which is performing some cryptographic functions.
该脚本依次调用执行某些加密功能的python脚本。 However when the build executes, I am getting the following error.
但是,当执行生成时,出现以下错误。
Traceback (most recent call last):
File "./xyz.py", line 4, in <module>
import rsa
ImportError: No module named 'rsa'
The Jenkins' node has two versions of python - 2.7 (default) and 3.4 and rsa
is installed for both of them. Jenkins的节点具有两个版本的python-2.7(默认)和3.4,并且为两个版本都安装了
rsa
。 I even ran the script (using version 3.4) on the slave itself and it worked fine. 我什至在从属服务器本身上运行了脚本(使用3.4版),并且运行良好。
What I have done so far: 到目前为止,我所做的是:
I am using EnvInject plugin to point PYTHONPATH
to correct location. 我正在使用EnvInject插件将
PYTHONPATH
指向正确的位置。 Without it, I found that PYTHONPATH
was undefined. 没有它,我发现
PYTHONPATH
是未定义的。
Using default version, my script starts with: #!/usr/bin/env python
使用默认版本,我的脚本以以下代码开头:
#!/usr/bin/env python
Jenkins output: 詹金斯的输出:
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
PYTHONPATH=/usr/local/lib/python2.7
[EnvInject] - Variables injected successfully.
[demo] $ /bin/sh -xe /tmp/hudson9217742060700174209.sh
+ export PYTHONPATH=/jenkins/workspace/demo:/usr/local/lib/python2.7
+ echo /jenkins/workspace/demo:/usr/local/lib/python2.7
/jenkins/workspace/demo:/usr/local/lib/python2.7
+ ./abc.sh
/usr/bin/env: python: No such file or directory
The Shebang in this case is #!/usr/bin/env python3
在这种情况下,Shebang是
#!/usr/bin/env python3
Jenkins output: 詹金斯的输出:
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
PYTHONPATH=/usr/local/lib/python3.4/
[EnvInject] - Variables injected successfully.
[demo] $ /bin/sh -xe /tmp/hudson4592372533933414288.sh
+ export PYTHONPATH=/jenkins/workspace/demo:/usr/local/lib/python3.4/
+ echo /jenkins/workspace/demo:/usr/local/lib/python3.4/
/jenkins/workspace/demo:/usr/local/lib/python3.4/
+ ./abc.sh
Traceback (most recent call last):
File "./xyz.py", line 4, in <module>
import rsa
ImportError: No module named 'rsa'
I even tried doing sys.path.append(os.environ['/usr/local/lib/python3.4/dist-packages/rsa'])
in the script itself, but the problem persists. 我什至尝试在脚本本身中执行
sys.path.append(os.environ['/usr/local/lib/python3.4/dist-packages/rsa'])
,但问题仍然存在。
Can anyone help me with this issue? 谁能帮我解决这个问题? Thanks.
谢谢。
PS- My knowledge of Python is very limited. PS-我对Python的了解非常有限。
As far as I can remember it, I had similar problems with my Python-script and I finally solved it by using 据我所记得,我的Python脚本也有类似的问题,最后我通过使用
python xyz.py
instead of 代替
./xyz.py
Unfortunately I can not explain why it works in this way, but not the other, but in my case it solved the problem. 不幸的是,我无法解释为什么它会以这种方式起作用,而不能以其他方式解释,但就我而言,它可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.