10
« on: January 17, 2017, 04:11:41 AM »
Hi; I'm trying to package my python script as an executable, but am finding it very difficult. I'm following the directions at py2exe.org, and am using bearlibterminal and libtcod, and am getting dependencies that I don't understand how to fix. When I try to click the .exe file I created, it just crashes with no errors, but it runs fine when I launch it out of powershell.
Here's what powershell tells me when I'm trying to run the .exe from there:
PS C:\Python27\Grit\dist> .\gritandsteel.exe
Traceback (most recent call last):
File "gritandsteel.py", line 6, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "PyBearLibTerminal.pyc", line 58, in <module>
File "PyBearLibTerminal.pyc", line 56, in _load_library
RuntimeError: BearLibTerminal library cannot be loaded (looked for BearLibTerminal.dll in C:\Python27\Grit\dist\gritandsteel.exe)
PS C:\Python27\Grit\dist>
I don't know why it's looking for the .dll IN the .exe, or how I would fix it. BearLibTerminal.dll is in the same file directory as my .exe.
I created the .exe using the tutorial code here:
from distutils.core import setup
import py2exe
import os
import sys
sys.argv.append('py2exe')
# The filename of the script you use to start your program.
target_file = 'gritandsteel.py'
# The root directory containing your assets, libraries, etc.
assets_dir = '.\\'
# Filetypes not to be included in the above.
excluded_file_types = ['py','pyc','project','pydevproject']
def get_data_files(base_dir, target_dir, list=[]):
"""
" * get_data_files
" * base_dir: The full path to the current working directory.
" * target_dir: The directory of assets to include.
" * list: Current list of assets. Used for recursion.
" *
" * returns: A list of relative and full path pairs. This is
" * specified by distutils.
"""
for file in os.listdir(base_dir + target_dir):
full_path = base_dir + target_dir + file
if os.path.isdir(full_path):
get_data_files(base_dir, target_dir + file + '\\', list)
elif os.path.isfile(full_path):
if (len(file.split('.')) == 2 and file.split('.')[1] not in excluded_file_types):
list.append((target_dir, [full_path]))
return list
# The directory of assets to include.
my_files = get_data_files(sys.path[0] + '\\', assets_dir)
# Build a dictionary of the options we want.
opts = { 'py2exe': {
'ascii':'True',
'excludes':['_ssl','_hashlib'],
'includes' : ['anydbm', 'dbhash'],
'bundle_files':'1',
'compressed':'True'}}
# Run the setup utility.
setup(console=[target_file],
data_files=my_files,
zipfile=None,
options=opts)
Any help is appreciated as to why this isn't launching. Thank you.