2

Possible Duplicate:
Outputed py2exe exe won't run only when signed: ImportError

I asked a similar question previously (Creating executable with Py2exe and matplotlib errors) that dealt with matplotlib errors. However, I have gotten past this stage. Now when I try to build my executable, none of my packages/code seem to import. For example, my code imports the following:

import os
import csv
import wx
import time
import math

from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle

I get a log error when I run my executable that it "No Module Named os". I get an error for every module I have in my code (if i change the order in which things are imported). Why aren't any of my modules importing? My Py2exe code looks like:

import os
from distutils.core import setup 
import py2exe

from distutils.filelist import findall
import matplotlib
import glob

from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle
import wx


setup( 


windows=[{'script': r'Scout_Tool.py'}], 


data_files = [(r'mpl-data', glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*')),

              (r'mpl-data', [r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
              (r'mpl-data\images',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-        data\images\*.*')),
              (r'mpl-data\fonts',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-        data\fonts\*.*'))],


#matplotlib.get_py2exe_datafiles(),

options={ 
    'py2exe':{ 
        'includes': [ 
            'matplotlib',
            'matplotlib.backends.backend_wx',
            'matplotlib.pyplot',
            'mpl_toolkits.basemap',
            'matplotlib.figure',
            'numpy.random',
            'wx.calendar',
            'mpl_toolkits', 
            'numpy', 
            'datetime', 
            'wx', 
            'pylab', 
            'adodbapi', 
            'sqlparse',
            'annote_new',
            'cPickle', 
            'pylab' 
        ], 
        'dll_excludes': ['MSVCP90.dll'],  
    } 
},


) 

Any thoughts on why my modules aren't importing after I run the py2exe? BTW, I get no errors when running the py2exe code -- only when i try to run the produced executable. Thanks!

EDIT

Okay, here is what i have done. I have taken out some of the modules that I weren't using and removed the duplicates. I also fixey my setup.py file to look like:

from distutils.core import setup 
import py2exe
import matplotlib
import glob

setup( 

windows=[{'script': r'Scout_Tool.py'}], 

data_files = matplotlib.get_py2exe_datafiles(),

options={ 
        'py2exe':{ 
            'includes': [ 
                'matplotlib',
                'matplotlib.backends.backend_wx',
                'matplotlib.pyplot',
                'mpl_toolkits.basemap',
                'matplotlib.figure',
                'wx.calendar',
                'mpl_toolkits', 
                'datetime', 
                'wx', 
                'adodbapi', 
                'sqlparse',
                'annote_new',
                'cPickle', 
                'pylab' 
            ], 

        } 
    },


) 

After this, I cleared out my entire 'dist' folder to be sure anything wasn't kept from before. Then I ran the following in CMD Prompt: C:\Python27\python setup.py py2exe. This ran with no errors.

Then when i go to run Scout_Tool.exe, I first get a MatPlotLib data error. I am not sure why i am getting this, but to fix it, I do the following: I unzip "library.zip", then add the "data" folder from Mpl-toolkits - basemap - data, then re-zip the library folder.

Then, when I try running Scout_Tool.exe, it comes up with the error that "No module named os" exists. This is true if I put any module first in my Scout_Tool.py code.

Hopefully this helps with where i am at? Thanks!

Community
  • 1
  • 1
mcfly
  • 1,151
  • 4
  • 33
  • 55
  • Py2exe whould output a wall of text more or less telling the user which things it is byte compiling. After that it should dump a list of things that are "missing". Are any of those librarys ones that you think you need? Take a look at the log message, it might help you out – Paul Seeb Jun 29 '12 at 13:05
  • I checked it out. I posted above my output. Doesn't seem to help? – mcfly Jun 29 '12 at 13:12
  • your setup.py script is an excellent starting point for anyone else suffering to get matplotlib deployed along with a py2exe executable. Would have saved me 3 hrs had I seen it first.. – ecoe Oct 06 '13 at 21:53

2 Answers2

2

I compiled your program (the imports) and it runs OK for me. the py2exe missed module report is not relevant if you are not using those modules (I got the same list as that you show).

Remember that the executable will run while you execute it within the dist module py2exe creates (and not from a copy in your desktop, for example. For that you need to make a direct access link).

joaquin
  • 82,968
  • 29
  • 138
  • 152
  • I am not having the same luck as you. Can you post an example of what you did? Also, I am running it in the "dist" folder that it is created in. And when i unzip the library.zip folder, i see "os.pyc" in there... – mcfly Jun 29 '12 at 13:39
  • I did nothing special, just copied your files (eliminated two or three imports like basemap I do not have in my installation) and executed `python setup.py py2exe`. Then I ran the executable from the shell with no error indication. You could try to eliminate all your imports except for `import os` and with only one statement in your script (i.e. print 'hello'). And check if you get the same problem – joaquin Jun 29 '12 at 14:52
  • Seems to build fine with just import os and print "hello" in the file. I guess i'll have to investigate further unless you have other ideas? – mcfly Jun 29 '12 at 15:10
  • dit it print 'hello' when executed ? About your script, note that you are importing numpy twice with different names. Note also you dont need to import every module used in your script or cited in setup.py, just those directly used in setup.py (only lines 2,3 and 7 in your setup if i'm right). – joaquin Jun 29 '12 at 17:30
  • No, just ran with no error log – mcfly Jun 29 '12 at 17:30
  • I added some more edits above. This takes out unnecessary lines and explains exactly what i did -- help? – mcfly Jun 29 '12 at 18:27
0

Not going to take credit for this but do either of these help your problem?

http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=6659

Outputed py2exe exe won't run only when signed: ImportError

This question is also a continuation of

py2exe doesn't import the os module?

Community
  • 1
  • 1
Paul Seeb
  • 6,006
  • 3
  • 26
  • 38
  • Neither of these help. I already check out these three sites. PyInstaller does not work because I can't seem to fix some _Imaging C Module to be found. I cannot seem to figure out the py2exe errors with these given sites either (seems like threads weren't finished) – mcfly Jun 29 '12 at 13:28