'AttributeError: module 'numpy.random' has no attribute 'BitGenerator' in python 3.8.10

I'm trying to import the xarray module into python 3.8.10 but I get this error:

AttributeError: module 'numpy.random' has no attribute 'BitGenerator'

In order to allow you to reproduce the error: First of all, I created a new environment with conda and by importing at the same time the modules I need (to avoid the problems of incompatible dependencies) :

conda create -n Myenv Python=3.8 matplotlib numpy time xarray netCDF4 termcolor

Then, I try to import in ipython3 all modules I need to run my code:

import matplotlib as mpl
mpl.use('agg')
import numpy as np
import os
import time
import glob
import sys
from datetime import datetime,date,timedelta
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.colors as colors
# from operator import itemgetter
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap, shiftgrid
from termcolor import colored
import xarray as xr

and, at this moment, I get the error...

I searched the documentation to see if the BitGenerator Attribute exists in my version of numpy (1.22.3), and it does. So I don't understand why this error occurs.

Someone can help me to understand please ?

Thank u !

If you want more informations about my environnement, I can provide.



Solution 1:[1]

I solved mine with pip install --upgrade numpy

Solution 2:[2]

Hint: Check if processedData outputs something.

Mistake: Looping over json data is incorrect as the response is an object and not an array. Create an IIFE and verify the first part then move ahead with chart creation. eg.

$(function () {
    var processedData = [];

    $.getJSON("https://api.alternative.me/fng/?date_format=en", function (json) {
            // wrong
             for (i = 1; i > json.length; i++){
                     processedData.push(json[i].value);
             }
    });
    console.log(processedData);
});

Solution 3:[3]

I reproduce your code and receive the data using this approach:

fetch("https://api.alternative.me/fng/?date_format=en")
  .then(response => response.json())
  .then(output => {
    const chartData = output.data.map(d => parseFloat(d.value))

Demo: https://jsfiddle.net/BlackLabel/s1fczwj0/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank Kusters
Solution 2 Dharman
Solution 3 Sebastian W?dzel