pythonjsonpandasimporterrorjson-normalize

ImportError: cannot import name 'json_normalize' from 'pandas.io.json'


python 3.9.2-3
pandas 2.0.0
pandas-io           0.0.1
Error: 
from pandas.io.json import json_normalize
ImportError: cannot import name 'json_normalize' from 'pandas.io.json' (/home/casaos/.local/lib/python3.9/site-packages/pandas/io/json/__init__.py)

Apparently this was a problem early on in the pre 1x days of pandas, but seems to have resurfaced. Suggestions?

I'm running a script which was functional previously, but migrating it to a new host. It errors out on the line:

from pandas.io.json import json_normalize

and throws the error

ImportError: cannot import name 'json_normalize' from 'pandas.io.json' (/home/casaos/.local/lib/python3.9/site-packages/pandas/io/json/__init__.py)

I've attempted to reinstall pandas ('install' option), remove and reinstall, and 'install --force-reinstall' all performed as root so that the base install of python3 has it installed as opposed to a single user


Solution

  • This was indeed the solution simply removing the import line. I'd have liked an attribute to check to determine the pandas version installed easily, but have to settle for a try:except: to determine if the import is needed.

    pandas.io.json.json_normalize was deprecated and removed in the newest version. Use pandas.json_normalize. Also, the tutorial you were following is most probably severely outdated. You are on your own now. – Ξένη Γήινος Apr 23 at 7:48