在Python中导入模块时出错 [英] Errors while importing modules in Python

查看:376
本文介绍了在Python中导入模块时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



作为Python的新手,当我尝试运行一些pandas和Matplotlib库的示例代码时,我遇到了错误,我不知道了解如何解决。



这是第一个示例代码...



Hi Everyone,

Being as a newbie in Python, while I tried to run some sample code of pandas and Matplotlib libraries, I got errors which I don't understand how to resolve.

Here is the first sample code...

import pandas

writer = pandas.ExcelWriter('farm_data.xlsx', engine='xlsxwriter')
pandas.to_excel(writer, sheet_name='Sheet1')

workbook = writer.book
worksheet = writer.sheets['Sheet1']

chart = workbook.add_chart({'type': 'column'})





对于这段片段,我得到了:



For this piece of snippet, I got:

AttributeError: module 'pandas' has no attribute 'to_excel'





除此之外,我还尝试运行另一个示例代码

示例:折线图 - XlsxWriter图表 [ ^ ]

我得到了这个



Apart from this, I tried to run another sample code
Example: Line Chart — XlsxWriter Charts[^]
and I got this

ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package





我已经拥有使用pip命令的模块(matplotlib,pandas)。



任何想法如何避免将来出现这种错误或者如何调试这些错误以节省宝贵的时间都会非常明显



我尝试过:



尝试:



在shell中导入matplotlib和pandas,没有发现错误。

我试图在网上找到类似的问题,得到一些与这个问题不同的问题。



I already have the modules (matplotlib, pandas) using pip command.

Any idea like how to avoid such kind of errors in future or how to debug these errors to save valuable time would be really appreciable

What I have tried:

Tried:

import matplotlib and pandas in shell, no error found.
I tried to find out the similar question on web, got some questions way different from this problem.

推荐答案

请参阅 pandas .Series.to_excel - pandas 0.20.3文档 [ ^ ]。并绘图命令摘要 - Matplotlib 2.0.2文档 [ ^ ]为第二个。
See pandas.Series.to_excel — pandas 0.20.3 documentation[^] for the first error. And Plotting commands summary — Matplotlib 2.0.2 documentation[^] for the second.


这篇关于在Python中导入模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