【发布时间】:2015-02-16 22:02:00
【问题描述】:
问题:
我有一个执行 shell 脚本的 Jenkins 构建步骤。该脚本依次调用执行一些加密功能的 python 脚本。但是,当构建执行时,我收到以下错误。
Traceback (most recent call last):
File "./xyz.py", line 4, in <module>
import rsa
ImportError: No module named 'rsa'
Jenkins 的节点有两个版本的 python - 2.7(默认)和 3.4,并为它们安装了rsa。我什至在从站本身上运行了脚本(使用 3.4 版),它运行良好。
到目前为止我做了什么:
我正在使用 EnvInject 插件将PYTHONPATH 指向正确的位置。没有它,我发现PYTHONPATH 是未定义的。
- 使用 Python 2.7
使用默认版本,我的脚本开头为:#!/usr/bin/env python
詹金斯输出:
[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
- 使用 Python 3.4
本例中的Shebang是#!/usr/bin/env python3
詹金斯输出:
[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'
我什至尝试在脚本本身中执行sys.path.append(os.environ['/usr/local/lib/python3.4/dist-packages/rsa']),但问题仍然存在。
谁能帮我解决这个问题?谢谢。
P.S.- 我对 Python 的了解非常有限。
【问题讨论】: