1

I am running a python file in the directory where the file is and I get 'No such file or directory', with ls -l the file appears with the needed 'x' permission; my command is ./filename.py + options > name of output file

Thank you for your comments. The error resulted because I was using the upper arrow to find a cmd that I used in an earlier version and, even though the recovered cmd read good in the terminal window, the code won't run. By retyping anew the same cmd it worked fine! I think that the corrupted cmd was the result of an ubuntu error (indicated to me by ubuntu) as startup after I put the system to sleep the day before. I think this is the reason because it happened again, and only retyping the cmd anew resolved the problem. Somehow I have problems every time I startup after I put the system to sleep (the corruption of cmd stored by ubuntu do not happen if I startup from a full shut down).

8
  • 1
    Can you give us the output of ls -l?
    – edwinksl
    Jun 29, 2016 at 0:14
  • -rwxrwxr-x 1 richardabuli richardabuli 30519 5월 19 22:06 V2_sn .py~ -rwx--x--x 1 richardabuli richardabuli 41871 6월 29 01:32 V2_sn.py -rwx--x--x 1 richardabuli richardabuli 41867 6월 29 01:09 V2_sn.py~ -rwxrwxr-x 1 richardabuli richardabuli 31639 5월 22 03:11 V3_sn.py~ -rw-rw-r-- 1 richardabuli richardabuli 113411 5월 28 21:39 Vp_G1J50N4.ls Jun 29, 2016 at 0:21
  • 1
    Thanks. Can you edit your question to include those details? In addition, can you also tell us what exact command you tried to run?
    – edwinksl
    Jun 29, 2016 at 0:27
  • 2
    Click the edit link to edit your question :)
    – Videonauth
    Jul 4, 2016 at 19:13
  • 1
    Please post an answer instead of adding the solution you found to your question. Thanks!
    – Byte Commander
    Jul 4, 2016 at 19:29

3 Answers 3

1

The error resulted because I was using the upper arrow to find a cmd that I used in an earlier run and, even though the recovered cmd read good in the terminal window, the code won't run. By retyping anew the same cmd it worked fine! I think that the corrupted cmd was the result of an ubuntu error (indicated to me by ubuntu) as startup after I put the system to hivernation the day before. I think this is the reason because it happened again, and only retyping the cmd anew resolved the problem. Somehow I have problems every time I startup after I put the system to sleep (the corruption of cmd stored by ubuntu do not happen if I startup from a full shut down).

0

Try running it with

python filename.py

Or

python3 filename.py

You may need sudo depending on the file.

EDIT: usually the ./ is used for bash scripts

7
  • 2
    ./ denotes that the file is in the current directory. It's used anywhere the path needs to be determined.
    – Stormlord
    Jun 29, 2016 at 0:19
  • @Stormlord can it be used to execute any scripts? I guess so, as long as it has the #!/bin/bash or something like that
    – tycrek
    Jun 29, 2016 at 0:20
  • The command I'm using to run this file always worked before; the ls -l command for this file gives: -rwx--x--x 1 richardabuli richardabuli 41871 6월 29 01:32 V2_sn.py (I bough the computer in Korea and the date exhibits Korean characters, this is not the problem) Jun 29, 2016 at 0:24
  • 1
    ./ is just a path determination. If an executable file, either script or not, is in a different folder than the one you're, you type /foldername/filename to run it. If it's in the current folder, you type ./filename. That's all it is.
    – Stormlord
    Jun 29, 2016 at 0:26
  • yes, this is how I run the file, but somehow it doesn't work anymore Jun 29, 2016 at 0:28
0

Since you're running it with ./, you may need to prepend

#!/usr/bin/env python

To your Python file.

If you would like to avoid that, you could just run the file with python instead:

python script.py

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .