cx_Freeze pygame error - python

i've recently started working with pygame and wanted to create an executable using cx_Freeze but i encounter an error every time i try to run my exe file.
Fatal Python error: initfsencoding: unable to load the file system codec
ImportError: invalid flags 1530097318 in 'encodings'
Current thread 0x000016f0 (most recent call first):
Here's my setup.py file:
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "C:\\Python37-64\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Python37-64\\tcl\\tk8.6"
executables=[cx_Freeze.Executable('snk.py')]
cx_Freeze.setup(
name='Snake',
options={'build_exe':{'packages':['pygame'], 'include_files':['beep.wav', 'lost.wav', 'apple.png', 'snakehead2.png', 'apple2.png', 'tail.png', 'C:\\Windows\\Fonts\\MAGNETOB.TTF']}},
description='Snake Game',
executables=executables
)
Can someone please help.

As I answered here.You are using python 3.7. As far as I have tested , modules like pyinstaller and cx_freeze don't seem to be working in this version. Try uninstalling your python (don't forget to backup your files before), and installing python 3.6.3 or any other python 3 version except python 3.7.

Related

Python cx_Freeze import _tkinter and ImportError: DLL load failed %1 is not a valid win32 application ERROR

cx_Freeze import _tkinter #if this fails your python may not be configurated for Tk.. ImportError: DLL load failed: %1 is not a valid win32 application
Hi! I created a word guessing/memorizing language practice program in tkinter, and i wanted to convert it to an executable app but i get errors again and again... I tried at least 10-15 different ways but it is still same. So i googled all the similar topics and tried every single suggestion but they did not work for me. I tried pyinstaller as well. It does not give an error but also it does not run the executed app either. When i click on the app.exe, black CMD screen appears then disappears and it creates the csv file to save the words. So i changed to cx_Freeze but it does not work either.
What have i tried?
For pyinstaller:
I converted my app.py to app.exe by using pyinstaller -F app.py and pyinstaller app.py, but none of them worked.
For cx_Freeze
1- I tried my old setup.py (which worked to convert my all games to .exe) but it did not work on this, i guess it is about tkinter. Because my games were written with pygame, i did not use tkinter for anything.
2 -I tried at least 10 different setup files shared by you guys on stackoverflow and other websites. But they did not work either.
3- I tried to set environment
4- I tried to specify environment
5- I copied tcl86t.dll and tk86t.dll files from the python dlls to my app directory and added them as included files in the setup.py
6- I deleted 64bit version and i only have 32bit version of python3.7
and more and more...
So this is my current setup.py
import sys,os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = "C:\Python37\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\Python37\tcl\tk8.6"
build_exe_options = {"packages": ["os"],"includes":["tkinter"],"include_files": []}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "App",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)]
)
I use Windows7 64bit and Python 3.7.1 32bit and 3.7.0 64bit
So what should i do? I am stuck here. I really gave up and asking a new question on here. Please help me guys.. Thanks in advance.

Errors when freezing a Python application with cx_Freeze

I'm trying to build a program in Python 3.6, but I've been struggling to get a functional .exe out. The packing script looks like it completes, but the resulting program instantly crashes. I've had similar issues with py2exe and pyinstaller even when using earlier versions of python 3, but I was able to get the following error out of cx_freeze 5.0.1's executable:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000019a0 (most recent call first):
Searching around this has been mentioned before in relation to unix systems, but I'm doing this on Windows 10?
Here's the packaging script:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Program Files (x86)\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files (x86)\\Python36-32\\tcl\\tk8.6"
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
base = None
#'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('WorkingScript.py', base=base, targetName = 'WorkingScript.exe', icon='IconSml.ico')]]
includefiles=["Logo3.png", "Image4.png", "IconSml.ico"]
setup(name='WorkingScript',
version = '0.9',
description = 'This time around',
options = dict(build_exe = buildOptions),
executables = executables)
The only modules my program imports are tkinter, PIL, os, threading, csv and xml.dom.

Error using cx_freeze and PyInstaller to make an .exe file in Python (which includes xlwings)

