我使用python 2.7.6和pysphere 0.1.7.I我得到下面的代碼中的錯誤:導入錯誤:無法導入名稱「VIServer」
import sys
import pysphere
from pysphere import VIServer
server=VIServer()
server.connect(host,login,password)
vm_target=server.get_vm_by_name(guest)
if vm_target.get_status() == 'POWERED OFF':
vm_target.power_on()
while vm_target.is_powering_on():
continue
server.disconnect()
錯誤說:導入錯誤:無法導入名稱'VIServer'
腳本正試圖將文件從本地計算機複製到目標虛擬機。
完整的錯誤信息是:
Traceback (most recent call last):
File "copy.py", line 4, in <module>
from pysphere import VIServer
File "/usr/local/lib/python2.7/dist-packages/pysphere/__init__.py", line 171, in <module>
from pysphere.vi_task import VITask
File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_task.py", line 34, in <module>
from pysphere.resources import VimService_services as VI
File "/usr/local/lib/python2.7/dist-packages/pysphere/resources/VimService_services.py", line 6, in <module>
from pysphere.resources.VimService_services_types import *
File "/usr/local/lib/python2.7/dist-packages/pysphere/resources/VimService_services_types.py", line 7, in <module>
import pysphere.ZSI
File "/usr/local/lib/python2.7/dist-packages/pysphere/ZSI/__init__.py", line 151, in <module>
from pysphere.ZSI.wstools.Namespaces import ZSI_SCHEMA_URI
File "/usr/local/lib/python2.7/dist-packages/pysphere/ZSI/wstools/__init__.py", line 7, in <module>
from pysphere.ZSI.wstools import WSDLTools
File "/usr/local/lib/python2.7/dist-packages/pysphere/ZSI/wstools/WSDLTools.py", line 15, in <module>
from pysphere.ZSI.wstools.Utility import Collection, CollectionNS, DOM, ElementProxy, basejoin
File "/usr/local/lib/python2.7/dist-packages/pysphere/ZSI/wstools/Utility.py", line 36, in <module>
import xml.dom.minidom
File "/usr/lib/python2.7/xml/dom/minidom.py", line 22, in <module>
from xml.dom.xmlbuilder import DOMImplementationLS, DocumentLS
File "/usr/lib/python2.7/xml/dom/xmlbuilder.py", line 3, in <module>
import copy
File "/home/shasha/devOps/pythonSamples/copy.py", line 4, in <module>
from pysphere import VIServer
ImportError: cannot import name VIServer
copy.py是腳本的名稱。
任何幫助將是善良的;
當你刪除「import pysphere」這一行並且剛剛從'pysphere import VIServer'行刪除了這行時會發生什麼? – Wolf
@Wolf,它給出了同樣的錯誤; – Shasha99
你能否包含完整的錯誤信息?你是否將腳本命名爲pysphere.py? – M4rtini