What to do if cmd gives errror: "python: can't open file 'C:\Users\Username\3.9.1': [Errno 2] No such file or directory | Sololearn: Learn to code for FREE!

0

What to do if cmd gives errror: "python: can't open file 'C:\Users\Username\3.9.1': [Errno 2] No such file or directory

(Python 3.9.1) File was compiled with sublime 3

4/13/2021 9:09:38 PM

Raphael Thikusho II

9 Answers

New Answer

+3

go to the python script dir and try running the cmd there

+3

it means the file doesnt exist. You cant just provide a filename. Wherever your code is being saved is the current working directory. if you want to reference a file, you should provide the full path from root or C drive

+1

Is the file called '3.9.1'? If it is actually named '3.9.1.py' you should refer to it as such. Also one should not put dots in filenames unless it is for defining file extensions or such errors appear. Just good programming practice ;)

0

Slick When I do it like this I still get the same error

0

delete the current file and install it agian

0

with this command, you should be able to see name of your python file in a list: import os print([i for i in os.listdir() if ".py" in i]) and then you can get full path of your python file with this command: print(os.path.abspath("your_file_name.py"))

0

Tomáš Konečný should i do this in the cmd??

0

Raphael Thikusho II run this command in your python script

0

He can try to use Python IDE and run it there... It should be more error-proof way