0

I was trying to run a python file "exe.py" on vs code by typing:

python3 .\exe.py

But it comes with the following replys from vs code:

python3: can't open file '/Users/exercise/my-python-app/myenv/.exe.py': [Errno 2] No such file or directory

No ideas why couldn't it works given that I already installed the python package and running the command in appropriate environment.

2
  • If you're in the correct directory, just run python3 exe.py. Backslashes are file separators only on windows, whereas you seem to be on macOS Commented May 27, 2022 at 7:55
  • The slash in the path is the wrong way round, making your python look for a file called .exe.py - ./exe.py Commented Jun 1, 2022 at 18:12

2 Answers 2

1

You are running

python3 .\exe.py

which is escaping the e and therefore is replaced by e as there's no matching escape char and it becomes

python3 .exe.py

You need, as other response states

python3 exe.py

or

python3 ./exe.py
Sign up to request clarification or add additional context in comments.

Comments

0

In fact python3 is installed in your system but you are typing incorrectly the command. Imagine that you have the python file named exe.py with the following code

print("Hello world")

If you are in the same directory of the file you can execute it using the command

python3 exe.py

Another way to execute exe.py is using the shebang line. The shebang is a line that you can write to tell to the operative system which executable must use to interpret the code of the file. If you add the typical shebang for python3 in linux at the beginning of exe.py

#!/usr/bin/env python3
print("Hello world")

and you tip the command

./exe.py

you will see the result of the execution too. If you get an error probably you have to give permissions to the file with the command

chmod 777 exe.py

You can find a lot of resources talking about the shebang. The following link talks about the shebang in python

https://www.pythonpool.com/python-shebang/

I hope you found it useful.

Greetings.

2 Comments

chmod 777 is very bad advice
Indeed, with a 777 permission assignment any user on the system could read, modify and execute the script so possibly the 700 permission assignment is much more appropriate. However, I do not see any danger in assigning the 777 permissions to the script that I exposed above. You are right that in general you have to be very careful with the permissions you assign to scripts, especially in a production environment. For example applying chmod +s permissions to the vim binary can lead to catastrophic consequences such as privilege escalation to root. More info in gtfobins.github.io

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.