如何为特定的python软件包安装所有依赖项?

时间:2020-04-08 09:43:36

标签: python pandas dependencies package

例如,当我安装一些python软件包pandas时,我想使用以下命令:

conda install pandas

这确实安装了pandas的某些开销,但不是全部!

当我运行以下代码时:

import pandas as pd

df = pd.DataFrame()
df.to_excel('a_excel_file.xlsx')

它给了我错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\Miniconda\envs\to_be_deleted2\lib\site-packages\pandas\core\generic.py", line 2181, in to_excel
    engine=engine,
  File "D:\Miniconda\envs\to_be_deleted2\lib\site-packages\pandas\io\formats\excel.py", line 726, in write
    writer = ExcelWriter(stringify_path(writer), engine=engine)
  File "D:\Miniconda\envs\to_be_deleted2\lib\site-packages\pandas\io\excel\_openpyxl.py", line 18, in __init__
    from openpyxl.workbook import Workbook
  File "D:\PyCharm Professional 2019.1.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'openpyxl'

openpyxl一样的外观没有被安装。为什么会这样?如何解决?

1 个答案:

答案 0 :(得分:1)

openpyxlpandas可选依赖项,这就是安装pandas时未安装它的原因。

pandas具有许多这样的可选依赖关系,这些依赖关系添加了有用但不是核心的功能-请参阅installation documentation以获取完整列表。