Python Forum
No such file or directory
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No such file or directory
#11
# Give path and run hello.py
C:\WINDOWS\system32>python C:\testpy\hello.py

gives:
"can't open file 'C:\testpy\hello.py" and "no such file or directory"

# cd into testpy
C:\WINDOWS\system32>cd C:\testpy

works!

# Run when in folder of hello.py
C:\testpy>python hello.py

gives again:
"can't open file 'C:\testpy\hello.py" and "no such file or directory"

# cd to root C:
C:\testpy>cd\

works!

# Test where python run from,these command should be same no matter what folder you into in cmd
C:\>python -c "import sys; print(sys.executable)"

gives: C:\Users\myname\AppData\Local\Programs\Python\Python37-32\Python.exe

# Test pip
C:\>pip -V

gives

pip 10.0.1 from c:\users\myname\appdata\local\programs\python\python37-32\lib\site
-packages\pip (python 3.7)

# cd into testpy
C:\>cd testpy

works again

# List files
C:\testpy>dir

works, see the same as you.

# Spelling error
C:\testpy>more hell.py

gives "can't access file" again...

# Ok
C:\testpy>more hello.py

gives "can't access file"...


my name has a special symbol: "ยด"
Can this be the problem in
pip 10.0.1 from c:\users\myname\appdata\local\programs\python\python37-32\lib\site
-packages\pip (python 3.7)
where "myname" is actually my real name with the special symbol?
Reply
#12
(Aug-02-2018, 05:23 PM)SchroedingersLion Wrote: where "myname" is actually my real name with the special symbol?
No it work when you use python and pip so that's okay.
Quote:gives again:
"can't open file 'C:\testpy\hello.py" and "no such file or directory"
This dos usually never lie,try make new folders and files in other place(also an other drive like eg E:) then try again.
You can eg do it all in cmd:
# Make folder
C:\>mkdir my_dir
C:\>cd my_dir

# Make file
C:\my_dir>echo print('hello world') >my.py

# look 
C:\my_dir>more my.py
print('hello world')

# Run
C:\my_dir>python my.py
hello world
Reply
#13
Yeah, doesn't work with other folder either. I don't get it...

But the "print" command in my file is not even displayed in blue, which should happen in a .py document, right? So it seems like the computer does not even reckognise it as a .py document.

It works now! My own comment gave me the right idea.

I took a look at "properties" of the file and even though I renamed it into "hello.py", in properties, the name was given as "hello.py.txt". So it was still a .txt file for the computer.
It seems like the file endings were disabled on my system, so I had to enable them first before I could change the file type with a simple ".py". Works now!

Thanks anyway!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020