Python Forum
"[Errno 2] No such file or directory" (.py file)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"[Errno 2] No such file or directory" (.py file)
#1
Hi to you all,

I am reaching out due to an issue while trying to run a ".py" file on Windows 11 Home Single Language.

After entering this on the command prompt:

py C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start%20Menu\Programs\Python%203.12\Waterfall%20Chart
.py
the following error code is rendered

Error:
C:\Users\ibrah\AppData\Local\Programs\Python\Python312\python.exe: can't open file 'C:\\Users\\ibrah\\AppData\\Roaming\\Microsoft\\Windows\\Start%20Menu\\Programs\\Python%203.12\\Waterfall%20Chart.py': [Errno 2] No such file or directory
I verified the exact name of the file, as well as its path several times and they are both correct.

Does anyone see anything wrong with this line of code?

Please find attached a screenshot for the actual line of code entered and the error message rendered on the command prompt

Greetings.

Attached Files

Thumbnail(s)
   
Reply
#2
Does the file exist?
What is in the file waterfall chart.py?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
You should not have folder %20 in name,
Just make new folder with much shorter path easier to work with,place your Python files there.
From eg cmd.
# Cd down
C:\Users>cd ..

# Make a folder
C:\>mkdir my_code

# cd in
C:\>cd my_code

# Make a file 
C:\my_code>echo.> hello.py

# Look at files in folder
C:\my_code>dir
 Volume in drive C has no label.
 Volume Serial Number is EED7-45CC

 Directory of C:\my_code
  .
10.06.2024  21:49    <DIR>          ..
10.06.2024  21:49                 2 hello.py
               1 File(s)              2 bytes
               2 Dir(s)  17 600 786 432 bytes free

# Run code,i have added print('hello world')
C:\my_code>python hello.py
hello world

C:\my_code>py hello.py
hello world

# Test python and pip version
C:\my_code>python --version
Python 3.12.2

C:\my_code>pip --version
pip 24.0 from C:\Python312\Lib\site-packages\pip (python 3.12)

C:\my_code>
Reply
#4
(Jun-10-2024, 07:11 PM)menator01 Wrote: Does the file exist?
What is in the file waterfall chart.py?

I created the file yesterday at 9:55:55 under the name "Waterfall Chart". Here is its content:

   
Reply
#5
(Jun-10-2024, 07:59 PM)snippsat Wrote: You should not have folder %20 in name,
Just make new folder with much shorter path easier to work with,place your Python files there.
From eg cmd.
# Cd down
C:\Users>cd ..

# Make a folder
C:\>mkdir my_code

# cd in
C:\>cd my_code

# Make a file 
C:\my_code>echo.> hello.py

# Look at files in folder
C:\my_code>dir
 Volume in drive C has no label.
 Volume Serial Number is EED7-45CC

 Directory of C:\my_code
  .
10.06.2024  21:49    <DIR>          ..
10.06.2024  21:49                 2 hello.py
               1 File(s)              2 bytes
               2 Dir(s)  17 600 786 432 bytes free

# Run code,i have added print('hello world')
C:\my_code>python hello.py
hello world

C:\my_code>py hello.py
hello world

# Test python and pip version
C:\my_code>python --version
Python 3.12.2

C:\my_code>pip --version
pip 24.0 from C:\Python312\Lib\site-packages\pip (python 3.12)

C:\my_code>

Thank you for your answer. I moved the file to another folder easier to locate. I also tried running the line of code this way, without the %20 portion in the name of the file, however the following was rendered:

C:\Users\ibrah\AppData\Local\Programs\Python\Python312\python.exe: can't open file 'C:\\Users\\ibrah\\Waterfall': [Errno 2] No such file or directory
When not using %20 instead of the space between "Waterfall" and "Chart", the following name: "Waterfall'"gets rendered instead of "Waterfall Chart".

Does the location of the file has any incidence on its execution? Does it have to be at a specific place for it to be executed, for example, in "Python 3.12" for a file to be executed with the "py" command?
Reply
#6
You should use quotes around filenames that contain spaces.

"C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.12\Waterfall Chart.py"

or you can use quotes only where needed

C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\"Python 3.12"\"Waterfall Chart.py"

%20 does not work at all. Where did you get that?

The indenting in your waterfall chart.py file looks like a waterfall. You'll need to fix that. Indenting in python is syntax.
Reply
#7
(Jun-10-2024, 08:57 PM)IbrahimBennani Wrote: I created the file yesterday at 9:55:55 under the name "Waterfall Chart". Here is its content:

I observe that filename on screenshot is Waterfall Plot and you try to open Waterfall Chart.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#8
(Jun-10-2024, 09:59 PM)deanhystad Wrote: You should use quotes around filenames that contain spaces.

"C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.12\Waterfall Chart.py"

or you can use quotes only where needed

C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\"Python 3.12"\"Waterfall Chart.py"

%20 does not work at all. Where did you get that?

The indenting in your waterfall chart.py file looks like a waterfall. You'll need to fix that. Indenting in python is syntax.

The quote work indeed, but the same error message still gets rendered.

C:\Users\ibrah\AppData\Local\Programs\Python\Python312\python.exe: can't open file 'C:\\Users\\ibrah\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Pyton 3.12\\Waterfall Chart.py': [Errno 2] No such file or directory
As for "%20", it is an ASCII encoding reference, which you can find here:

https://www.w3schools.com/tags/ref_urlencode.ASP

I'll fix this for the indenting, however I am still struggling with the execution of the file for the moment.
Reply
#9
(Jun-11-2024, 05:00 AM)perfringo Wrote:
(Jun-10-2024, 08:57 PM)IbrahimBennani Wrote: I created the file yesterday at 9:55:55 under the name "Waterfall Chart". Here is its content:

I observe that filename on screenshot is Waterfall Plot and you try to open Waterfall Chart.

True Perfringo, it is just the same file with two different names. Both do not get executed when I use the "py" command.
Reply
#10
I actually succeeded to run the file by using quotation marks instead of the "%20" encoding reference, however, another error message was rendered when running the file:

 C:\Users>py "C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.12\Waterfall Plot.py"
Error:
File "C:\Users\ibrah\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.12\Waterfall Plot.py", line 9 connector = "line":{"color":"rgb(63, 63, 63)"},) SyntaxError: closing parenthesis ')' does not match opening parenthesis '[' on line 4
The first element referred to by the "SyntaxError" message is a parenthesis while the second one is actually a hook. There might be a confusion between both elements.

Here is the code contained in the file that was run through the "py" command:

import plotly.graph_objects as go

fig = go.Figure(go.Waterfall(
    measure = ["relative", "relative", "total", "relative", "relative, "total"]   "Sales
    x = ["Sales", "Consulting", "Net revenue", "Purchases", "Other Expenses", "Profit Before Tax"],
    textposition = "outside"
    text = ["+60", "+80", "" "-40", "-20", "Total"]
    y = [60, 80, 0, -40, -20, 0]
    connector = "line":{"color":"rgb(63, 63, 63)"},)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 463 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  file open "file not found error" shanoger 8 1,646 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 940 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 1,161 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 4,048 Jun-27-2023, 01:17 PM
Last Post: diver999
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,270 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 1,232 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,285 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,775 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 1,161 Oct-07-2022, 02:01 PM
Last Post: Nasir

Forum Jump:

User Panel Messages

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