【问题标题】:FileNotFoundError: [Errno 2] No such file or directory; How to fix?FileNotFoundError: [Errno 2] 没有这样的文件或目录;怎么修?
【发布时间】:2021-04-20 13:24:36
【问题描述】:

我是 VSCode 的新手,我一直在尝试从 Jupyter 切换过来,并且非常挣扎。我现在的主要项目是开发一个工作情绪分析程序,我什至无法开始,因为我无法读取我的数据。

这是我当前的代码:

import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split

data_train = pd.read_csv("trainingData/yelp_review_full_csv/train.csv", header = None)
data_test = pd.read_csv("trainingData/yelp_review_full_csv/test.csv", header = None)
data_train.head(5)

我的 launch.json 是

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "python": "${command:python.interpreterPath}",
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${fileDirname}"
        }
    ]
}

我搜索了所有可能的方法,每次遇到同样的错误。有人可以建议如何解决此问题吗?

【问题讨论】:

  • 写入文件的完整路径。或者将训练数据文件放在您正在处理的同一目录中。

标签: python pandas visual-studio-code


【解决方案1】:

1.当读取文件(.py文件)和数据文件(.csv文件)在同一个文件夹时:

1>。使用时:"cwd": "${workspaceFolder}",(cwd的默认值)在launch.json中。

2>。当使用"cwd": "${fileDirname}"

2.当读取文件和数据文件在不同文件夹时:请使用"cwd": "${workspaceFolder}",

参考:cwd in VS Code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 2021-08-24
    • 2021-03-07
    • 2015-06-09
    • 2021-04-01
    • 2021-10-15
    • 1970-01-01
    相关资源
    最近更新 更多