We're working on a Cocos2D game for Ludum Dare right now, and we are having issues packaging the game into an executable of some kind.
We have tried using py2exe, but it doesn't seem to work. I've read that py2exe often causes problems with this kind of libraries, but that they are usually workable. However, I've been doing some research for the last few hours and I can't seem to find a solution.
Here's the error message it gives us when executing the .exe, apparently it can't import the pyglet.resource module.
C:\Users\Jon\Documents\GitHubVisualStudio\King-of-the-Dungeon\King of the Dungeon\King of the Dungeon\dist>king_of_the_dungeon.exe
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pyglet\__init__.py", line 351, in __getattr__
return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'path'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "king_of_the_dungeon.py", line 1, in <module>
File "C:\Python34\lib\site-packages\cocos2d-0.6.3-py3.4.egg\cocos\__init__.py", line 71, in <module>
pyglet.resource.path.append(
File "C:\Python34\lib\site-packages\pyglet\__init__.py", line 357, in __getattr__
__import__(import_name)
ImportError: No module named 'pyglet.resource'
I just tried it myself and It works without problem. But I used cx_freeze.
See, Py2exe is old, no longer maintained, and overall you're better off using cx_freeze.
Download cx_freeze
create a setup.py file to create an exe:
import cx_Freeze
# Change "App" to the name of your python script
executables = [cx_Freeze.Executable("App.py")]
cx_Freeze.setup(
name="Sample Name",
version = "1",
options={"build_exe": {"packages":["pyglet", "cocos", "pygame"]}},
executables = executables
)
open cmd / terminal and build with ; python setup.py build
I just tried it with a simple game and it compiled with no trouble.
Related
Currently trying to build a exe using PyInstaller. The installation goes fine, although when trying to run the exe an exception occurs
Exception ignored in: <function Library.__del__ at 0x000002126637F160>
Traceback (most recent call last):
File "C:\Users\blah\AppData\Local\Programs\Python\Python39\lib\site-packages\pylink\library.py", line 272, in __del__
File "C:\Users\blah\AppData\Local\Programs\Python\Python39\lib\site-packages\pylink\library.py", line 390, in unload
File "C:\Users\blah\AppData\Local\Programs\Python\Python39\lib\ctypes\__init__.py", line 444, in __getattr__
File "PyInstaller\loader\pyimod04_ctypes.py", line 79, in __init__
pyimod04_ctypes.install.<locals>.PyInstallerImportError: Failed to load dynlib/dll 'kernel32'. Most likely this dynlib/dll was not found when the application was frozen.
I've followed the lead on some other posts and ensured the Visual C++ Redistributables are installed and also included --hidden-import ctypes in the build to no avail.
Building on Windows 10 - Python 3.9 - PyInstaller 5.0.1
Any help would be great!
Taken from the comments on the original answer. Quote stevod:
I ended up finding the problem, our company anti virus wouldn't let the bootloader access the required files, so we had to rebuild the bootloader manually and then it worked!
The same worked also for me.
I am creating a bot and I am using libs like pandas, numpy and sklearn and I have also installed all these libraries in a virtual env. The bot works fine on Pycharm but when I use pyinstaller and create a standalone, it's standalone shows this error:
Traceback (most recent call last):
File "PyInstaller\loader\pyiboot01_bootstrap.py", line 167, in __init__
File "ctypes\__init__.py", line 373, in __init__
FileNotFoundError: Could not find module 'C:\Users\vabha\AppData\Local\Temp\_MEI38962\sklearn\.libs\vcomp140.dll' (or one of its dependencies). Try using the full path with constructor syntax.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "chandlerbing.py", line 3, in <module>
from sklearn.pipeline import Pipeline
.
.
.
Console debbug say FileNotFoundError... Let me translate it for you.
vcomp140.dll is missing and need to be used you had it on temporary location and now is not any more. Try also look on this answer or you can try also Auto Py To Exe maybe will work.
You need to have all the libraries installed in the same environment as pyinstaller. You probably installed pyinstaller in a global environment so you should install the libraries in the globa environment.
I am using ITKPython,
My codes are working well in PyCharm with *.py format but after making a standalone *.exe file via PyInstaller some errors occure as follow:
Traceback (most recent call last):
File “RSG_V_0.py”, line 27, in <module>
File “site-packages\itkExtras.py”, line 449, in imread
File “site-packages\itkLazy.py”, line 40, in getattribute
AttributeError: ‘LazyITKModule’ object has no attribute ‘ImageFileReader’
[29316] Failed to execute script RSG_V_0
Would you please show me the way to solve these kind of problems.
By the way, already I test my PyInstaller with a simple print.py, In fact PyInstaller is working correctly without ITK filters.
Thanks
Sina
That is most likely a problem in PyInstaller. Report it on their issue tracker.
I'm trying use py2exe to compile an eye tracking experiment written in Python 2.7 (32-bit). The experiment uses the psychopy library. I wrote the experiment using the PyCharm IDE, and the experiment runs when I run it through the PyCharm IDE, using an interpreter in a virtual environment located at C:\Users\phil\Python_2.7_32-bit.
The experiment compiles without generating any errors when I enter the following command into the command prompt: C:\Users\phil\Python_2.7_32-bit\Scripts\python.exe C:\Users\phil\PycharmProjects\iTRAC\VisSearch\setup.py py2exe.
When I run the executable generated by the above py2exe command, I get this error:
Traceback (most recent call last):
File "VisualSearch.py", line 3, in <module>
File "psychopy\__init__.pyc", line 39, in <module>
File "psychopy\preferences\__init__.pyc", line 5, in <module>
File "psychopy\preferences\preferences.pyc", line 172, in <module>
File "psychopy\preferences\preferences.pyc", line 33, in __init__
File "psychopy\preferences\preferences.pyc", line 98, in loadAll
File "psychopy\preferences\preferences.pyc", line 146, in loadAppData
File "psychopy\preferences\configobj.pyc", line 583, in __getitem__
KeyError: 'builder'
My setup.py script is as follows:
from distutils.core import setup
import py2exe
setup(windows =['C:\Users\phil\PycharmProjects\iTRAC\VisSearch\VisualSearch.py'])
I've also tried using the following setup.py script with the same results:
from distutils.core import setup
import py2exe
setup(windows = [{'script':'C:\Users\phil\PycharmProjects\iTRAC\VisSearch\VisualSearch.py',
'options' : {'py2exe':{'includes':['psychopy'],
'compressed': True,
'bundle_files': 1,}}}])
I googled the error and came up with 0 results.
Can anybody tell me why I am running into this error?
This is probably a missing config/prefs file. PsychoPy uses the configobj library to read and validate preferences but my guess is that py2exe is only automatically packaging py/pyc files and needs to include the .spec files in the psychopy/preferences folder.
I am fighting a few hours trying to configure PyCharm for debugging my app. I was looking for solution, but twisted seems to not be so popular and there is weak support. Below I put error log that i got.
/usr/local/bin/python3.4m -u /Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_run_in_console.py 57276 57277 /usr/bin/twistd -y /Users/artur/projs/private/elanga-web/start_app.tac
Running /usr/bin/twistd
PyDev console: starting.
Traceback (most recent call last):
File "/usr/bin/twistd", line 7, in <module>
import _preamble
ImportError: No module named '_preamble'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_run_in_console.py", line 68, in <module>
globals = run_file(file, None, None)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_run_in_console.py", line 28, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/usr/bin/twistd", line 9, in <module>
sys.exc_clear()
AttributeError: 'module' object has no attribute 'exc_clear'
Process finished with exit code 1
Couldn't connect to console process.
I will be grateful for an answer why there is no such module like _preamble
On OS X, /usr/bin/twistd is a version of Twisted installed into the system python. This is not python 3.4. The symptom you're seeing is not the missing _preamble module (which is in fact not supposed to be installed, which is why there is an except block around that import catching the exception) but rather that you have pointed python 3.4 at some random python 2 program.
If you want to run python 3.4, you need to create a python 3 environment with Twisted installed. Keep in mind that not all of Twisted is ported, so only a subset of APIs will be available to you. One of the things that is not ported to python 3 yet is the twistd command line, so there's no way to run twistd with python 3 yet.