nx.draw_networkx shows module matplotlib has no attribute path - python-3.x

I'm trying to learn some Python graph visualization. while running the following piece of code I am encountering this error
AttributeError: module 'matplotlib' has no attribute 'path'
import pandas as pd
import matplotlib.pyplot as plt
import networkx as nx
FG = nx.from_pandas_adjacency(pandas_df)
nx.draw_networkx(FG, with_labels=True)
Any help would be appereciated, thanks in advance.

For some reason after I close and reopen the spyder it worked.

Related

Ordinal Logistic Regression in python and Google Colab

I have been trying to import statmodels (https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html#Probit-ordinal-regression:) to google colab without success.
I tried pip install statmodels which worked but then when I tried to import the ordinal model following the code from the above website:
import numpy as np
import pandas as pd
import scipy.stats as stats
from statsmodels.miscmodels.ordinal_model import OrderedModel
The following error message came up:
ModuleNotFoundError: No module named 'statsmodels.miscmodels.ordinal_model'
I have tried to follow the instruction from https://www.statsmodels.org/devel/install.html but I am not sure what went wrong, please help, thank you so much
The module location has changed to from statsmodels.discrete.discrete_model import OrderedModel

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.
I solved mine with pip install --upgrade numpy

ModuleNotFoundError: No module named 'plotly' but it work from workspace

i have read all the posts related to this topic but i could not find the solution for my case.
In my ubuntu 20.04 I have installed plotly through the command:
pip3 install plotly
and if i launch python3 from command line and if i run:
import plotly.graph_objects as go
it works perfectly. But if i launch the same command from python script "test.py":
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cgi
import cgitb
from datetime import date, timedelta
import datetime
import time
import numpy as np
import pandas as pd
import os
import calendar
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
import plotly.graph_objects as go
it returns the error log:
ModuleNotFoundError: No module named 'plotly'
Anyone can help me? many thanks
Ok, i resolved the issue by installing the module as a root user because in this way Python will try to search for the module’s name in the root directory and not in the usr one
thank you everyone

Yolo-v3 object detection with python

I'm trying to detect objects using Yolo-v3 referring this tutorial. I have already installed darknet.
When I tried to run the following code:
from darknet import Darknet
it says:
ImportError: cannot import name 'Darknet' from 'darknet' (unknown location)
so I tried:
import darknet as dn
net = dn.load_net("cfg/tiny-yolo.cfg", "tiny-yolo.weights", 0)
then it says:
"AttributeError: module 'darknet' has no attribute 'load_net'"
How I can avoid these errors?
Use it like this.
import cv2
import matplotlib.pyplot as plt
from utils import *
from darknet import Darknet
net = Darknet("cfg/tiny-yolo.cfg")
net.load_weights("tiny-yolo.weights")

ModuleNotFoundError: no module named 'scipy'

Hi I am bit of newby tinkering around with some machine learning, and I am getting an error in the python shell for scipy. I did a pip install for scipy in the windows command prompt and there are some odd looking errors when pip attempts to install. This is the simple little code I am using, any ideas to try for the scipy error?
import pandas as pd
import math
import numpy as np
import scipy
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
df = pd.read_csv('C:\\Users\\bbartling\\Documents\\Python\\test_SP data\\testElectData.csv')
df = df[['kWhDay','CDDbase55',]]
print(df.head())
# forecast_col = 'kWhDay'
X = np.array(df.drop(['kWhDay'],1))
y = np.array(df.drop(['CDDbase55'],1))
I figured this out on how to install python modules thru wheels. Good U tube video to make it work
https://www.youtube.com/watch?v=YXIlclFQZVU

Resources