我在台式机和Windows 2008 R2服务器上都收到相同的错误消息-
这是代码-
from sharepoint import SharePointSite, basic_auth_opener
server_url = "http://sharepoint/"
site_url = server_url + "path/to/page/Forms/AllItems.aspx"
opener = basic_auth_opener(server_url, "acct", "password")
site = SharePointSite(site_url, opener)
for sp_list in site.lists:
print sp_list.id, sp_list.meta['Title']
运行它时出现以下错误-
Traceback (most recent call last):
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
ImportError: cannot import name SharePointSite
这是怎么回事?包裹在以下位置-
C:\Python27\Lib\site-packages\sharepoint
我可以导入其他软件包。例如,lxml可以正常工作。
from lxml import etree
没问题。
您命名了脚本sharepoint.py
,并且掩盖了该库:
Traceback (most recent call last):
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
ImportError: cannot import name SharePointSite
查看回溯中的文件名,您可以看到脚本最终将自身导入;当Python启动脚本时,它将以方式加载__main__
,因此导入sharepoint
会再次加载自己的文件,这时它将无法再次导入自身。
将脚本重命名为其他名称。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句