I have created the following Python script using the gspread and oauth2 modules
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...
When I run this code as a .py file everything works smoothly. However, when I try to package it into an executable Windows program using py2exe, I get the following output
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']
Accordingly, when I try to run the resulting exe file, I get the following error
Traceback (most recent call last):
File "gspread_to_autocomplete_json.py", line 2, in <module> ImportError: No module named oauth2client.client
It appears as if py2exe cannot find the gspread and oauth2client.client modules. These modules are installed on my machine.
Does anybody have a clue why this is happening?
Thanks.
Nicola
You can choose in your setup.py with packages and modules you want to include.It might be that your setup script is not finding all the dependencies automatically (actually it is pretty common).Try to have a look at the answer I gave to this question.
Add options to your setup.py
You can also use more py2exe options in order that you are importing all the modules and the packages required by your project. E.g.
# 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
}
}
)
In this way you can force the import of the missing script of your project
Related
I have successfully converted .py file to .exe file using py2exe.
I can successfully run the .py file,if i run it standalone.However, when iam trying to run the .exe file, it throws an error as seen in attached image.
In my .py file, i have the below import statements:
import xlrd,xlwt,xlutils.copy,re,time,openpyxl,os
from openpyxl.styles import Alignment
from openpyxl import load_workbook
I have also accordingly tweaked setup.py file to include these packages as below setup.py code shows
from distutils.core import setup
import py2exe
setup(
console=['vu_t2.py'],
options = {
'py2exe': {
'packages': ['xlrd','xlwt','xlutils','openpyxl','openpyxl.workbook']
}
}
)
Please refer the attached error snapshot
I used the below command to run py2exe
python setup.py py2exe
openpyxl only supports distribution via pip.
I'm trying to use py2exe to build an executable on 64-bit Windows 7 with Anaconda (Python 3.4) for a project of mine that depends on a lot of libraries. Some of the more complex ones include vispy (pyopengl), PyQt4, numba, and scipy. I've been stepping through various errors to try to get a working executable, but have hit a road block with no clear way forward. Currently, the py2exe command completes, but I get the following error when running the exe:
...
from numba import jit
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\__init__.py", line
13, in <module>
from .pycc.decorators import export, exportmany
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\pycc\__init__.py",
line 12, in <module>
from .cc import CC
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\pycc\cc.py", line
4, in <module>
from distutils.command import build_ext
File "C:\Anaconda3\envs\sift_py2exe\lib\distutils\command\build_ext.py", line
17, in <module>
from site import USER_BASE
ImportError: No module named 'site'
I was able to do a small workaround by adding the C:\Anaconda3\envs\sift_py2exe\Lib directory to sys.path in my main script, but I doubt that's going to help me much later. Not to mention I had more scipy DLL issues after that.
Here are the relevant parts of my setup.py:
try:
import py2exe
from llvmlite.binding.ffi import _lib_dir, _lib_name
kwargs["data_files"] = [('.', [os.path.join(_lib_dir, _lib_name), os.path.join(_lib_dir, "MSVCP120.dll"), os.path.join(_lib_dir, "MSVCR120.dll")])]
kwargs["console"] = [{
'script': 'cspov/__main__.py',
'dest_base': "SIFT",
}]
kwargs["options"] = {'py2exe': {"includes": ["vispy.app.backends._pyqt4", "PyQt4.QtNetwork"]}}
except ImportError:
print("'py2exe' and/or 'llvmlite' not available")
I've tried adding the "Lib" directory in setup.py and then including "site", but it doesn't find the module. Any ideas? Thanks.
Side note: I'm using the Microsoft DLLs from llvmlite as a quick workaround because I couldn't get it to work in any of the normal ways.
This isn't the answer I was hoping for, but I was able to get a working executable when I switched to pyinstaller. All of the other SO questions I saw relevant to my problem had similar "solutions".
My python script includes a Qt GUI which I'm trying to convert into a Windows executable using Py2exe. My script is using the Tweepy module to fetch data from Twitter. So I include Tweepy and try to compile it into an executable using the following Setup.py:
from distutils.core import setup
import py2exe
setup(
windows = [{"script": "main.py"}],
options = {"py2exe":{"includes":["sip", "tweepy"]}}
)
The following Error gets raised:
raise ImportError, "No module named " + qname
ImportError: No module named tweepy
I've succesfully used the same setup file (minus the 'Tweepy include') to compile other script in the past. What am I missing here?
Assuming that you have tweepy installed in the python installation that you are trying to build with try adding:
import tweepy
near the start of your setup.py to ensure that py2exe can really see it, some packages do some interesting things during import.
So I am trying to freeze a Python script as an .exe. I installed cx_freeze to do so as I am using 3.4. I created the setup.py file successfully and also ran the build which appears in the build folder and .exe appears. However, when I open the .exe it displays the following error:
zipimport.ZipImportError: can't find module 'cx_Freeze__init__'
Fatal python error: unable to locate initialization module
Current thread 0x00001d58 <most recent call first>:
I believe I did everything else correctly. There is indeed a cx_Freeze_init_.pyc file in the library.zip, however it cannot find it for some reason. The only other error I had was that certain modules were missing when during the cmd build:
Missing modules:
? _dummy_threading imported from dummy_threading
? ce imported from os
? doctest imported from heapq
? getopt imported from base64, quopri
? org.python.core imported from copy
? os.path imported from os
? posix imported from os
? pwd imported from posixpath
? subprocess imported from os
This is not necessarily a problem - the modules may not be needed on this platfo
rm.
This is the setup.py I used:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
base = 'Console'
executables = [
Executable('guess.py', base=base)
]
setup(name='Guess',
version = '1.0',
description = 'test',
options = dict(build_exe = buildOptions),
executables = executables)
Thanks in advance!
I've created a program that pulls information from routers using SNMP (via PySNMP module). The application works great and I now what to compile it into a standalone application so that I can distribute it to my co-workers. However, after trying both Py2exe and PyInstaller, I've been unsuccessful in compiling a working application. I have searched the internet (a lot!) trying to find an example of someone who has successfully been able to compile their PySNMP application, but haven't been able to find anyway. Is there a better way to compile this or am I just doing it wrong?
These are the modules I've imported:
from Tkinter import *
import tkMessageBox
from pysnmp.entity.rfc3413.oneliner import cmdgen
This is the setup.py I've created for Py2exe:
from distutils.core import setup
import py2exe
setup( console = [
{ "script": "RSSIChecker.py",
}],
options = {
"py2exe":{
'includes': [
'pysnmp.smi.mibs.*',
'pysnmp.smi.mibs.instances.*'
]
}
}
)
Any suggestions?
With the following setup.py, a pysnmp-based app can be packaged with py2exe right out of the box (see line 101 and below). There are also some additional modules added implicitly into py2exe packaging as they are used by the app, not pysnmp itself.