I created a little script using the datetime functions in python and am trying to convert this to a .exe using py2exe. When I try running this from someone else's machine I get an error message about calendare module not found

This is the python

import datetime
import calendar

no_of_days = int(raw_input('enter to number of days you want to add: '))
print no_of_days
today = datetime.date.today()
datethen = today + datetime.timedelta(days=no_of_days)
print 'the answer is: ' , datethen

The setup script looks like this

from distutils.core import setup
import py2exe
import datetime
import calendar
setup(console=['datestuff.py'])

When I run it on his machine I get this error message- (I already copied python25.dll and the MSVR71.dll files to his machine)

Traceback (most recent call last):
  File "C:\Python25\lib\site-packages\py2exe\boot_common.py", line 92, in <modul
e>
    import linecache
ImportError: No module named linecache
Traceback (most recent call last):
  File "datestuff.py", line 2, in <module>
ImportError: No module named calendar

First let's add a console wait so you can see the result before the console closes ...

import datetime
import calendar

no_of_days = int(raw_input('enter to number of days you want to add: '))
print no_of_days
today = datetime.date.today()
datethen = today + datetime.timedelta(days=no_of_days)
print 'the answer is: ' , datethen

# wait to show results
raw_input("press enter to go on ... ")

Now make the py2exe package this way ...

"""
Py2ExeConSetup.py

Py2Exe (version 6.6 and higher) setup file for a console 
programs.  Creates a single .exe file.

Simply add this file into the same folder with the source 
file.  Change your source filename at the bottom to whatever 
you called your code file.  Now run Py2ExeConSetup.py ...

Two subfolders will be created called build and dist.
The build folder is for info only and can be deleted.
Distribute whatever is in the dist folder.
The dist folder contains your .exe file, MSVCR71.dll and 
w9xpopen.exe

Your .exe file contains your code as . pyo optimized byte code 
files, all needed modules and the Python interpreter (as a 
Pythonxx.dll).  MSVCR71.dll can be distributed, but is often 
already in the system32 folder.  File w9xpopen.exe is needed 
for os.popen() only, can be deleted otherwise.
Tested with Python25  by  vegaseat
"""

from distutils.core import setup
import py2exe
import sys

sys.argv.append("py2exe")
sys.argv.append("-q")

setup(
  options = {"py2exe": {"compressed": 1,
                        "optimize": 2,
                        "ascii": 1,
                        "bundle_files": 1}},
  zipfile = None,
  # replace 'DateTime1.py' with your own code filename
  # (replace console with windows for a windows program)
  console = [{"script": 'DateTime1.py'}]
)

First let's add a console wait so you can see the result before the console closes ...

import datetime
import calendar

no_of_days = int(raw_input('enter to number of days you want to add: '))
print no_of_days
today = datetime.date.today()
datethen = today + datetime.timedelta(days=no_of_days)
print 'the answer is: ' , datethen

# wait to show results
raw_input("press enter to go on ... ")

Now make the py2exe package this way ...

"""
Py2ExeConSetup.py

Py2Exe (version 6.6 and higher) setup file for a console 
programs.  Creates a single .exe file.

Simply add this file into the same folder with the source 
file.  Change your source filename at the bottom to whatever 
you called your code file.  Now run Py2ExeConSetup.py ...

Two subfolders will be created called build and dist.
The build folder is for info only and can be deleted.
Distribute whatever is in the dist folder.
The dist folder contains your .exe file, MSVCR71.dll and 
w9xpopen.exe

Your .exe file contains your code as . pyo optimized byte code 
files, all needed modules and the Python interpreter (as a 
Pythonxx.dll).  MSVCR71.dll can be distributed, but is often 
already in the system32 folder.  File w9xpopen.exe is needed 
for os.popen() only, can be deleted otherwise.
Tested with Python25  by  vegaseat
"""

from distutils.core import setup
import py2exe
import sys

sys.argv.append("py2exe")
sys.argv.append("-q")

setup(
  options = {"py2exe": {"compressed": 1,
                        "optimize": 2,
                        "ascii": 1,
                        "bundle_files": 1}},
  zipfile = None,
  # replace 'DateTime1.py' with your own code filename
  # (replace console with windows for a windows program)
  console = [{"script": 'DateTime1.py'}]
)

Great. That worked. The reason I didn't have that "press enter to go on " construct was that I was planning to run this from the command line and and hadn't even thought of double clicking the .exe in windows explorer. But that's also good input.

I'm guessing that the bundle_files option enabled the inclusion of the calendar and datetime modules?

Great. That worked. The reason I didn't have that "press enter to go on " construct was that I was planning to run this from the command line and and hadn't even thought of double clicking the .exe in windows explorer. But that's also good input.

I'm guessing that the bundle_files option enabled the inclusion of the calendar and datetime modules?

The "bundle_files": 1 option includes the Python interpreter (eg. python25.dll) inside the .exe file. The "bundle_files": 2 option keeps the Python interpreter separate from the .exe file.

The interpreter DLL is often the largest portion of the .exe file. If you have several packed .exe files to distribute, it is better to keep this DLL separate, so you need to distribute it only once.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.