0

I'm having a problem when accessing a file path while using python in VSCode with pyenv and poetry on Ubuntu 20.04.

I run this:

import pandas as pd

data = pd.read_csv("../docs/lists.csv")
data

And I got this error:

Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: '../docs/lists.csv'
  File "/home/nisase/my_folder/examples/list.py", line 3, in <module>
    data = pd.read_csv("../docs/lists.csv")`

Project tree is below:

my_folder/
 |examples/             
    |list.py
 |docs/              
    |lists.csv
Nisase
  • 1
  • 1

1 Answers1

0

Could you try data = pd.read_csv("docs/lists.csv")?

The python script to search the file depends on the cwd, you can get it through os.getcwd.

os.getcwd()

Return a string representing the current working directory.

The default value of cwd in VSCode is:

${workspaceFolder} - the path of the folder opened in VS Code

So the path is docs/lists.csv instead of ../docs/lists.csv

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13