2016-01-13 164 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