When I execute python helloworld.py in powershell. The response is this C:\Users\ragal\AppData\Local\Microsoft\WindowsApps\python.exe: can't open file 'C:\Users\ragal\helloworld.py': [Errno 2] No such file or directory.
What should I do
Related
Running Python 3.9.6 on Terminal (Mac).
I can't seem to figure out how to use an existing file from the python console.
My existing file is named sim.txt.
>>> wv.evaluate_word_pairs("sim.txt")
Gets me FileNotFoundError: [Errno 2] No such file or directory: 'sim.txt'.
How do I get this to work?
I'm trying to open Python project through bat file and getting error in cmd(win10):
C:\Python\python.exe: can't open file '<unprintable file name>': [Errno 2] No such file or directory
My bat file contained:
py -3 %~dp0\data_analyzer.py %*
Also tried with:
py -3 %cd%\data_analyzer.py %*
I've found that <unprintable file name> is something with encoding. But encoding of what? Where is that issue? I've checked differet .py files and also have same issue.
If it's in that bat file I've tried to change encoing in Notepad, but it doesn't change anything. What else I can do and where to look for answer?
I am trying to run two python scripts on startup on my Raspberry Pi.
Both scripts work if I launch them with
python script1.py
python script2.py
They also work with a shell script in the same folder containing
python script1.py &
python script2.py &
But if I add either the individual scripts to the rc.local startup file, or the shell script, I get errors of missing files.
If I add the python scripts to startup via rc.local then it claims that text files I call in the script are missing:
pi#raspberrypi ~ $ sudo service rc.local start
My IP address is 192.168.0.4
pi#raspberrypi ~ $ Traceback (most recent call last):
File "home/pi/scripts/script1.py", line 8, in <module>
scripts.make_batch(randint(10,12))
File "/home/pi/scripts/functions.py", line 36, in make_batch
num_lines = sum(1 for line in open('script1_file.txt'))
IOError: [Errno 2] No such file or directory: 'script1_file.txt'
Traceback (most recent call last):
File "home/pi/scripts/script2.py", line 5, in <module>
scripts.check(3,30)
File "/home/pi/scripts/functions.py", line 78, in check
with open('script2_file.txt', 'r+') as followed:
IOError: [Errno 2] No such file or directory: 'script2_file.txt'
^C
If I add the batch script.sh to startup that calls the python scripts then it claims they are missing.
pi#raspberrypi /etc $ sudo service rc.local start
My IP address is 192.168.0.4
pi#raspberrypi /etc $ python: can't open file 'script1.py': [Errno 2] No such file or directory
python: can't open file 'script2.py': [Errno 2] No such file or directory
^C
Is this something to do with permissions? My script folder is 755 recursive.
All the files ARE there and the scripts run fine directly. This is something to do with running files within files through the rc.local startup process... but I don't know what!
Help greatly appreciated.
You need to supply the full paths to the files:
with open('full/path/to/script2_file.txt', 'r+')
The same for your second problem:
'full/path/to/script2.py'
I have SSHed from my local machine (a Mac) to a remote machine called “ten-thousand-dollar-bill” as the user “chilge”.
I want to run a Python script in the folder “/afs/athena.mit.edu/c/h/chilge/web_scripts” that generates and saves a .png image to the folder “/afs/athena.mit.edu/c/h/chilge/www/TAF_figures/KORD/1407”. When I run the script from the command line, the image is generated and saved without any issues. When I run the script as cron job, though (the crontab resides in “/afs/athena.mit.edu/c/h/chilge/cron_scripts”), I get the following error:
Traceback (most recent call last):
File "/afs/athena.mit.edu/user/c/h/chilge/web_scripts/generate_plots.py", line 15, in
save_taffig(taf,fig)
File "/afs/athena.mit.edu/user/c/h/chilge/web_scripts/plotting.py", line 928, in save_taffig
fig.savefig(os.getcwd()+'/'+savename+'.png')
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 1084, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py", line 1923, in print_figure
**kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 443, in print_png
filename_or_obj = file(filename_or_obj, 'wb')
IOError: [Errno 13] Permission denied: '/afs/athena.mit.edu/user/c/h/chilge/www/TAF_figures/KORD/1407/140723-1200_AMD_140723-1558.png'
I believe I’ve correctly changed the permissions of all of the necessary directories, but I’m still getting this error. I am not sure why the script would run fine from the command line, but fail when I try to run the script as a cron job.
(Also, I’m not sure if this will be relevant, but don’t have sudo permissions on the remote machine.)
Maybe an other software opens the file which you want to overwrite?
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.