[英]Heroku: FileNotFoundError [Errno 2] during file IO operations on deployment - Python
I have successfully deployed a webapp to Heroku.我已成功将 web 应用程序部署到 Heroku。 However, my file IO operations are not happening because Heroku is unable to recognize the files in the folders.
但是,我的文件 IO 操作没有发生,因为 Heroku 无法识别文件夹中的文件。
My folder structure is:我的文件夹结构是:
- Project Folder
- datafolder
- otherdata.csv
- main.py
- userdata.csv
When I use df = pd.read_csv('userdata.csv')
all works fine, because this is in the root directory as the main file and Heroku is able to find it, and allow read write operations.当我使用
df = pd.read_csv('userdata.csv')
一切正常,因为它在根目录中作为主文件并且 Heroku 能够找到它,并允许读写操作。
However when I use df = pd.read_csv('datafolder\\\\otherdata.csv')
Heroku logs display this error:但是,当我使用
df = pd.read_csv('datafolder\\\\otherdata.csv')
Heroku 日志时,会显示此错误:
FileNotFoundError: [Errno 2] No such file or directory: 'datafolder\\\\otherdata.csv'
When I ran bash command using Heroku CLI, I can see the datafolder as well as csv file.当我使用 Heroku CLI 运行 bash 命令时,我可以看到数据文件夹和 csv 文件。 Why is Heroku not able to recognise "datafolder" and the csv inside it?
为什么 Heroku 无法识别“数据文件夹”和其中的 csv?
您没有以正确的方式使用路径,您只需要使用 df = pd.read_csv('datafolder/otherdata.csv') 并且它应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.