簡體   English   中英

無法導入名稱SharePointSite

[英]cannot import name SharePointSite

我在台式機和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會再次加載您自己的文件,這時它將無法再次導入自身。

將腳本重命名為其他名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM