问题
back again. I am still working on it but I can not fix it
The script is running fine but when I freeze it using cx_freeze a cx_freeze error appears.
at the end of the message says
OSError:proj data directory not found. Expecting it at: C:\python34........mpl_toolkits\basemap\data
Is the data not included in the build directory created by cx_freeze ?
I am using the following script for freezing
base = None
def find_data_file(pyproj):
if getattr(sys,'XXXXs.exe',False):
datadir = os.path.dirname(sys.aaEjecutable.py)
else:
datadir = os.path.dirname(__file__)
return os.path.join(datadir,pyproj)
if (sys.platform == "win32"):
base = "Win32GUI"
exe = Executable(
script = "Conver.py",
icon = "logo4.ico",
targetName = "XXXXs.exe",
base = base
)
includefiles = ["Logo1.jpg","Logo2R.jpg","Logo2R.jpg","logo4.ico",
(('C:\Python34\Lib\site-packages\mpl_toolkits'),("mpl_toolkits"))]
setup(
name = "Conver",
version = "V3",
description = "conve",
author = "Jose ",
options = {"build_exe": {"include_files":includefiles}},
executables = [exe]
)
I think that something is wrong whit it. I must include the basemap but I dont't know how to do it
I can not go foward. The script is fine but I can use it in a computer with no python
Thanks
回答1:
I got a similar issue using Python 3.4 and cx_freeze 4.3.3. My fix required 2 changes:
In the cx_freeze setup script:
buildOptions = dict( include_files = [("C:/Python34/Lib/site-packages/mpl_toolkits/basemap/data","data")])
In my module where I am using Basemap:
import sys, os if getattr(sys, 'frozen', False): os.environ['BASEMAPDATA'] = os.path.join(os.path.dirname(sys.executable), 'data') from mpl_toolkits.basemap import Basemap
As requested, my full setup script is:
from cx_Freeze import setup, Executable
buildOptions = dict(packages = ['osgeo._gdal'], excludes = [], \
include_files = [("C:/Python34/Lib/site-packages/mpl_toolkits/basemap/data","data")])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('main.py', base=base, targetName = 'xxxxxxx.exe', icon='ico/xxxxx.ico')
]
setup(name='Xxxxx',
version = '0.0.1',
description = 'Xxxxx xxxx xxxx',
author = 'xxxxxxx@xxx.edu',
options = dict(build_exe = buildOptions),
executables = executables)
回答2:
A way to always get the basemap data directory, with out hard coding
import matplotlib
from mpl_toolkits import basemap
build_options = dict( include_files = [(basemap.basemap_datadir, 'data')])
来源:https://stackoverflow.com/questions/26286624/can%c2%b4t-freeze-a-script-with-matplotlib-basemap-and-cx-freeze