我正在尝试使用python与jenkins进行交互。
最初,当我尝试import jenkinsapi
时,我收到了以下错误。
>>> import jenkinsapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/jenkinsapi-0.3.4/jenkinsapi/__init__.py", line 49, in <module>
from jenkinsapi import (
File "/root/jenkinsapi-0.3.4/jenkinsapi/api.py", line 15, in <module>
from jenkinsapi.jenkins import Jenkins
File "/root/jenkinsapi-0.3.4/jenkinsapi/jenkins.py", line 12, in <module>
from jenkinsapi.jobs import Jobs
File "/root/jenkinsapi-0.3.4/jenkinsapi/jobs.py", line 6, in <module>
from jenkinsapi.job import Job
File "/root/jenkinsapi-0.3.4/jenkinsapi/job.py", line 10, in <module>
from jenkinsapi.build import Build
File "/root/jenkinsapi-0.3.4/jenkinsapi/build.py", line 17, in <module>
import pytz
ImportError: No module named 'pytz'
然后我安装了pytz
。
# yum install python34-pytz.noarch -y
Loaded plugins: product-id, rhnplugin, search-disabled-repos, subscription-manager
This system is receiving updates from RHN Classic or Red Hat Satellite.
Resolving Dependencies
--> Running transaction check
---> Package python34-pytz.noarch 0:2016.7-1.el7 will be installed
--> Processing Dependency: python(abi) = 3.4 for package: python34-pytz-2016.7-1.el7.noarch
--> Running transaction check
---> Package python34.x86_64 0:3.4.5-3.el7 will be installed
--> Processing Dependency: python34-libs(x86-64) = 3.4.5-3.el7 for package: python34-3.4.5-3.el7.x86_64
--> Processing Dependency: libpython3.4m.so.1.0()(64bit) for package: python34-3.4.5-3.el7.x86_64
--> Running transaction check
---> Package python34-libs.x86_64 0:3.4.5-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
python34-pytz noarch 2016.7-1.el7 epel 46 k
Installing for dependencies:
python34 x86_64 3.4.5-3.el7 epel 50 k
python34-libs x86_64 3.4.5-3.el7 epel 6.7 M
Transaction Summary
==============================================================================================================================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 6.8 M
Installed size: 28 M
Downloading packages:
(1/3): python34-3.4.5-3.el7.x86_64.rpm | 50 kB 00:00:00
(2/3): python34-pytz-2016.7-1.el7.noarch.rpm | 46 kB 00:00:00
(3/3): python34-libs-3.4.5-3.el7.x86_64.rpm | 6.7 MB 00:00:01
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 4.2 MB/s | 6.8 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python34-3.4.5-3.el7.x86_64 1/3
Installing : python34-libs-3.4.5-3.el7.x86_64 2/3
Installing : python34-pytz-2016.7-1.el7.noarch 3/3
Verifying : python34-pytz-2016.7-1.el7.noarch 1/3
Verifying : python34-libs-3.4.5-3.el7.x86_64 2/3
Verifying : python34-3.4.5-3.el7.x86_64 3/3
Installed:
python34-pytz.noarch 0:2016.7-1.el7
Dependency Installed:
python34.x86_64 0:3.4.5-3.el7 python34-libs.x86_64 0:3.4.5-3.el7
Complete!
这导致成功导入jenkinsapi
root@dselilx6390 ~/jenkinsapi-0.3.4
# python3.4
Python 3.4.5 (default, Nov 9 2016, 16:24:59)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jenkinsapi
>>>
我能够做很多工作然后退出python CLI。然后我重新登录并尝试import jenkinsapi
然后获得了错误。
>>> import jenkinsapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'jenkinsapi'
突然间,它给了我一个ImportError: No module named 'jenkinsapi'
错误。我没有安装任何软件包或修改任何东西。什么可能出错?
答案 0 :(得分:0)
目前的问题是,当您能够导入Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\System32>pip install PyAutoGUI-0.9.35
Collecting PyAutoGUI-0.9.35
Could not find a version that satisfies the requirement PyAutoGUI-0.9.35 (from
versions: )
No matching distribution found for PyAutoGUI-0.9.35
C:\Windows\System32>pip install pyautogui==0.9.35
Collecting pyautogui==0.9.35
Downloading PyAutoGUI-0.9.35.zip (57kB)
100% |################################| 61kB 223kB/s
Collecting pymsgbox (from pyautogui==0.9.35)
Downloading PyMsgBox-1.0.6.zip
Collecting PyTweening>=1.0.1 (from pyautogui==0.9.35)
Downloading PyTweening-1.0.3.zip
Requirement already satisfied: Pillow in c:\python35\lib\site-packages (from pya
utogui==0.9.35)
Collecting pyscreeze (from pyautogui==0.9.35)
Downloading PyScreeze-0.1.9.tar.gz
Requirement already satisfied: olefile in c:\python35\lib\site-packages (from Pi
llow->pyautogui==0.9.35)
Building wheels for collected packages: pyautogui, pymsgbox, PyTweening, pyscree
ze
Running setup.py bdist_wheel for pyautogui ... done
Stored in directory: C:\Users\me\AppData\Local\pip\Cache\wheels\28\
3b\07\64bee61ca73d56260a47d6b49692e7f217a69568aae2117167
Running setup.py bdist_wheel for pymsgbox ... done
Stored in directory: C:\Users\me\AppData\Local\pip\Cache\wheels\c1\
cb\86\c3c2e3c39f9f0d015cf0f94ab6ca41e14f8c2083846e82b91d
Running setup.py bdist_wheel for PyTweening ... done
Stored in directory: C:\Users\me\AppData\Local\pip\Cache\wheels\04\
86\59\70a93cd378740b5266c51e11c36ee3fc8b9dfef4b3bc72fd82
Running setup.py bdist_wheel for pyscreeze ... done
Stored in directory: C:\Users\me\AppData\Local\pip\Cache\wheels\6a\
f7\db\9521ae30a53499f6c9024df5f5a605d56b6e6ad0c2d48dcb42
Successfully built pyautogui pymsgbox PyTweening pyscreeze
Installing collected packages: pymsgbox, PyTweening, pyscreeze, pyautogui
Successfully installed PyTweening-1.0.3 pyautogui-0.9.35 pymsgbox-1.0.6 pyscreez
e-0.1.9
C:\Windows\System32>
时,您的工作目录为jenkinsapi
;注销并登录后,您的工作目录为~/jenkinsapi-0.3.4
。在后一种情况下,Python无法在同一目录中找到模块并失败。
如果你执行~
然后打开Python shell,cd ~/jenkinsapi-0.3.4
应该可以正常工作。
作为旁注,您可能想要了解Pythons虚拟环境(请参阅this StackOverflow question以获取指针)并通过pip安装软件包。