0

Getting below error when running the command:

output = open( "C:/Users/TAA3656/mytddutc_nudges_sample.json", 'w') # Update to local path and file name 

[Errno 2] No such file or directory: 'C:/Users/TAA3656/mytddutc_nudges_sample.json' 
Traceback (most recent call last): 
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/TAA3656/mytddutc_nudges_sample.json' 
ForceBru
  • 43,482
  • 10
  • 63
  • 98
saurabh
  • 11
  • 1
  • 1
    I OCR'd the code and error message for you. Please don't post images of code, it makes it inconvenient to try out. – kindall May 18 '22 at 20:58

3 Answers3

2

I'd guess the path C:/Users/TAA3656 doesn't exist, so it's not possible to create a file in this nonexistent path. For example:

>>> open("nonexistent/thing.json", 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'nonexistent/thing.json'

One could think that open(..., 'w') should create nonexistent/thing.json if it doesn't exist, but in this case, the directory nonexistent is... non-existent, so open refuses to create the file along with an entire path structure.

You should create the path first:

from pathlib import Path

the_path = Path("C:/Users/TAA3656")
# Create the path if it doesn't exist
the_path.mkdir(parents=True, exist_ok=True)
# Open or create the file
with (the_path / "your_file.json").open("w") as output:
   ... # run your code
ForceBru
  • 43,482
  • 10
  • 63
  • 98
0

verify the path of the file you are trying to open is correct. to verft the path exist use !pwd to show the path you are in and navegate to the location and !mkdir name to create the folder and the you can acces it.you also need to import sys and import os. so you can navegate through the system files

Francis
  • 1
  • 2
0

Do you know if you are running your jupyterlab locally, or in some kind of cloud environment? (Your mention of a pyspark kernel suggests to me it may be the latter.) If it is a cloud platform of some kind, you may not have access to your local hard disk.

Try this to check your platform, and see if it looks local to you.

Or you can try:

import os
os.getcwd()

to give you the path of where you are currently working. If it doesn't look like a directory on your local pc, again, you not be working locally.

Or ask a friendly looking colleague.

s_pike
  • 1,710
  • 1
  • 10
  • 22