Python AttributeError: 'NoneType' object has no attribute 'fileno'

Viewed 5872

as I am trying to print financial data:

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())

I get the error that df does not exist, or more specifically:

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'

I have no clue how to fix this, as this code seems to be working with everyone else who is trying it. I am just a beginner, so any help would be really appreciated. Thank you! Greetings, Tristan

4 Answers

This is not a full solution, but at least a workaround.

You can use shutil's get_terminal_size() instead. There's also a backport available for python 2.

I faced the same problem with the code below:

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

An easy hack would be to shift your work to the Python shell, instead of IDLE (in my case, working on IDLE was the problem, but this same code ran perfectly on the Python Shell)

In my case, I've used a screen session in the terminal to start up spyder IDE for python. I've accidentally terminated the screen session, but spyder kept working with this error. After I restarted spyder in a new screen session, the error disappeared.

Related