Pygame application instantly closes when opened [duplicate] - python

Always, when I want to use Python framework pygame and I want to compile it, it's printing this:
Traceback (most recent call last):
File "/home/hanisek/game.py", line 1, in <module>
import pygame
File "/home/hanisek/pygame.py", line 3
03f3 0d0a 5fff 9355 6300 0000 0000 0000
^
SyntaxError: invalid syntax
Do you know why?

You are not importing pygame the framework, you are importing pygame.py, a file in the same directory:
import pygame
File "/home/hanisek/pygame.py", line 3
Remove or rename that file.

Related

Why am I getting traceback and value errors when trying to run NLTK import?

I have downloaded NLTK-3.5 and successfully ran the pip install nltk command. When running 'import nltk' in Python 3.8, I am getting the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Python\Python38\lib\site-packages\nltk_init_.py", line 128, in
from nltk.collocations import *
File "C:\Python\Python38\lib\site-packages\nltk\collocations.py", line 39, in
from nltk.metrics import (
File "C:\Python\Python38\lib\site-packages\nltk\metrics_init_.py", line 16, in
from nltk.metrics.scores import (
File "C:\Python\Python38\lib\site-packages\nltk\metrics\scores.py", line 15, in
from scipy.stats.stats import betai
ValueError: source code string cannot contain null bytes
I have tried uninstalling and reinstalling, open the files listed and deleting spaces (that generates indentation errors) and just don't know what to do next.
Any suggestions for solving this problem?
Thank you!
Genie

pyinstaller error, exe compilation error?

music player programming. ran into a problem. The program should play the file that I run using my program. For this, I formatted the code in exe. When I started using my exe an error occurred
Traceback (most recent call last):
File "MP3.py", line 13, in <module>
File "MP3.py", line 7, in music
pygame.error
[1980] Failed to execute script MP3
MP3.py -my python code/
import pygame
import sys
f = str(sys.argv[1])
print(f)
def music(f):
pygame.init()
clock = pygame.time.Clock()
pygame.mixer.music.load(f)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.mixer.init(22050,-16,2)
music(f)
various methods do not help.
although the code with music playback works shortly and in exe as well as the output of the file that I launch by the program
this error
C:\Users\Acer\Documents\Projects\MP3\Test.mp3
Traceback (most recent call last):
File "MP3.py", line 15, in <module>
music(f)
File "MP3.py", line 9, in music
pygame.mixer.music.load(f)
pygame.error
[17280] Failed to execute script MP3
You should first use pygame.mixer.init before using mixer to do anything you want. You can refer to this document for details about how to tweak the parameters of the mixer.

Python Arcpy: Non-ASCII character in library import

I was debugging a basic GIS python script, when I randomly(?) got this error:
Traceback (most recent call last):
File "<module1>", line 13, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\__init__.py", line 25, in <module>
from arcpy.toolbox import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\toolbox.py", line 371, in <module>
from .management import Graph, GraphTemplate
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 5694
SyntaxError: Non-ASCII character '\xc2' in file C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py on line 5695, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Tried just running import arcpy and the same error popped up. So far here's what I tried:
Ran from Pyscripter and cmd.
Restarted my computer a couple times.
Opened that management.py file out of curiosity but it's only a couple hundred lines? I'm a GIS/data analyst, not a programmer of any sort, so this realm is beyond what I know.
I'm stumped. Yes, I could reinstall the library, but that's quite involved as this library is a tiny part of a massive software package.
you can have a try add "#encoding: utf-8" in your first row
Add # -*- coding: utf-8 -*- at the top of your script.
Probably the IDE that you are using, use the default encoding set.

SublimeREPL on Sublime Text 3 not importing Python 2.7 modules

I have been trying to configure SublimeText 3 to run SublimeREPL, setting everything so it runs as IDLE, or PyCharm IDE, but, after trying different options I checked in SO, it keeps returning:
>>> import pandas
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named pandas
>>> import os
>>> os.environ['PYTHONPATH']
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'PYTHONPATH'
I have tried editing the SublimeREPL.sublime-settings file with the default extend path file you can see at the FAQ site of SublimeREPL, but still does not work.
Does anyone know how this could be solved?
I don't know if this is the problem for you, but I was getting the exact same error and learned that by opening sublime text from the command line (e.g. 'subl .' to open the directory, once you have that shortcut set up) you get one PATH- and if you open sublime text from Spotlight Search you get another PATH. Try opening sublime text from the command line once you've confirmed you can import pandas in an interactive command line session and hopefully it will work.

Jedi-vim doesn't work

I have a issue with VIM. I'm trying to install jedi-vim according to https://github.com/davidhalter/jedi-vim
but when I open vim, it report such error:
initialize.py" 25L, 831C'import site' failed; use -v for traceback
Error detected while processing /home/.../.vim/autoload/jedi.vim:
line 285
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/.../.vim/initialize.py", line 10, in <module>
import os
ImportError: No module named os
And when I use Ctrl+Space in vim, it results in
Error detected while processing function jedi#completions:
line 1:
Traceback (most recent call last):
Press ENTER or type command to continue
In fact, I don't get any error when importing os from the command line..
import os
os,
module 'os' from '/usr/local/install/python-2.7.5/lib/python2.7/os.pyc'
Anybody know how to solve this error?Thank You.
Pretty sure that there's something wrong with your VIM. You're probably using vim on mac and there's something wrong with the sys.path.
You should be able to use :python import os in VIM. If that doesn't work, Jedi certainly won't.

Categories

Resources