Cx_Freeze executable doesn't work with pygame - python

I am having trouble with creating an executable for my python program with cx_freeze.I am on windows (XP) and my program uses Tkinter, Pygame (and random) and is coded in python 3.2. I have tried creating a distils and running from command prompt:
cxfreeze --target-dir dist
On both I get this error:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 117, in <module>
try: import pygame.display
File "ExtensionLoader_pygame_display.py", line 12, in <module>
File "ExtensionLoader_pygame_surface.py", line 12, in <module>
ImportError: No module named _view
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
exec(code, m.__dict__)
File "BallGame.pyw", line 1, in <module>
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 118, in <module>
except (ImportError,IOError):display=MissingModule("display", geterror(), 1)
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 61, in __init__
self.warn()
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 85, in warn
warnings.warn(message, RuntimeWarning, level)
File "C:\Python32\lib\warnings.py", line 18, in showwarning
file.write(formatwarning(message, category, filename, lineno, line))
File "C:\Python32\lib\warnings.py", line 25, in formatwarning
line = linecache.getline(filename, lineno) if line is None else line
File "C:\Python32\lib\linecache.py", line 15, in getline
lines = getlines(filename, module_globals)
File "C:\Python32\lib\linecache.py", line 41, in getlines
return updatecache(filename, module_globals)
File "C:\Python32\lib\linecache.py", line 127, in updatecache
lines = fp.readlines()
File "C:\Python32\lib\codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x90 in position 2: invalid s
tart byte
Please could you tell me how to fix it, or recommend a different piece of software to turn my python script into executables. Any help is greatly appreciated. Thanks in advance!

You need to run import pygame._view at the start of your script.

Related

'Prophet' object has no attribute 'stan_backend' and there is no answer for me

I want to use Facebook's prophet,however when I try to create a model:
model = prt.Prophet(stan_backend='CMDSTANPY')
It occurs mistake like this:
Traceback (most recent call last):
File "C:\Users\UserName\IdeaProjects\station-simulate\stcd-predict.py", line 24, in <module>
model = prt.Prophet(stan_backend='CMDSTANPY')
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 142, in __init__
self._load_stan_backend(stan_backend)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 153, in _load_stan_backend
self.stan_backend = StanBackendEnum.get_backend_class(stan_backend)()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\models.py", line 67, in __init__
super().__init__()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\models.py", line 23, in __init__
self.model = self.load_model()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\models.py", line 79, in load_model
return cmdstanpy.CmdStanModel(exe_file=model_file)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\cmdstanpy\model.py", line 192, in __init__
do_command(['where.exe', 'tbb.dll'], fd_out=None)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\cmdstanpy\utils\command.py", line 53, in do_command
line = proc.stdout.readline()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
If I don't use stan_backend='CMDSTANPY':
Traceback (most recent call last):
File "C:\Users\k6789\IdeaProjects\station-simulate\stcd-predict.py", line 24, in <module>
model = prt.Prophet()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 141, in __init__
self._load_stan_backend(stan_backend)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 154, in _load_stan_backend
logger.debug("Loaded stan backend: %s", self.stan_backend.get_type())
AttributeError: 'Prophet' object has no attribute 'stan_backend'
I re-setup prophet with micromamba and it has no effect.
How to solve this?
Now I changed another computer and created a new conda environment,solved this.

Installation of pyproj wheel file

Installations:
Windows 10, 64 bit.
Python 3.6.5
I am trying to execute pip install -r pyproj-1.9.6-cp36-cp36m-win_amd64.whl command.
However getting below error:
ERROR: Exception:
Traceback (most recent call last):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
status = self.run(options, args)
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
return func(self, options, args)
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\commands\install.py", line 302, in run
check_supported_wheels=not options.target_dir,
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\cli\req_command.py", line 341, in get_requirements
finder=finder, options=options, session=session):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 151, in parse_requirements
for parsed_line in parser.parse(filename, constraint):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 330, in parse
for line in self._parse_and_recurse(filename, constraint):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 335, in _parse_and_recurse
for line in self._parse_file(filename, constraint):
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 369, in _parse_file
filename, self._session, comes_from=self._comes_from
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\req\req_file.py", line 574, in get_file_content
content = auto_decode(f.read())
File "c:\users\sneka\appdata\local\programs\python\python36\lib\site-packages\pip\_internal\utils\encoding.py", line 41, in auto_decode
locale.getpreferredencoding(False) or sys.getdefaultencoding(),
File "c:\users\sneka\appdata\local\programs\python\python36\lib\encodings\cp1252.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 118: character maps to <undefined>
I am new to python and not able to solve this error. Please help.
Remove -r. It should be pip install pyproj-1.9.6-cp36-cp36m-win_amd64.whl

Python Kivy UnicodeEncodeError

I am new to Kivy and I am trying to do my first app with using Kivy. But in my first attemp I failed and unfortunately I couldn't find any answer from anywhere.
my code is:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class EpicApp(App):
def build(self):
return Label(text="hi there")
if __name__ == "__main__":
EpicApp().run()
My error is simply:
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 280: character maps to < undefined>
my whole error code is:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/burak/Desktop/Stuff/python for fun/kivy basics/kivyapp.py", line 13, in <module>
EpicApp().run()
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\app.py", line 829, in run
root = self.build()
File "C:/Users/burak/Desktop/Stuff/python for fun/kivy basics/kivyapp.py", line 9, in build
return Label(text="hi there")
File "kivy\_event.pyx", line 188, in kivy._event.EventDispatcher.__cinit__
File "kivy\properties.pyx", line 447, in kivy.properties.Property.link
File "kivy\properties.pyx", line 632, in kivy.properties.NumericProperty.init_storage
File "kivy\properties.pyx", line 418, in kivy.properties.Property.init_storage
File "kivy\properties.pyx", line 655, in kivy.properties.NumericProperty.convert
File "kivy\properties.pyx", line 663, in kivy.properties.NumericProperty.parse_str
File "kivy\properties.pyx", line 670, in kivy.properties.NumericProperty.parse_list
File "kivy\properties.pyx", line 296, in kivy.properties.dpi2px
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\utils.py", line 505, in __get__
retval = self.func(inst)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\metrics.py", line 174, in dpi
EventLoop.ensure_window()
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\base.py", line 123, in ensure_window
import kivy.core.window # NOQA
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\window\__init__.py", line 2068, in <module>
Window = core_select_lib('window', window_impl, True)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\__init__.py", line 103, in core_select_lib
'identify potential causes\n{1}'.format(category.capitalize(), err))
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1425, in critical
self._log(CRITICAL, msg, args, **kwargs)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1514, in _log
self.handle(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1524, in handle
self.callHandlers(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 1586, in callHandlers
hdlr.handle(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\logging\__init__.py", line 894, in handle
self.emit(record)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\logger.py", line 247, in emit
self._write_message(message)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\logger.py", line 218, in _write_message
stream.write(fs % msg)
File "C:\Users\burak\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 280: character maps to <undefined>
edit: When I tried to open file from cmd I get this error.(Normally I am using PyCharm)
[ERROR ] [Clock ] Unable to import kivy._clock. Have you perhaps forgotten to compile kivy? Kivy contains Cython code which needs to be compiled. A missing kivy._clock often indicates the Cython code has not been compiled. Please follow the installation instructions and make sure to compile Kivy Traceback (most recent call last): File "kivyapp.py", line 2, in <module>
from kivy.app import App File "C:\Users\burak\AppData\Roaming\Python\Python37\site-packages\kivy\app.py", line 319, in <module>
from kivy.base import runTouchApp, stopTouchApp File "C:\Users\burak\AppData\Roaming\Python\Python37\site-packages\kivy\base.py", line 26, in <module>
from kivy.clock import Clock File "C:\Users\burak\AppData\Roaming\Python\Python37\site-packages\kivy\clock.py", line 363, in <module>
from kivy._clock import CyClockBase, ClockEvent, FreeClockEvent, \ ModuleNotFoundError: No module named 'kivy._clock'

Getting Unknown encoding: idna and then unable to debug in python PyDev plugin on eclipse

Colleague provided me set of py files for testing, which are running fine on his machine. However when I run the py files, I am getting following error:
Traceback (most recent call last):
File "D:\workspaces\pyworkspace\Analytics Python\python_server\server1.py", line 84, in <module>
start_server()
File "D:\workspaces\pyworkspace\Analytics Python\python_server\server1.py", line 57, in start_server
socketObj.bind(server_address)
LookupError: unknown encoding: idna
Here, it says to add import encodings.idna. So I added that import (even though eclipse says "unused import"), but still getting the same error. So I put some breakpoints and started up debugging, but debugger didnt hit the breakpoints. The program termniates without hitting any breakpoints giving following error:
pydev debugger: starting (pid: 8316)
Traceback (most recent call last):
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 741, in _pydevd_bundle.pydevd_cython_win32_34_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_34_64.c:15515)
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 254, in _pydevd_bundle.pydevd_cython_win32_34_64.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython_win32_34_64.c:5631)
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 764, in do_wait_suspend
self._activate_mpl_if_needed()
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 416, in _activate_mpl_if_needed
activate_function()
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 407, in <lambda>
self.mpl_modules_for_patching = {"matplotlib": lambda: activate_matplotlib(do_enable_gui),
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydev_ipython\matplotlibtools.py", line 93, in activate_matplotlib
is_interactive = is_interactive_backend(backend)
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydev_ipython\matplotlibtools.py", line 56, in is_interactive_backend
from matplotlib.rcsetup import interactive_bk, non_interactive_bk # #UnresolvedImport
ImportError: cannot import name 'interactive_bk'
Traceback (most recent call last):
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 1621, in <module>
main()
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 1615, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 1022, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:\Mahesh\workspaces\pyworkspace\Analytics Python\python_server\server.py", line 84, in <module>
start_server()
File "D:\Mahesh\workspaces\pyworkspace\Analytics Python\python_server\server.py", line 84, in <module>
start_server()
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 982, in _pydevd_bundle.pydevd_cython_win32_34_64.SafeCallWrapper.__call__ (_pydevd_bundle/pydevd_cython_win32_34_64.c:19346)
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 498, in _pydevd_bundle.pydevd_cython_win32_34_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_34_64.c:18639)
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 750, in _pydevd_bundle.pydevd_cython_win32_34_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_34_64.c:15669)
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 741, in _pydevd_bundle.pydevd_cython_win32_34_64.PyDBFrame.trace_dispatch (_pydevd_bundle/pydevd_cython_win32_34_64.c:15515)
File "_pydevd_bundle\pydevd_cython_win32_34_64.pyx", line 254, in _pydevd_bundle.pydevd_cython_win32_34_64.PyDBFrame.do_wait_suspend (_pydevd_bundle/pydevd_cython_win32_34_64.c:5631)
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 764, in do_wait_suspend
self._activate_mpl_if_needed()
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 416, in _activate_mpl_if_needed
activate_function()
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydevd.py", line 407, in <lambda>
self.mpl_modules_for_patching = {"matplotlib": lambda: activate_matplotlib(do_enable_gui),
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydev_ipython\matplotlibtools.py", line 93, in activate_matplotlib
is_interactive = is_interactive_backend(backend)
File "D:\Programs\Eclipse Oxygen\plugins\org.python.pydev_6.2.0.201711281614\pysrc\pydev_ipython\matplotlibtools.py", line 56, in is_interactive_backend
from matplotlib.rcsetup import interactive_bk, non_interactive_bk # #UnresolvedImport
ImportError: cannot import name 'interactive_bk'
Why is this happening? (I am using python 3.4, eclipse oxygen 4.7 and PyDev 6.2.0.201711281614)
Apparently the problem is because pydev is expecting matplotlib to have some modules which aren't available in your installation... so, the import:
from matplotlib.rcsetup import interactive_bk, non_interactive_bk # #UnresolvedImport
is failing (and that's expected in PyDev if you have matplotlib installed).
Not sure why... I need to investigate whether you have a broken matplotlib or if matplotlib actually changed (in which case the pydev debugger would need to be fixed).
Can you add details on the matplotlib version you have?

sublime text when open browser unicodeEncodeError

Traceback (most recent call last):
File "/Applications/Sublime
Text.app/Contents/MacOS/sublime_plugin.py", line 818, in run_
return self.run(edit)
File "open_in_browser in /Applications/Sublime
Text.app/Contents/MacOS/Packages/Default.sublime-package", line 9, in run
File "./python3.3/webbrowser.py", line 70, in open_new_tab
File "./python3.3/webbrowser.py", line 62, in open
File "./python3.3/webbrowser.py", line 635, in open
UnicodeEncodeError: 'ascii' codec can't encode characters in position
56-57: ordinal not in range(128)
How can i fix this? I use the plugin SidebarEnhancements to open my html,but I meet this problem.

Categories