I am unable to turn a game I made from a tutorial on youtube into an executable with cx_Freeze. I'm using virtualenv and cx_Freeze is version 5.0. When running the game I get a message:
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x00002c24 (most recent call first):
Below is the trace backs when creating the file.
(pygame) G:\Programming\scripts\Python\PyGame\compile_files>python setup.py build
running build
running build_exe
creating directory build\exe.win32-3.5
copying G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win32-3.5\Slither.exe
copying G:\Programming\scripts\Python\virtualenv\pygame\Scripts\python35.dll -> build\exe.win32-3.5\python35.dll
Traceback (most recent call last):
File "setup.py", line 12, in <module>
executables=executables
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "G:\python\Python35-32\Lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "G:\python\Python35-32\Lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "G:\python\Python35-32\Lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "G:\python\Python35-32\Lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "G:\python\Python35-32\Lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "G:\python\Python35-32\Lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 623, in Freeze
self._FreezeExecutable(executable)
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 225, in _FreezeExecutable
self._AddVersionResource(exe)
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 165, in _AddVersionResource
trademarks = exe.trademarks)
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 759, in __init__
parts = version.split(".")
AttributeError: 'NoneType' object has no attribute 'split'
(pygame) G:\Programming\scripts\Python\PyGame\compile_files>`
My setup file is:
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "G:\\python\\Python35-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "G:\\python\\Python35-32\\tcl\\tk8.6"
executables=[cx_Freeze.Executable("Game.py")]
cx_Freeze.setup(
name="Game",
options={"build_exe":{"packages":["pygame"],"include_files":["image1.png","image2.png"]}},
description="Game",
executables=executables
)
The images are in the same directory as the setup.py file.
Use this in your setup file:
from cx_Freeze import setup,Executable
setup(name="NAME OF YOUR PROGRAM",
version="1.0",
description="as above",
executables=[Executable("NAME OF THE SCRIPT.py")])
After that, drag your png files to the folder into the same folder with your program.
python setup.py build
Finally put your png,jpg etc. files into that folder.
Related
I have Python 3.8 on a windows 10 64bit. I had some trouble installing cx-Freeze and had to install "cx_Freeze-6.0-cp38-cp38-win32.whl", as it was the only one that worked.
I am trying to convert a script that generates a simple GUI using wxPyhton to an executable.
I get the following error when i run "steup.py build"
running build
running build_exe
.....
copying C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\VCRUNTIME140.dll -> build\exe.win32-3.8\VCRUNTIME140.dll
Traceback (most recent call last):
File "setup.py", line 21, in <module>
setup(name='editor',
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cx_Freeze\dist.py", line 348, in setup
distutils.core.setup(**attrs)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cx_Freeze\freezer.py", line 617, in Freeze
self._FreezeExecutable(executable)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cx_Freeze\freezer.py", line 208, in _FreezeExecutable
self._AddVersionResource(exe)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\cx_Freeze\freezer.py", line 143, in _AddVersionResource
stamp(fileName, versionInfo)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32\lib\win32verstamp.py", line 157, in stamp
vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug, is_dll)
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32\lib\win32verstamp.py", line 103, in VS_VERSION_INFO
result = result + nullterm('VS_VERSION_INFO')
File "C:\Users\ptanas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32\lib\win32verstamp.py", line 50, in nullterm
return (str(s) + '\0').encode('unicode-internal')
LookupError: unknown encoding: unicode-internal
I have no idea why this error appears.
setup.py:
import os
import sys
from cx_Freeze import Executable, setup
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(
packages = [],
excludes = [],
include_files=[]
)
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('test.py', base=base)
]
setup(name='editor',
version = '1.0',
description = '',
options = dict(build_exe = buildOptions),
executables = executables)
It's fixed: https://github.com/mhammond/pywin32/commit/74f9d8b8b549ff0d547ff600eaca1f25c79b4432.
Upgrade pywin32:
pip install -U pywin32
So I have a script called papercutter.py and a setup.py that is set up as follows according to the py2exe tutorial:
from distutils.core import setup
import py2exe
setup(console=['papercutter.py'])
So following the tutorial, i run python setup.py py2exe and it looks successful:
c:\Codes>python setup.py install
running install
running build
running install_egg_info
Removing C:\Python\Lib\site-packages\UNKNOWN-0.0.0-py3.6.egg-info
Writing C:\Python\Lib\site-packages\UNKNOWN-0.0.0-py3.6.egg-info
but when I run the next step, python setup.py py2exe, I get error:
c:\Codes>python setup.py py2exe
running py2exe
Traceback (most recent call last):
File "setup.py", line 4, in <module>
setup(console=['papercutter.py'])
File "C:\Python\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Python\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Python\lib\site-packages\py2exe\runtime.py", line 157, in analyze
self.mf.import_package(modname[:-2])
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 91, in import_package
self.import_hook(name)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 320, in _ find_and_load
self._scan_code(module.__code__, module)
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 352, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Python\lib\site-packages\py2exe\mf3.py", line 381, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
What am I doing wrong here?
Note: this is the tutorial I am following: http://www.py2exe.org/index.cgi/Tutorial
Also note: I am using py2exe 0.9.2.0 and python 3.6.0. I think these should be fine together.
The answer is at the bottom of the Traceback. Seems like you have an indexing problem with a tuple. Indexes are 0 based in Python.
Currently py2exe supports Python up to 3.4
I'm trying to convert a python 3.4 program of mine into an exe for distribution. I tried using cx_Freeze to do this. However, when I run python setup.py build with this setup.py:
from cx_Freeze import setup, Executable
setup( name = "Converter" ,
version = "0.1" ,
description = "" ,
executables = [Executable("filename.py")] , )
I get this error code:
C:\Python34>python setup.py build
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 6, in <module>
executables = [Executable("helloworld.py")] , )
File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "C:\Python34\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\distutils\command\build.py", line 126, in run
self.run_command(cmd_name)
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 231, in run
metadata = metadata)
File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 136, in __init__
self._VerifyConfiguration()
File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 504, in _VerifyConfiguration
self._GetBaseFileName()
File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 239, in _GetBaseFileName
raise ConfigError("no base named %s", name)
cx_Freeze.freezer.ConfigError: no base named Console
This same error code occurs when I try to setup for a hello world file. So it has nothing to do with my script.
Any help? This is the first time I've used cx_Freeze.
It appears that this line is failing argsSource.base = self._GetFileName("bases", name, ext) which means that it can't find that file, which makes sense. Check this folder C:\Python27\Lib\site-packages\cx_Freeze\bases for Console.exe. If you don't have that then try reinstalling cx_freeze. That's my directory for python. I would assume yours is in the same place but if not just search for it
Just type in cmd "pip uninstall cx_Freeze" for uninstall cx_Freeze and again reinstall it by type "pip install cx_Freeze".
I have python 2.7.3 installed on my system an I am trying to install Kobo module. The path where the module is located is:
C:\Users\nelson.menezes\Desktop\new softwares\kobo-0.3.6
.I opened the command promt and set the above mentioned path. Then as specified I run the following command to install Kobo.
python setup.py install
But it gives me the following error
File "c:\python27\lib\distutils\util.py", line 204, in convert_path
raise ValueError, "path '%s' cannot be absolute" % pathname
ValueError: path '/usr/bin' cannot be absolute
I know that it an error generated due to Path problems. But I cannot figure out how to resolve it. It would be great if anyone could help in any possible way.
The full traceback is as follows:
running install
running build
running build_py
running install_lib
running install_data
Traceback (most recent call last):
File "setup.py", line 91, in <module>
scripts = script_files,
File "c:\python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "c:\python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\distutils\command\install.py", line 575, in run
self.run_command(cmd_name)
File "c:\python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\distutils\command\install_data.py", line 58, in run
dir = convert_path(f[0])
File "c:\python27\lib\distutils\util.py", line 204, in convert_path
raise ValueError, "path '%s' cannot be absolute" % pathname
ValueError: path '/usr/bin' cannot be absolute
I have been trying to get cx_freeze working on ubuntu, but when i try to run the "python setup.py build" i get the following error:
cx_Freeze.freezer.ConfigError: no initscript named Console
I have searched google and i see a lot of people have ahd this issue, but i can't seem to find a solution.
my setup.py code is as follows:
from cx_Freeze import setup, Executable
setup( name = "hello world" ,
version = "0.1" ,
description = "Hello" ,
executables = [Executable("hello.py")] ,
)
I have placed the setup.py file and hello.py in the same folder.
Any idea as to what could solve this problem?
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 7, in <module>
executables = [Executable("hello.py")] ,
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
cx_Freeze/dist.py", line 365, in setup
distutils.core.setup(**attrs)
File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run
self.run_command(cmd_name)
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/dist.py", line 234, in run
metadata = metadata)
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/freezer.py", line 104, in __init__
self._VerifyConfiguration()
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/freezer.py", line 466, in _VerifyConfiguration
self._GetInitScriptFileName()
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze-4.3.1-py2.7-linux-i686.egg
/cx_Freeze/freezer.py", line 311, in _GetInitScriptFileName
raise ConfigError("no initscript named %s", name)
cx_Freeze.freezer.ConfigError: no initscript named Console
For my installation I took same problem. Looks like symbolic link for initscripts not created, so I make it manually and everything works (change cx_Freeze version to your own):
cd /usr/local/lib/python2.7/dist-packages/
cd cx_Freeze-4.3.1-py2.7-linux-i686.egg
sudo ln -s -t cx_Freeze/ ../../cx_Freeze/initscripts/
PS: Ubuntu 12.10/quantal, Python 2.7.3