0
votes

I am trying to create an .exe-file from a script using py2exe (WinPython 3.4.4 in Windows 7). In this script I am using different backends of the matplotlib package (Version 1.5.2). All of my attempts resulted with the error:

... name = self._resolve_name(name, package, level) File "M:\Python\WinPython-32bit-3.4.4.4Qt5b1\python-3.4.4\lib\site-packages\py2exe\mf3.py", line 213, in _resolve_name raise ValueError('attempted relative import beyond top-level package') ValueError: attempted relative import beyond top-level package

With other packages, that are on the same directory-level as matplotlib, there is no problem. I read all the posts concerning this topic, but couldn't find a solution yet (including pyinstaller). Can anybody help me?

"setup.py":

from distutils.core import setup
import py2exe
import matplotlib

setup(console=['skript.py'],
options={
   "py2exe":{
             "packages":   ['matplotlib.pyplot','matplotlib.backends.backend_pdf'], # List of all the modules you want to import
            }
        },
data_files=matplotlib.get_py2exe_datafiles(),        
)

UPDATE I now installed matplotlib version 2.0.0. I import the packages in my script with

from matplotlib import pyplot, dates
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.ticker import MaxNLocator

Running the script in spyder works well. The error message when using py2exe now changed to:

File "M:\Python\WinPython-32bit-3.4.4.4Qt5b1\python-3.4.4\lib\site-packages\py2exe\hooks.py", line 291, in getattr self.__finder.safe_import_hook(renamed, caller=self) RuntimeError: maximum recursion depth exceeded

1

1 Answers

0
votes

I seems you use py2exe the wrong way.

You first need to have a sunning python script that you want to convert to exe, say you call it script01.py.

Then in script01.py do

import matplotlib.pyplot as plt

And then you write a setup.py script to convert sctipy01.py to exe like this, in its most simple form:

from distutils.core import setup
import py2exe

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