Problem importing pandas_datareader in Python - python

I want to get historic and current data stock prices from yahoo finance and/or google finance with python. To do so, I installed pandas and pandas_datareader on my machine. When I import pandas everything goes fine, but when I import pandas_datareader I get an error. More specifically, the following script
import pandas
import pandas_datareader
generates the following error
File "a.py", line 5, in <module>
import pandas_datareader
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
I tried to reinstall pandas_datareader, but It still doesn't work. Any idea what the problem might be? I use python3 on macBook Pro (beginning 2015) with macOS High Sierra Version 10.13.5.

Try this:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader
and let me know if it worked :)

Related

conda: importing pandas package produces error on vscode

I'm new to conda, but I'm sure I have pandas installed in the base environment. I also have selected it as the python interpreter in VSCode. However, when I try to import pandas it throws the following error:
Traceback (most recent call last):
File "/Users/raimundbuehler/Documents/UNIDOCS/Python:Psychopy:RALT/Rando/Randomization.py", line 2, in <module>
import pandas as pd
File "/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import is_numpy_dev as _is_numpy_dev
File "/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/compat/__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/compat/numpy/__init__.py", line 4, in <module>
from pandas.util.version import Version
File "/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/util/__init__.py", line 1, in <module>
from pandas.util._decorators import ( # noqa:F401
File "/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/util/_decorators.py", line 14, in <module>
from pandas._libs.properties import cache_readonly # noqa:F401
File "/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/_libs/__init__.py", line 13, in <module>
from pandas._libs.interval import Interval
ImportError: dlopen(/Users/raimundbuehler/opt/anaconda3/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so, 0x0002): rebase opcodes terminated early at offset 1 of 1800
I'm assuming numpy to be the problem, but updating both numpy and pandas didn't solve it. It may also be because I have Pycharm and pip installed, so it may be messy regarding multiple installations of python and packages... in fact in Pycharm, I can import pandas (using a different interpreter). Any help how to find out if this is indeed the case and how to solve it would be greatly appreciated!
I refer to this issue.
I think the feasible way may still be to unload and reinstall.

Is there a specific way to import openpyxl in tkinter?

I am relatively new to writing code in tkinter, so I apologize for this question. I am writing an application in tkinter, where I want to update the values in Excel based on the entries in widgets.
I have tried installing openpyxl through pip install, and a manual install. I have moved openpyxl to the folder of my project, but has not helped at all.
from tkinter import *
from tkinter import ttk
import tkinter as tk
from datetime import datetime
from tkinter import messagebox
import os
import pandas as pd
import xlrd
import xlwt
from pandas import ExcelWriter
from pandas import ExcelFile
import sqlite3
import getpass
import openpyxl
I get error
Traceback (most recent call last):
File "C:/Users/vik.makker/Desktop/NewProj/Internal Inventory Tracking System.py", line 1, in <module>
import openpyxl
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\__init__.py", line 5, in <module>
from openpyxl.workbook import Workbook
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\workbook\__init__.py", line 5, in <module>
from .workbook import Workbook
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\workbook\workbook.py", line 8, in <module>
from openpyxl.worksheet.worksheet import Worksheet
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\worksheet\worksheet.py", line 30, in <module>
from openpyxl.cell import Cell, MergedCell
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\cell\__init__.py", line 4, in <module>
from .cell import Cell, WriteOnlyCell, MergedCell
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\cell\cell.py", line 32, in <module>
from openpyxl.utils.datetime import (
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\utils\datetime.py", line 13, in <module>
from jdcal import (
ModuleNotFoundError: No module named 'jdcal'
The error is that although you've installed openpyxl, you haven't installed all of its dependencies (could be just a mistake in how the people that wrote openpyxl specified what packages their tool required). The last line of your error message says that you will also need to install jdcal, I suspect your code will work fine after that.

I'm getting unstable API warning and also getting error 'pandas_datareader._utils.RemoteDataError: Unable to read URL:' [duplicate]

I am working in a virtual environment. I am able to import and work in pandas without any error but when I am trying to import pandas_datareader
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from matplotlib import style
import pandas_datareader as web
it is giving following error -
Traceback (most recent call last):
File "stock.py", line 6, in <module>
import pandas_datareader as web
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
(env) xxxxx#xxxxx-yyyyy ~/pyt $ python stock.py
Traceback (most recent call last):
File "stock.py", line 6, in <module>
import pandas_datareader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
A solution without changing any files locally and bypass the version control of your package manager (pip) is to define is_list_like like this:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
right before
import pandas_datareader as web
Furthermore this problem will be fixed in pandas_datareader version 0.7.0 release.
I meet this error and I found a method to solve it. My pandas and pandas_datareader versions are 0.23 and 0.6.
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas_datareader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
Because the is_list_like is moved to pandas.api.types, I change the fred.py file which is highlighted in the picture. I replace from pandas.core.common import is_list_like with from pandas.api.types import is_list_like, and it works.
This is due to the fact that is_list_like has been moved from pandas.core.common to pandas.api.types in Pandas 0.23.0. This issue has been repaired here and will be a part of the Pandas Datareader 0.7.0 release. For now, I would recommend using the dev version of Datareader. Instructions for installing can be found in the documentation.
If you are not working with pandas_datareader. you need to check your conda environment data reader is installed or not if not install than you can import this way this.
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web
Edit fred.py file inside /your_installation_path/python2.7/site-packages/pandas_datareader and replace as below:
from pandas.core.common import is_list_like #COMMENT IT
from pandas.api.types import is_list_like #ADD
In Ubuntu 18.04, using Python 3.6 I resolved the error in the following way.
cd /home/username/.local/lib/python3.6/site-packages/pandas_datareader
subl fred.py
and I changed the first line of code which was
from pandas.core.common import is_list_like
to
from pandas.api.types import is_list_like

Pandas Error: cannot import name 'is_list_like' [duplicate]

I am working in a virtual environment. I am able to import and work in pandas without any error but when I am trying to import pandas_datareader
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
from matplotlib import style
import pandas_datareader as web
it is giving following error -
Traceback (most recent call last):
File "stock.py", line 6, in <module>
import pandas_datareader as web
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
(env) xxxxx#xxxxx-yyyyy ~/pyt $ python stock.py
Traceback (most recent call last):
File "stock.py", line 6, in <module>
import pandas_datareader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/home/xxxxx/django-apps/env/lib/python3.5/site-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
A solution without changing any files locally and bypass the version control of your package manager (pip) is to define is_list_like like this:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
right before
import pandas_datareader as web
Furthermore this problem will be fixed in pandas_datareader version 0.7.0 release.
I meet this error and I found a method to solve it. My pandas and pandas_datareader versions are 0.23 and 0.6.
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas_datareader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File "/usr/local/lib/python3.6/dist-packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
Because the is_list_like is moved to pandas.api.types, I change the fred.py file which is highlighted in the picture. I replace from pandas.core.common import is_list_like with from pandas.api.types import is_list_like, and it works.
This is due to the fact that is_list_like has been moved from pandas.core.common to pandas.api.types in Pandas 0.23.0. This issue has been repaired here and will be a part of the Pandas Datareader 0.7.0 release. For now, I would recommend using the dev version of Datareader. Instructions for installing can be found in the documentation.
If you are not working with pandas_datareader. you need to check your conda environment data reader is installed or not if not install than you can import this way this.
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web
Edit fred.py file inside /your_installation_path/python2.7/site-packages/pandas_datareader and replace as below:
from pandas.core.common import is_list_like #COMMENT IT
from pandas.api.types import is_list_like #ADD
In Ubuntu 18.04, using Python 3.6 I resolved the error in the following way.
cd /home/username/.local/lib/python3.6/site-packages/pandas_datareader
subl fred.py
and I changed the first line of code which was
from pandas.core.common import is_list_like
to
from pandas.api.types import is_list_like

ImportError: cannot import name 'PandasError'

I am very new to Python 3x, running on a mac.
Currently using a sentdex tutorial for python with finance, tried running the following script:
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2000,1,1)
end = dt.datetime(2016,12,31)
df = web.DataReader('TSLA', 'yahoo', start, end)
print(df.head())
However this returns the following error message:
Traceback (most recent call last):
File "F:\Downloads\Python Work\try figuring thigns out\finance\try.py", line 1, in <module>
import pandas_datareader.data as web
File "C:\Python36\lib\site-packages\pandas_datareader\__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "C:\Python36\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "C:\Python36\lib\site-packages\pandas_datareader\google\daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "C:\Python36\lib\site-packages\pandas_datareader\base.py", line 13, in <module>
from pandas_datareader._utils import (RemoteDataError, SymbolWarning,
File "C:\Python36\lib\site-packages\pandas_datareader\_utils.py", line 5, in <module>
from pandas.core.common import PandasError
ImportError: cannot import name 'PandasError'
I think maybe there's something wrong with panda-datareader itself, which I've ensured has been upgraded to most recent version (pandas-datareader 0.3.0.post0)
Is there an older version I can install instead? I've been using pip3 to install via mac terminal.
Thanks very much for any help!
I think you installed pandas v. 0.20.1 released yesterday.
pandas-datareader is still not compatible with this version, for the moment you should stay on pandas 0.19.2:
pip install -U pandas==0.19.2
The latest version of pandas_datareader (0.5.0) takes care of this import error. You can install it with pip:
sudo pip install -U pandas_datareader
I may already be too late to the discussion but I encountered this earlier today using a brand new Azure Compute that I spun up, I did all the steps above and was always encountering the error.
It may not be explicitly stated above but restarting the kernel AFTER the steps above fixed the issue.

Categories

Resources