In an Ubuntu environment, I am hosting a script on a web server and I'm trying to run the script without writing it to a file using the line wget -O - -o /dev/null 0.0.0.0:8000/myscript | python
The script starts off running just fine, until I get to a use of input() where I get this error
Traceback (most recent call last):
File "<stdin>", line 629, in <module>
EOFError: EOF when reading a line
I did a little reading on sys.stdin but I'm not finding a clear solution. What can exactly is happening here and how can I work around it?
Found the solution here: Pipe input to Python program and later get input from user
I added the line sys.stdin = open("/dev/tty") and now it seems to work.
Related
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
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!
I am trying to have a Python script automatically download an updated version of itself, replace the existing version, then restart automatically so that it loads the new version.
I'm currently using the following code to restart it:
os.execv(__file__, sys.argv)
However, this isn't working. Whenever Python tries to run this line, it returns the following error:
Traceback (most recent call last):
File "N:\CardDB\Station\Read.py", line 195, in <module>
else:
File "N:\CardDB\Station\Read.py", line 187, in run_update
print("\n\nWould you like to install this update?")
File "N:\CardDB\Station\Read.py", line 144, in update
f.write(version)
OSError: [Errno 8] Exec format error
Other questions on StackOverflow suggest that it's due to a missing shebang line, but I've made sure that it isn't missing - the first line of my script is:
#!/usr/bin/env python3
Unlike unix OSes, Windows does not seem to have native support for interpreted executables. os.execv requires a binary and fails because it is given a text file. So instead of calling the script directly, call the python interpreter
os.execv(sys.executable, [sys.executable, __file__] + sys.argv)
On, e.g., Linux, you can use os.execv(__file__, [__file__] + sys.argv) if the script is marked executable and contains a shebang line. For nonexecutable scripts you have to call the python executable as above.
I am a beginner in Python and am learning via online tutorials. On Study Drill #6 for example 15 on this page, I'm trying to open up the 'ex15_sample.txt' file that I have created and exists.
This is what it says to do:
Start 'python' to start the Python shell, and use 'open' from the prompt just like in this program. Notice how you can open files and run 'read' on them from within 'python'?
In the command prompt, I entered python to start the Python shell and have tried typing in the following, which threw me an error:
open(ex15_sample.txt)
The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ex15_sample' is not defined
ex15_sample.txt is a file that exists in the same folder. How am I supposed to use open or any other command from the prompt? I am running Python 2.7.8 on Powershell, by the way.
The first argument of open is a string containing the filename.
Just put file name in Quotation Mark:
f = open('ex15_sample.txt')
This is my script
removed
it works fine through terminal but when i make it a .app with Platypus i get this when running the app
Hello How are you?
Traceback (most recent call last):
File "/Users/shameer/Desktop/Test Programs/questions.app/Contents/Resources/script", line 2, in <module>
feeling = raw_input()
EOFError: EOF when reading a line
Platypus doesn't create an interactive terminal session, it just pipes your script output into a textfield. You won't be able to wrap interactive programs with it.