I just installed pycharm and I can open my excel workbook. I recieve the error: FileNotFoundError: [Errno 2] No such file or directory

I just installed pycharm and I can open my excel workbook. I recieve the error: FileNotFoundError: [Errno 2] No such file or directory

我正在使用 Ubuntu-pycharm-openpyxl。我的代码是:

import openpyxl as xl
import os
p = os.getcwd ()
print(p)
filename = 'c:/home/elinor/Documents/data.xlsx'
wb1 = xl.load_workbook(filename)

它returns:

/home/elinor/PycharmProjects/untitled1/venv/bin/python /home/elinor/.config/JetBrains/PyCharmCE2020.1/scratches/scratch_1.py
/home/elinor
Traceback (most recent call last):
  File "/home/elinor/.config/JetBrains/PyCharmCE2020.1/scratches/scratch_1.py", line 6, in <module>
    wb1 = xl.load_workbook(filename) 
  File "/home/elinor/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 313, in load_workbook
    reader = ExcelReader(filename, read_only, keep_vba,
  File "/home/elinor/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 124, in __init__
    self.archive = _validate_archive(fn)
  File "/home/elinor/PycharmProjects/untitled1/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 96, in _validate_archive
    archive = ZipFile(filename, 'r')
  File "/usr/lib/python3.8/zipfile.py", line 1251, in __init__
    self.fp = io.open(file, filemode)
**FileNotFoundError: [Errno 2] No such file or directory: 'c:/home/elinor/Documents/data.xlsx'**

进程已完成,退出代码为 1

你确定你提到的文件路径是正确的吗?如果是,那么请尝试如下 filename = r'c:/home/elinor/Documents/data.xlsx'