I am writing a python (pgzero) project for a simple game with my teacher, but I wanted to improve it a bit. After adding something like a minimap, everything was fine, but after writing the next stage of the code, it stopped working completely. For other students who prescribed code identically to the teacher, everything works properly, unfortunately for me, it does not. Thank you in advance for any help. If more project code is needed I can share.
Terminal error:
Traceback (most recent call last):
File "C:\Users\Olek\AppData\Local\Programs\Python\Python38\lib\site-packages\pgzero\clock.py", line 168, in tick
cb()
File "C:/Users/Olek/PycharmProjects/gra_mars_alfa/gra.py", line 533, in petla_glowna
if mapa_pom[bohater_y][bohater_x] not in ob_mozna_stac:
NameError: name 'mapa_pom' is not defined
If I'm using terminal to run project terminal says:
PS C:\Users\Olek\PycharmProjects\gra_mars_alfa> pgzrun gra.py
pygame 2.1.0 (SDL 2.0.16, Python 3.8.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "c:\users\olek\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\olek\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Olek\AppData\Local\Programs\Python\Python38\Scripts\pgzrun.exe\__main__.py", line 7, in <module>
File "c:\users\olek\appdata\local\programs\python\python38\lib\site-packages\pgzero\runner.py", line 77, in main
src = f.read()
File "c:\users\olek\appdata\local\programs\python\python38\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 24633: character maps to <undefined>
I says that the class: mapa_pom is not defined.
Meaning that mapa_pom[][] is not what you wanted to use
your error is:
NameError: name 'mapa_pom' is not defined
your code is:
if mapa_pom[bohater_y][bohater_x] not in ob_mozna_stac:
so you are saying: if hero.x hero.y is not in list where_you_can_stand:
'code here'
if map[hero.x][hero.y] not in where_you_can_stand:
'code here'
variable error example:
print(i)
Traceback (most recent call last):
File "/home/pi/mu_code/i.py", line 1, in
print(i)
NameError: name 'i' is not defined
an_actor = Actor('not_here', anchor=('center', 'middle'))
Traceback (most recent call last):
File "/home/pi/mu_code/i.py", line 1, in
an_actor = Actor('not_here', anchor=('center', 'middle'))
NameError: name 'Actor' is not defined
If this doesn't work please show me where in the code where you use mapa_pom and I might be able to answer it better.
Related
I am trying to set up the ChirpSDK, but every time I configure and run the code, I get this error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
chirp = ChirpSDK()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 395, in __init__
self.read_chirprc(block)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 501, in read_chirprc
raise IOError('Could not find a ~/.chirprc file')
OSError: Could not find a ~/.chirprc file
Exception ignored in: <function ChirpSDK.__del__ at 0x10fa31af0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 422, in __del__
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 470, in close
if self._sdk:
AttributeError: 'ChirpSDK' object has no attribute '_sdk'
I realize that the error is saying that my .chirprc file is not being recognized, but I have no idea how to remedy this. I created a .chirprc file in my /Users/username/ path, and named it c.chirprc (as the Chirp getting started article suggests), but I am still getting this error. Is there another part that I am missing? Am I reading the instructions wrong?
Thanks
The Chirp configuration file should be placed at /Users/<username>/.chirprc on macOS.
If you run ls -l ~/.chirprc in the terminal, do you get any results? If it displays no such file or directory then you have not created the file correctly.
So I tried to convert my midi file to ogg and I still cant get it to work... hope some of you can help me?
This is my code:
showTextScreen('Tetromino')
while True: # game loop
if random.randint(0, 1) == 0:
pygame.mixer.music.load('tetrisb.mid')
else:
pygame.mixer.music.load('tetrisc.mid')
pygame.mixer.music.play(-1, 0,0)
runGame()
pygame.mixer.music.stop()
showTextScreen('Game Over')
It gives the error that it cant open tetrisb.mid
I tried renaming it and it still says the same...
If i can fix this I can fix the other file probably
Here is the error:
Traceback (most recent call last):
File "H:\Programmering\Python\TETRIS!.py", line 487, in <module>
main()
File "H:\Programmering\Python\TETRIS!.py", line 166, in main
pygame.mixer.music.load('tetrisc.mid')
pygame.error: Couldn't open 'tetrisc.mid'
I'm using windows and python 3.8 and i dont mind if im using midi or ogg...
I changed my midi file into ogg, hoping it would fix the problem but it didnt.
My file is ogg atm
It looks like you need to supply the correct path to your midi file. This question about how to check for file existence might also be helpful.
The error messages from pygame.mixer.music.load are different if the file format is not supported or non-existent:
>>> pygame.mixer.music.load("nonexistent.file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Couldn't open 'nonexistent.file'
>>> pygame.mixer.music.load(r"c:\tmp\empty.file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Couldn't read from RWops
>>> pygame.mixer.music.load(r"c:\tmp\robots.txt")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pygame.error: Module format not recognized
>>> pygame.mixer.music.load(r"C:\Windows\media\flourish.mid")
>>> pygame.mixer.music.play(-1, 0)
>>> pygame.mixer.music.stop()
Note that when specifying a file path a \ is an escape character which is processed differently. So you can use \\ instead, or put an r at the start of the string, before the quotation mark as I've shown above.
My final purpose is to convert a running Python project to Jython interpreter because some java API's are going to be added.
Details:
The latest Jython is 2.7
The project I have is runnable with Python 3.5
So I took the following approach:
First thing was to convert my project to Python 2.7 utilizing the future module and pasteurize executable.
This step was done successfully.
Second thing is to convert the Python 2.7 project to a Jython 2.7 Project.
Switching the interpreter at Eclipse mars, the following error was indicated:
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
To workaround it, the solution from this post was utilized by passing the encoding argument -Dpython.console.encoding=UTF-8 to the java VM according to figure below:
Thumbs were up when trying to run again. But unfortunately here, the error shown below just appeared. As I don't plan to change any imported module if there's no need to do so, I decided to ask help here.
pydev debugger: starting (pid: 4216)
Traceback (most recent call last):
File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 2364, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Users\souzadan\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydevd.py", line 1784, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Users\souzadan\FirmwareDevTools\Workspaces\Eclipse\aPythonWorkspace\aPythonProject\aPythonFolder\aPythonFile.py", line 7, in <module>
standard_library.install_aliases()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
from future.backports.urllib import request
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
from future.backports import email
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
from future.utils import surrogateescape
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
t.join()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Error in sys.exitfunc:
Traceback (most recent call last):
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 297, in _MainThread__exitfunc
t.join()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\threading.py", line 128, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
Running Jython through the command line results in a shorter error log:
Traceback (most recent call last):
File "somePythonCode.py", line 7, in <module>
standard_library.install_aliases()
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\standard_library\__init__.py", line 465, in install_aliases
from future.backports.urllib import request
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\urllib\request.py", line 96, in <module>
from future.backports import email
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\backports\email\__init__.py", line 16, in <module>
from future.utils import surrogateescape
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 167, in <module>
FS_ENCODING = 'ascii'; fn = b('[abc\xff]'); encoded = u('[abc\udcff]')
File "C:\Users\souzadan\FirmwareDevTools\Compilers\Jython2.7.0\Lib\site-packages\future-0.15.2-py2.7.egg\future\utils\surrogateescape.py", line 25, in u
return text.decode('unicode_escape')
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 4-10: illegal Unicode character
Does anybody have a clue of how to solve this error in the most elegant manner?
A bug was created at Jython.org with a critical severity because many people are utilizing already the latest Python modules and interpreter. And they might want to add Java functionality to their code. So they would basically have to take same path as I did. Backporting the project to Python 2.7 then to Jython 2.7 subsequentely.
At python-future a feature request bug was recorded too.
Relying on py4j, as Roland Smith suggests, would be a good approach for porting your app to a JVM environment.
I have checked that the file in my disk is the same as https://github.com/scipy/scipy/blob/master/scipy/misc/face.dat
but when I run this statement ,I have got this error. why ?
scipy.misc.face()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\scipy\misc\common.py", line 567, in face
data = bz2.decompress(rawdata)
ValueError: couldn't find end of stream
It's a bug (on Windows), see here
https://github.com/scipy/scipy/commit/7f0210fd28a2b3be79806d5cae462be52c1601e9
What's wrong in python script?
Code:
import os
import shutil
import getpass
os.mkdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\bb-freeze-script.py","C:\\dtmp")
os.chdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\main.py","C:\\dtmp")
os.system("python bb-freeze-script.py main.py")
os.mkdir("C:\\Program Files\\Directories v0.6")
os.chdir("C:\\")
shutil.rmtree("C:\\dtmp")
print getpass.getuser()
Error:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
File "C:\dtmp\main.py", line 14
^
IndentationError: expected an indented block
Operating system -- Windows XP
Here's a quick walkthrough on how to read tracebacks. It's pretty easy.
Looking through your code, all of it is calling Python builtin modules. It's safe to say they're not causing the error, so the only thing left is the os.system call. Sure enough, you're calling python through said call (why would you not just import the module you want to call?).
The traceback confirms that the error is in the other Python you are calling:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
Next, read through the lines of the transcript to burrow through the call stack and find out exactly where the error occurred.
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
until you get to
File "C:\dtmp\main.py", line 14
IndentationError: expected an indented block
There you go, the error is in line 14 of main.py, where you should have had an indent but didn't.