0

I am converting my python 2.7.6 code(which only uses easygui.py (v0.95) into an .exe but I am having trouble when using

python setup.py py2exe

my setup.py

from distutils.core import setup
import py2exe
import easygui
import matplotlib.pyplot as plt
import os

setup(console=["DataAnalysis-v2.5.py"])

top lines of my code

import os
import easygui
import matplotlib.pyplot as plt

***********UPDATE********************** So i am getting an error with numpy and matplot lib. I copied numpy,matplotlib and dateutil from the sitepackages section of portable python and pasted it into the lib site packages section of python 27. For some reason numpy it making the exe close quick and crash.

here is what shows in cmd when i click on the exe

Traceback (most recent call last):
  File "DataAnalysis-v2.5.py", line 3, in <module>
  File "matplotlib\__init__.pyc", line 838, in <module>
  File "matplotlib\__init__.pyc", line 749, in rc_params
  File "matplotlib\__init__.pyc", line 664, in matplotlib_fname
  File "matplotlib\__init__.pyc", line 292, in wrapper
  File "matplotlib\__init__.pyc", line 585, in _get_data_path_cached
  File "matplotlib\__init__.pyc", line 581, in _get_data_path
RuntimeError: Could not find the matplotlib data files
  • The contents of your setup.py file will be necessary to help determine what is (or is not) present to cause this error. – g.d.d.c May 19 '14 at 18:32
  • What's the name of your script? Is it `Data Analysis-v2.4.py` (you should avoid spaces in the names of .py files), or is it `mycode.py`? Also, note from the docs here: http://py2exe.org/index.cgi/Tutorial that console should be a list, not a string value. `console = ["Data Analysis-v2.4.py"]`. – g.d.d.c May 19 '14 at 19:12
  • As pointed out already in the comment of the answer below, have a closer look at the py2exe wiki. You need to add something like `setup( ... data_files=matplotlib.get_py2exe_datafiles(), )` to your `setup.py` and the error not finding matplotlib datafiles should go away. Also have a look at a [seemingly identical example](http://stackoverflow.com/questions/18228774/errors-with-matplotlib-when-making-an-executable-with-py2exe-python). BTW: Do you see the folder mpl-data in the dist dir of the frozen app? – nepix32 May 21 '14 at 12:53

1 Answers1

1

The issue looks to be that you've passed the console keyword incorrectly. It should be passed a list of scripts to compile. Because you've passed a string, which is iterable but not a list, py2exe is attempt to create a script from each letter in the input string.

for c in "Data Analysis-v2.4.py":
  # D
  # a
  # t
  # ...

for fname in ["Data Analysis-v2.4.py"]:
  # produces "Data Analysis-v2.4.py".
g.d.d.c
  • 46,865
  • 9
  • 101
  • 111
  • Okay so I got it to compile but it didnt work. So i took the the numpy, matplot and dateutil libraries from my portable python and pasted it into the lib folder for python27(I needed these libs for the code). Now i get a missing DLL error. Thanks for the help so far! – Waqar Khawaja May 19 '14 at 22:44
  • Okay I downloaded the DLL and now i dont get that error and it creates the exe. however when i click on the exe it closes quick. some error about matplot lib. just pasting it into the lib folder in python27 will work? or was there a method of installing of matplotlib? Thanks! – Waqar Khawaja May 19 '14 at 22:50
  • @WaqarKhawaja - There are details about getting matplotlib working with py2exe available here: http://www.py2exe.org/index.cgi/MatPlotLib. – g.d.d.c May 19 '14 at 23:39
  • Yeah I just tried that and I couldnt get it to work. I have matplot v1.2.1 so i just tried using the code till the end of the data files section in the site but it didnt work. This is my first time using py2exe so i am not sure how to setup the format in setup.py with what i currently have in there. – Waqar Khawaja May 19 '14 at 23:59