How to run .py pygame on Python 2.7? - python

My lab used python 2.7 with pygame with a program and I'm trying to run it on my computer with no success. Things I've tried:
(1) Installing Python 2.7 and pygame on Windows 10. The program just crashes when I run it with IDLE.
(2) Running a virtual system with ubuntu and installing IDLE, Python 2.7, pygame, etc.
(a) If I open IDLE and open the file Output.py
(b) If I open a shell and type
python /home/frank/Dropbox/clab/Maze_2.2/Output.py
Then I get the following error
python /home/frank/Dropbox/clab/Maze_2.2/Output.py Traceback (most
recent call last):
File "/home/frank/Dropbox/clab/Maze_2.2/Output.py", line 11, in
from Output2d import *
File "/home/frank/Dropbox/clab/Maze_2.2/Output2d.py", line 8, in
import ReadFile
File "/home/frank/Dropbox/clab/Maze_2.2/ReadFile.py", line 44, in
print get_mins()
File "/home/frank/Dropbox/clab/Maze_2.2/ReadFile.py", line 37, in
get_mins handle = open(INPUT_FILE, 'r')
IOError: [Errno 2] No such file or directory: 'data/prob.txt'
The file prob.txt is present and is not corrupt so I'm really unsure what to do next to troubleshoot this issue

This is not a pygame issue, you are just missing some data files of the game Maze: Maze_2.2/data/*
A file named data/prob.txt, you should find it

Related

Having an issue running Python Code in terminal

Hi everyone so I have some python code I am trying to run from my terminal (will not work in an IDE) to take a .mp3 file and classify the genre of the song based on the Spectrogram that we are using the librosa library plugin for. The code is from this gitHub: https://github.com/cetinsamet/music-genre-classification .When I use the command prompt specified by the gitHub user who created this app I get this error in my terminal:
(base) Nicos-MacBook-Pro:src nico$ python3 get_genre.py ../test.mp3
Traceback (most recent call last):
File "get_genre.py", line 61, in <module>
main(sys.argv[1:])
File "get_genre.py", line 30, in main
net.load_state_dict(torch.load(MODELPATH, map_location='cpu'))
File "/Users/nico/opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 419, in load
f = open(f, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '../utils/net.pt'
Here is the command line specified: $ python3 get_genre.py ../test.mp3
The error message quite plainly tells you that the code depends on having a file ../utils/net.pt

No Python IDE will start and it will not start in the Command Prompt

When I click on my Python IDE's (IDEL, PyScripter) they will not even open. I tried typing python in the command prompt and this is what happened:
C:\>python
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.5\lib\site.py", line 548, in <module>
main()
File "C:\Python27\ArcGIS10.5\lib\site.py", line 537, in main
aliasmbcs()
File "C:\Python27\ArcGIS10.5\lib\site.py", line 469, in aliasmbcs
codecs.lookup(enc)
File "C:\Python27\ArcGIS10.5\lib\encodings\__init__.py", line 85, in search_function
norm_encoding = normalize_encoding(encoding)
File "C:\Python27\ArcGIS10.5\lib\encodings\__init__.py", line 57, in normalize_encoding`enter code here`
encoding = str(encoding, "ascii")
TypeError: str() takes at most 1 argument (2 given)
Did you recently install ArcGIS? It looks to me like ArcGIS installed a few libraries, and overwrote your site.py, but it's using code that's meant for Python3 rather than Python2.7. The str function is capable of taking in 2 arguments in Python3 but not in Python2.
To get your Python to work again, you could try deleting the entire ArcGIS10.5 directory from your computer (or temporarily moving it to your desktop and seeing if that helps). You can also try running python -S in Command Prompt to run Python without importing site.py.
To try to get ArcGIS working, you might be able to install Python3, and reinstall ArcGIS using that.
Hopefully that helps!

Python numpy.savetxt - no such file or directory, although path is correct

Found no solution here on stackoverflow yet. In the threads I read, where this problem is considered, the problem was triggered by a wrong path. But in my case, the path should be correct, since I copied it to the windows navigation line and it worked.
The error message looks as follows:
Traceback (most recent call last):
File "C:\Users\micha\Dropbox\10. Semester\Fabios_error_bound\python_new_pc\feb_error_calculation_and_plotting\feb_error_calculation_and_plotting\feb_error_calculation_and_plotting.py", line 99, in <module>
np.savetxt(os.path.join(working_directory,error_folder,current_name.replace('.txt','')+'error_pop11.txt'),error_pop11, fmt='%20.14f')
File "C:\Python27amd64\lib\site-packages\numpy\lib\npyio.py", line 1194, in savetxt
fh = open(fname, 'w')
IOError: [Errno 2] No such file or directory: 'C:\\Users\\micha\\Dropbox\\10. Semester\\Fabios_error_bound\\python_new_pc\\feb_error_calculation_and_plotting\\feb_error_calculation_and_plotting\\error2\\ses_pop_site_eb__ohmic_lam50_gam100_T100_SD_ohmic_lam50_gam100_T100_angle39_Chl658_Egap0_J100_M2_K0_L8error_pop11.txt'
Furthermore, it works on my PC, but not on my notebook. In both cases I'm using Visual Studio with Python 3.5 and 3.6, respectively (with 2.7 it also doesn't work on my Notebook).
Does anybody has a clue?

Python script runs with double-click and IDLE but not windows CMD shell

I'm have a problem where if I double click my script (.py), or open it with IDLE, it will compile and run correct. However, if I try to run the script in my windows command line, using
C:\> "C:\Software_Dev\Python 2.7.1\python.exe" C:\path\to\script\script.py
I get...
Traceback (most recent call last):
File "C:\path\to\script\script.py", line 66, in <module>
a.CheckTorrent()
File "C:\path\to\script\script.py", line 33, in script
self.WriteLog(fileName)
File "C:\path\to\script\script.py", line 54, in WriteLog
myFile = open(r'%s' %(filename), 'w')
IOError: [Errno 13] Permission denied: './TorrentMonitor.log'
So my question is, why am I getting permission errors when I run this script through command line in window 7 but not when I double click? What's the difference between those two processes?
Thanks in advance!
The script is trying to write into a file in the current directory. In the example above, you're starting it from C:\ where you probably don't have write permissions.
cd to a directory that you own, and you should be able to run that command just fine.
This is because when you double-click the file (or when running it from IDLE), the current working directory is the directory that contains your script. When starting it from the command line, it's C:\ which you don't seem to have write access to.

"AttributeError: fileno" when attemping to import from pyevolve

I just installed Pyevolve using easy_install and I am getting errors trying to run my first program. I first tried copy and pasting the source code of the first example but this is what I receive when I attempt to run it:
Traceback (most recent call last):
File "/home/corey/CTest/first_intro.py", line 3, in
from pyevolve import G1DList
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/init.py", line 15, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Consts.py", line 240, in
import Selectors
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Selectors.py", line 12, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/GPopulation.py", line 11, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/FunctionSlot.py", line 14, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Util.py", line 20, in
AttributeError: fileno
I am running python 2.6 on Fedora 11 X86_64.
Edit: After looking into it more if I run python from the command line it works but it only fails when I'm running IDLE.
Have you tried to check out the Development version ? It's near of the RC1, so it is stable right now:
svn co https://pyevolve.svn.sourceforge.net/svnroot/pyevolve/trunk pyevolve
Your problem seems to be the paths, try uncompressing the "egg" file and put the "pyevolve" directory in the site-packages or inside your application directory.

Categories