Python AttributeError:'NoneType'对象没有属性'fileno'

时间:2017-10-05 13:07:03

标签: python python-3.x pandas attributeerror datareader

因为我正在尝试打印财务数据:

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
import numpy as np
style.use('ggplot')
start=dt.datetime(2000,1,1)
end=dt.datetime(2016,12,31)
df= web.DataReader('ERIE', 'google', start, end)
print(df.head())

我得到的错误是df不存在,或者更具体地说:

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
print(df.head(5))
File "C:\Python34\lib\site-packages\pandas\core\base.py", line 51, in __str__
return self.__unicode__()
File "C:\Python34\lib\site-packages\pandas\core\frame.py", line 582, in __unicode__
width, _ = console.get_console_size()
File "C:\Python34\lib\site-packages\pandas\io\formats\console.py", line 77, in get_console_size
terminal_width, terminal_height = get_terminal_size()
File "C:\Python34\lib\site-packages\pandas\io\formats\terminal.py", line 33, in get_terminal_size
return shutil.get_terminal_size()
File "C:\Python34\lib\shutil.py", line 1071, in get_terminal_size
size = os.get_terminal_size(sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'

我不知道如何解决这个问题,因为这段代码似乎与正在尝试它的其他人一起工作。我只是一个初学者,所以任何帮助都会非常感激。 谢谢! 问候,特里斯坦

4 个答案:

答案 0 :(得分:0)

已知shutil库中的错误:

https://bugs.python.org/issue24920

https://bugs.python.org/issue24966

看来,你应该改变你开始编码的方式(从GUI或shell和类似的)

答案 1 :(得分:0)

这不是一个完整的解决方案,但至少是一种解决方法。

您可以改用shutil get_terminal_size()。 python 2还有一个backport

答案 2 :(得分:0)

我在下面的代码中遇到了同样的问题:

import pandas as pd
dict = {
"country" :["Brazil", "Russia", "India", "China", "South Africa"],
"capital" :["Brasilia", "Moscow", "New Delhi", "Beijing", "Pretoria"],
"area" : [8.516, 17.10, 3.286, 9.597, 1.221],
"population" : [200.4, 143.5, 1252, 1357, 52.98] }

brics = pd.DataFrame(dict)

brics

一个简单的技巧是将您的工作转移到Python Shell上,而不是IDLE(对于我来说,在IDLE上工作是个问题,但是相同的代码在Python Shell上运行得很好)

答案 3 :(得分:0)

就我而言,我已经在终端中使用了一个屏幕会话来启动适用于python的spyder IDE。我不小心终止了屏幕会话,但是spyder继续处理此错误。在新的屏幕会话中重新启动spyder后,错误消失了。