2016-01-13 162 views
1

我創建使用gspread和的oauth2模塊py2exe缺少模塊:oauth2client.client和gspread模塊

import gspread 
from oauth2client.client import SignedJwtAssertionCredentials 

credentials = SignedJwtAssertionCredentials("client_email","private_key", "https://spreadsheets.google.com/feeds") 
gc = gspread.authorize(credentials) 

spreadsheet = gc.open_by_key("spreadsheet_id") 
worksheet = spreadsheet.worksheet("sheet_name") 
lstoforders = worksheet.get_all_values() 

...some extra code... 

當我運行此代碼爲.py文件一切工作順利以下Python腳本。然而,當我嘗試使用py2exe把它打包成一個可執行的Windows程序,我得到下面的輸出

The following modules appear to be missing 
['ElementC14N', 'IronPythonConsole', 'System', 'System.Windows.Forms.Clipboard', '_scproxy', 'ca_certs_locater', 'clr', 'console', 'email.FeedParser', 'email.Message', 'email.Utils', 'google.appengine.api', 'google.appengine.api.urlfetch','google3.apphosting.api', 'google3.apphosting.api.urlfetch', 'http', 'modes.editingmodes', 'oauth2client.client' 'pyreadline.keysyms.make_KeyPress', 'pyreadline.keysyms.make_KeyPress_from_keydescr', 'pyreadline.keysyms.make_keyinfo', 'pyreadline.keysyms.make_keysym', 'startup', 'urllib.parse'] 

因此,當我嘗試運行生成的exe文件,我得到以下錯誤

Traceback (most recent call last): 
File "gspread_to_autocomplete_json.py", line 2, in <module> ImportError: No module named oauth2client.client 

它看起來好像py2exe找不到gspread和oauth2client.client模塊。這些模塊安裝在我的機器上。

有沒有人有線索爲什麼會發生這種情況?

謝謝。

尼古拉

回答

0

您可以用包和模塊的setup.py要include.It可能是你的安裝腳本不會自動查找所有依賴選擇(其實這是很常見的)。嘗試以看看the answer I gave to this question

選項添加到您的setup.py

你也可以爲了要導入所有項目所需要的模塊和包使用更py2exe options。例如。

# setup.py 
from distutils.core import setup 
import py2exe 
setup(console=["script.py"], 
     options={ 
       "py2exe":{ 
        "optimize": 2, 
        "includes": ["mf1.py", "mf2.py", "mf3.py"], # List of all the modules you want to import 
        "packages": ["package1"] # List of the package you want to make sure that will be imported 
       } 
     } 
    ) 

這樣就可以迫使你的項目的缺失腳本的進口

+0

你可能要考慮[這個答案](http://stackoverflow.com/q/34438105/5687152)作爲整合到我上面寫的內容 – mabe02