Edit: What tools can I use to see what packages/file the executable is trying to find when it tries to access the psycopg2 package? Perhaps that can help profile where things are going wrong.
I have a python script that runs perfectly fine when run using the interpreter yet when I freeze it, I am getting the error:
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgresql.psycopg2
Because it runs fine through the interpreter and fails when frozen, I suspect that something is wrong with my setup.py file.
#-*- coding: 'utf-8' -*-
from cx_Freeze import setup, Executable
import sys
# Dependencies are automatically detected, but it might need
# fine tuning.
# execute this file with the command: python setup.py build
buildOptions = dict(packages = ['ht_cg.ht_cg_objects'],
includes = ['ht_cg.ht_cg_objects'],
excludes = ['tkinter', 'PyQt4', 'matplotlib', 'tcl', 'scipy'],
include_files = ['./cg_source_prep/readme.txt', "./ht_cg_objects/ht_db_config.cfg"],
build_exe = 'build/source_density_exe')
sys.path.append('./')
sys.path.append('../')
executables = [
Executable(script = "cg_source_save.py",
initScript = None,
base='Console',
targetName = 'source_density_save.exe',
copyDependentFiles = True,
compress = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
shortcutName="CG Source Density",
shortcutDir='DesktopFolder',
icon = "./cg_source_prep/archimedes.ico"
)
]
setup(name='Source_Density',
version = '1.0',
description = 'Source Density Uploader',
author = 'zeppelin_d',
author_email = 'zeppelin_d@email',
options = dict(build_exe = buildOptions),
executables = executables)
I'm reading the connection string from the ht_db_config.cfg file that is base64 encoded but I print out the string just before attempting sqlalchemy.create_engine() and it's correct. I also added a string literal as the argument to the sqlalchemy.create_engine method and the frozen executable fails. The actual output from the script that fails is:
postgresql+psycopg2://user_name:[email protected]:5432/ht_cg_prod
I've replaced the username and the password.
I've been trying to get this fixed for a couple of days. I'd be grateful for any help. I'm running python 3.4, sqlalchemy 1.0.8, cx_freeze 4.3.4 and psycopg2 2.6 as determined by 'conda list' on windows 8.1. Thanks.
I finally found an answer to this. On the cx_freeze mailing list someone else had the same problem. The solution was to add
'sqlalchemy.dialects.postgresql'
to my list of packages in the cx_freeze build options.