Docker pandas 阅读 excel
Docker pandas read excel
我是Docker的新人,我需要运行一个Flask应用程序,但在这个应用程序中,我需要读取一个xlsx文件。
当我构建 docker 图像时,我有 excel 文件,但 Docker 没有读取它。
使用 xlsx 查看我的代码部分:
try :
# Page PayPlug
infos_pay = pd.read_excel('./app-infos.xlsx', sheet_name='payplug')
secret_key = infos_pay.loc[0].tolist()
payplug.set_secret_key(secret_key[0])
# Page mail
feuille_mail = pd.read_excel('./app-infos.xlsx', sheet_name='mail')
infos_mail = feuille_mail.loc[0].tolist()
except :
print("Can't read file")
还有我的 docker 文件:
FROM python:3.8
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD [ "python", "./web_AuSpot.py" ]
当我在图像的cli中使用ls cmd时,我看到了xlsx文件,为什么pandas无法读取它?
谢谢,希望我的解释清楚。
pandas 操作不需要读取 excel 个文件。因此,您还需要在需求文件中列出 xlrd 包。如果这不能解决问题,您将需要列出 requirements.txt 文件并添加 docker 错误消息将有助于提出您的问题。
其他可能性是:
- 可能是文件位置问题。
- 可能是 pandas 没有作为 pd 导入(我在代码中没有看到它)
我删除了 try expect 并且出现了这个错误:
Traceback (most recent call last):
File "./web_AuSpot.py", line 46, in <module>
infos_pay = pd.read_excel('/app-infos.xlsx', sheet_name='payplug')
File "/usr/local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 21, in __init__
import_optional_dependency("xlrd", extra=err_msg)
File "/usr/local/lib/python3.8/site-packages/pandas/compat/_optional.py", line 110, in import_optional_dependency
raise ImportError(msg) from None
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
(评论里放不下所以放了)
编辑:
我在需求中添加了xrld,更改了xlsx的位置路径,现在我有了这个:
Traceback (most recent call last):
File "./web_AuSpot.py", line 46, in <module>
infos_pay = pd.read_excel('app-infos.xlsx', sheet_name='payplug')
File "/usr/local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 37, in load_workbook
return open_workbook(filepath_or_buffer)
File "/usr/local/lib/python3.8/site-packages/xlrd/__init__.py", line 170, in open_workbook
raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported
我是Docker的新人,我需要运行一个Flask应用程序,但在这个应用程序中,我需要读取一个xlsx文件。
当我构建 docker 图像时,我有 excel 文件,但 Docker 没有读取它。
使用 xlsx 查看我的代码部分:
try :
# Page PayPlug
infos_pay = pd.read_excel('./app-infos.xlsx', sheet_name='payplug')
secret_key = infos_pay.loc[0].tolist()
payplug.set_secret_key(secret_key[0])
# Page mail
feuille_mail = pd.read_excel('./app-infos.xlsx', sheet_name='mail')
infos_mail = feuille_mail.loc[0].tolist()
except :
print("Can't read file")
还有我的 docker 文件:
FROM python:3.8
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD [ "python", "./web_AuSpot.py" ]
当我在图像的cli中使用ls cmd时,我看到了xlsx文件,为什么pandas无法读取它?
谢谢,希望我的解释清楚。
pandas 操作不需要读取 excel 个文件。因此,您还需要在需求文件中列出 xlrd 包。如果这不能解决问题,您将需要列出 requirements.txt 文件并添加 docker 错误消息将有助于提出您的问题。
其他可能性是:
- 可能是文件位置问题。
- 可能是 pandas 没有作为 pd 导入(我在代码中没有看到它)
我删除了 try expect 并且出现了这个错误:
Traceback (most recent call last):
File "./web_AuSpot.py", line 46, in <module>
infos_pay = pd.read_excel('/app-infos.xlsx', sheet_name='payplug')
File "/usr/local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 21, in __init__
import_optional_dependency("xlrd", extra=err_msg)
File "/usr/local/lib/python3.8/site-packages/pandas/compat/_optional.py", line 110, in import_optional_dependency
raise ImportError(msg) from None
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
(评论里放不下所以放了)
编辑:
我在需求中添加了xrld,更改了xlsx的位置路径,现在我有了这个:
Traceback (most recent call last):
File "./web_AuSpot.py", line 46, in <module>
infos_pay = pd.read_excel('app-infos.xlsx', sheet_name='payplug')
File "/usr/local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "/usr/local/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 37, in load_workbook
return open_workbook(filepath_or_buffer)
File "/usr/local/lib/python3.8/site-packages/xlrd/__init__.py", line 170, in open_workbook
raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported