这个问题是我在linux环境下直接运行代码时出现的问题,
原来在vscode中远程linux服务器debug是没有问题的
项目组织结构为:
│ train.py
│ __init__.py
│
├─data
│ └─raw
│ test.txt
│ train.txt
│
├─preprocess
│ │ remove_words.py
│ │ __init__.py
│
└─utils
│ utils.py
│ __init__.py
想运行preprocess文件夹下的remove_words.py,
在linux环境下进入到preprocess文件夹,
输入 python remove_words.py ,结果也就报了如标题的错误
看错误是没找到我的数据集,看样是路径没有找到
train_filename = 'data/raw/train.txt'
df = pd.read_csv(train_filename, sep='#', header=None)
使用 os.getcwd() 可以看到当前目录仍在preprocess文件夹下
通过搜索最终解决:
看样子是跳到了上级目录,这也也就能访问data文件夹下的数据集了
import os
os.chdir("..")