My script, built as an application, stops working when it tries to load pickle model data. The following is the problematic code:
with open('model_pickle','rb') as f:
mp = pickle.load(f)
This is the setup file I’m using:
setup(
name="Test",
version="1.0",
options={"build_exe":{"include_files":["model_pickle"]}},
executables=[target]
)
The program works as it should when executing the python script. However, after converting it to an executable via cx_freeze, the issue is with opening the pickle model data file. I have tested this with and without the data, so I’m pretty sure this is the issue.
You can import model as follows model = pickle.load(open('MODEL_PATH','rb')) .Hope this will work!
I’m 99.99% positive that you need to also add the model_pickle file to your setup(…) call as package data for this to work as an executable. Here’s a setup.py snippet showing the package data options:
from setuptools import setup, find_packages
PROJECT_NAME = 'my_project' # this should reflect your package structure
setup(
# …
packages=[package for package in find_packages() \
if package.startswith(PROJECT_NAME)],
package_dir={ 'my_project' : 'my_project' },
package_data={ '' : ['*.*'] },
include_package_data=True,
zip_safe=True,
# …
)
Also, if I were you, I’d rename the data file to something like model_pickle.pkl so that your package_data expression doesn’t have to be double-wildcarded (as above).
If that doesn’t immediately work, I would also recommend adding a MANIFEST.in file that explicitly names your binary data file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With