Yesterday I asked a question about using Excel and Python simultaneously. The solution was found: using xlwings package.
However, there is another problem connected with that - I can not save my .py file as an executable file (exe).
Here is the code I try to save:
doiterations.py
import xlwings as xl
import numpy
import time
wb = xl.Workbook.active()
sheet = wb.active
iter = input("How many iterations do you need? \n")
i = 0
cell1 = raw_input("Write a column where you need to iterate \n")
cell2 = int(raw_input("Write a row where you need to iterate \n"))
while True:
i += 1
if i <= iter:
arg = numpy.random.uniform()
xl.Range("%s%d" % (cell1, cell2)).value = arg
else:
break
wb.save()
print("Done!")
time.sleep(2)
I tried to use cx_freezer and made a setup.py file with the following code:
from cx_Freeze import setup, Executable
setup(
name = "Uniform distribution generator",
version = "1.0",
description = "Uniform distribution generator",
executables = [Executable("doiterations.py")]
)
Such setyp.py files with the similar code properly worked with other modules. However, this time I got an error no file named sys:
cx_Freeze.freezer.ConfigError: no file named sys (for module collections.sys)
I tried to use PyInstaller package with the following command:
and again faced an error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 7: ordinal not in range(128)
I searched through Google and Stackoverflow and found some comments on this problem that may help to find the solution:
https://mborgerson.com/creating-an-executable-from-a-python-script
http://www.dreamincode.net/forums/topic/192592-making-an-exe-file-with-pyinstaller/
cx_freeze fails to create exe with pandas library
cx-freeze error on build
Traceback from CX_Freeze doesn't make sense
My version of Python is 2.7.
Please, help to solve the problem and create a working executable file!
At least in the case of cx_freeze an explanation can be found: https://bitbucket.org/anthony_tuininga/cx_freeze/issues/127/collectionssys-error
Unfortunately Python Package Index does not provide a version of cx_freeze that includes the necessary changes. A new version of cx_Freeze can be installed after Microsoft Visual C++ Compiler for Python 2.7 has been installed. It is possible to install python packages from other locations than Python Package Index with pip command, in this case
pip install --upgrade https://bitbucket.org/anthony_tuininga/cx_freeze/get/tip.zip
This needs to be done in Anaconda prompt that should be found from the Start menu. command prompt suffices if the PATH has been modified during the installation of Anaconda.

Installing Audiere Module on Python 2.7 Windows 7

I have downloaded the module from sourceforge. audiere-1.9.4-win32
The unzipped folder has the following folders:
-bin
-bindings
-doc
-include
-lib
The Bindings folder includes a file called audiere.pyd and an installation instruction which says:
Into the Windows distribution of Python 2.2:
Copy audiere.dll and audiere.pyd into your Python22 directory (or
perhaps Python22/DLLs, depending on your system).
I tried copying both files to:
-python 2.7/
-python 2.7/DLL
-python 2.7 /LIb/site-packages/ directory but
import audiere
still gives a import error:
Traceback (most recent call last):
File "", line 1, in
import audiere
ImportError: DLL load failed: The specified module could not be found.
I am sure this is nothing to do with python 2.2 versus python 2.7 because people have successfully used audiere on 2.7 without any modification.
How do I install audiere on windows 7.
You can try to use pyglet. This library has the capability to play using external library called Avbin.
Simple example of how to use:
import pyglet
music = pyglet.resource.media('music.mp3')
music.play()
pyglet.app.run()
If you have some problems with avbin, put the dll in the same directory of your code and insert this two lines before "pyglet.resource.media('music.mp3')":
pyglet.lib.load_library('avbin')
pyglet.have_avbin=True

Using Eclipse with PyWin32

I am running Eclipse (Indigo) with PyDev, Python 2.6 and PyWin32 (build 217, 32 bit), and having a problem that gets stranger the more I investigate.
I'm running a Python program that imports the following 3 libraries:
import win32con
import win32file
import pywintypes
win32con imports properly but win32file does not (note: win32con is a pyc and win32file is a pyd, in raw Python):
Traceback (most recent call last):
File "....\dynamic\testpywin32.py", line 2, in <module>
import win32file
ImportError: DLL load failed: The specified module could not be found.
I tried the equivalent in pure Python 2.6 (IDLE) and everything imported properly.
Comparing sys.path in IDLE and Eclipse, the only thing not in Eclipse is ['C:\Python26\Lib\idlelib']; the only extra thing Eclipse has (besides the workspace) is C:\eclipse\plugins\org.python.pydev.debug_2.2.4.2011121401\pysrc.
In addition, I went on and used the following commands right after startup, through the debugger:
sys.path = [sys.path from IDLE]
os.environ['PATH'] = [os.environ['PATH'] from IDLE]
which didn't seem to help.
What's going on here?
which windows version are you using??
i am using windows XP + pydev plugin and its works.
go to python path and try to fix the python eggs path, and press apply

Categories