user9368716
user9368716

Reputation:

Cannot run generated .exe with py2exe

I am trying to generate aa .exe using py2exe for a python script that generates an excel. Here is just a sample code. I am writing value 100 to a cell and saving the excel to Users Desktop using openpyxl. This works perfectly fine when I run it directly.

import openpyxl
import getpass

wb = openpyxl.Workbook()

ws = wb.create_sheet('test')
ws.cell(row=1, column=1, value=100)

username = getpass.getuser()

wb.save('C:\\Users\\{}\\create_exe\\gen.xlsx'.format(username))
print 'Done'

And when I compile it using py2exe it compiles also just fine. The problem arises when I run the generated .exe file. I get a return saying ImportError: No module named jdcal

setup.py file is as follows

import py2exe
from distutils.core import setup

packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml"]
excludes = []

setup(console=['test_program.py'],
      options={"py2exe": {"excludes": excludes,
                          "packages": packages}}
      )

Thisngs I have already tried

  1. I have searched and few people said Install openpyxl using pip. I have done that and pip says its alöready installed.
  2. I have also tried to install jdcal using pip and pip says it is installed.
  3. I have uninstalled jdcal and installed it using pip and manually, and still the same error.
  4. I have included jdcal in the packages and still no change in the outcome.

I hope someone can help me with it.

Thanks in advance

EDIT : Generated Filed in dist folder are as follows (openpyxl cannot be seen here, I don't know why)

  1. tcl (Folder)
  2. _ctypes.pyd
  3. _elementtree.pyd
  4. _hashlib.pyd
  5. _multiprocessing.pyd
  6. _socket.pyd
  7. _ssl.pyd
  8. _tkinter.pyd
  9. bz2.pyd
  10. pyexpat.pyd
  11. select.pyd
  12. unicodedata.pyd
  13. win32ui.pyd
  14. numpy.core._dummy.pyd
  15. numpy.core.multiarray.pyd
  16. numpy.core.multiarray_tests.pyd
  17. numpy.core.operand_flag_tests.pyd
  18. numpy.core.struct_ufunc_test.pyd
  19. numpy.core.test_rational.pyd
  20. numpy.core.umath.pyd
  21. numpy.core.umath_tests.pyd
  22. numpy.fft.fftpack_lite.pyd
  23. numpy.linalg._umath_linalg.pyd
  24. numpy.linalg.lapack_lite.pyd
  25. numpy.random.mtrand.pyd
  26. _win32sysloader.pyd
  27. win32api.pyd
  28. win32pdh.pyd
  29. win32pipe.pyd
  30. tk85.dll
  31. tcl85.dll
  32. libiomp5md.dll
  33. pywintypes27.dll
  34. python27.dll
  35. w9xpopen.exe
  36. pythoncom27.dll
  37. library.zip
  38. test_program.exe (Executable File)

Upvotes: 0

Views: 974

Answers (3)

HaR
HaR

Reputation: 1067

I use cx_freeze and never had any issues. Here's the setup.py for a cx_freeze file

from cx_Freeze import setup, Executable
build_exe_options = {"excludes": ["html5lib"],"optimize":2}
setup(name = "App Name" ,
      version = "1.0.0.0" ,
      options = {"build_exe": build_exe_options},
      description = "" ,
      executables = [Executable("FooBar.py")])

Upvotes: 0

Josh Duzan
Josh Duzan

Reputation: 80

I personally have had good luck letting py2exe detect the modules that are needed. I've never tried to specify every module necessary. try this:

   from distutils.core import setup
import py2exe

setup(console=['test_program.py'])

this should be run from command line as

python setup.py py2exe

py2exe outputs .dll files in the dist directory, these have to be in the directory that you run your .exe file from. if you just want one .exe file and no .dll files try this:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    console = [{'script': "test_program.py"}],
    zipfile = None,
)

this should be run from command line as

python setup.py

Upvotes: 0

Maxoz99
Maxoz99

Reputation: 31

Try to manually include it in setup.py in packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml"] so it would be: packages = ["openpyxl", "openpyxl.workbook", "xml.etree", "xml", "jdcal"]

Upvotes: 0

Related Questions