Menu

#139 Using py2exe with PyProj

open
nobody
None
5
2014-12-26
2014-12-26
No

I don't know whether this should be considered a bug or a workaround, but there's a bunch of workarounds on at the py2exe pages and my findings working with PyProj could just as well be added to that list.

However, it seems that py2exe tries to deal with the situation:
In my <PytonDir>/Lib/site-packages/pyproj-1.9.3-py2.7-win32.egg/pyproj/data, there is a bunch of files that pyproj need and will load at runtime.

py2exe puts these files in the dist/library.zip file, more precisely in the /pyproj/data directory with that file. Hence when running my script as an executable, pyproj.pyproj_datadir correcly is set to <path2dist>/library.zip/pyproj/data.

Nonetheless, I still get a runtime error when accessing pyproj: RuntimeError: no system list, errno: 2.

The workaround for me, was to include the pyproj/data files in my data_files entry in my setup.py file:

pyProjData = pyproj.pyproj_datadir
sys.path.append( pyProjData)  # not sure if this is necessary, but it is needed for msvcr90.dll
dataFiles = [...,
             ( "pyproj", glob( os.path.join( pyProjData, "*" )))]

setup(data_files=dataFiles,
      console=['<myscript.py>'])

And then, early in my main script, manually set the pyproj data path:

mainDir = get_main_dir()

if main_is_frozen():
    pyproj.set_datapath(os.path.join( mainDir, "pyproj"))

Where the get_main_dir() and main_is_frozen() functions are found here.

Discussion


Log in to post a comment.

Auth0 Logo