Hi everyone, I'm trying to create a network visualization with python using the networkx package. Unfortunately I'm getting a "AttributeError: module 'scipy.sparse' has no attribute 'coo_array'" at the end of my code. I've tried to fix it but every help in the internet points towards upgrading pip or conda which I've done and still get the same error. I'm using jupyter notebooks - any help would be greatly appreciated!
#Prerequisites
import sys
!{sys.executable} -m pip install --user networkx
!{sys.executable} -m pip install --user numpy
!{sys.executable} -m pip install --user pandas
pip install notebook --upgrade
conda upgrade notebook
import networkx as nx
import numpy as np
import pandas as pd
from pathlib import Path
from pandas import DataFrame
#Read in Source File - NB this must match the schema requirements
df_InputData = pd.read_excel("/Users/paulkruse/Desktop/FR/Fr1.xlsx")
Src_Column = 'Source ID'
Tgt_Column = 'Target ID'
print(df_InputData);
#Nodes are positioned using the Fruchterman-Reingold force-directed algorithm.
Q = nx.Graph()
arr_SrcTgt= np.array(df_InputData[[Src_Column, Tgt_Column]])
print(arr_SrcTgt);
Q.add_edges_from(arr_SrcTgt)
dict_Coords = nx.spring_layout(Q)
It seems that your scipy version is out of date. The most recent version 1.8.1 certainly has coo_array function. One way to resolve this should be to upgrade scipy. If you're doing this from inside jupyter notebook, then use
!pip install --user scipy==1.8.1
Make sure to restart kernel after installation.
I imported sklearn DecisionBoundaryDisplay via the below command in my Google Colab file.
from sklearn.inspection import DecisionBoundaryDisplay
And I'm getting the following error.
ImportError: cannot import name 'DecisionBoundaryDisplay' from 'sklearn.inspection'
I even installed the following packages & also tried by restarting my runtime but still I'm getting the error.
!pip install --upgrade scikit-learn
!pip install scipy
!pip3 install -U scikit-learn scipy matplotlib
How to fix this issue?
what worked for me was installing scikit learn 1.1.0, i had version 1.0.2 before and got the same error you're encountering.
pip install -U scikit-learn --user
Hope it helps.
It seems DecisionBoundaryDisplay is a new feature and it is currently in an unstable development version. To use it, you need to install the nightly build.
Alpaca backtrader plot issue: I ran into this import issue and found this article, so I applied the code, but same issue not resolved. any one can help please?
My installed matplotlib version is 3.3.1
backtrader 1.9.76.123
python 3.8.5
the entire code posted below:
from matplotlib.dates
import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,MONTHS_PER_YEAR,
DAYS_PER_WEEK,SEC_PER_HOUR, SEC_PER_DAY,num2date, rrulewrapper,
YearLocator,MicrosecondLocator)
import alpaca_backtrader_api
import backtrader as bt
from datetime import datetime
#import matplotlib
ALPACA_API_KEY = "XXXXX"
ALPACA_SECRET_KEY = "XXXX"
ALPACA_PAPER = True
class SmaCross(bt.SignalStrategy):
def init(self):
sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
crossover = bt.ind.CrossOver(sma1, sma2)
self.signal_add(bt.SIGNAL_LONG, crossover)
cerebro = bt.Cerebro()
cerebro.addstrategy(SmaCross)
store = alpaca_backtrader_api.AlpacaStore( key_id=ALPACA_API_KEY,secret_key=ALPACA_SECRET_KEY,paper=ALPACA_PAPER)
if not ALPACA_PAPER:
broker = store.getbroker() # or just alpaca_backtrader_api.AlpacaBroker()
cerebro.setbroker(broker)
DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData
data0 = DataFactory(dataname='AAPL', historical=True, fromdate=datetime(2015, 1, 1), timeframe=bt.TimeFrame.Days)
cerebro.adddata(data0)
print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.run()
print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
cerebro.plot()
Downgrade to matplotlib 3.2.2 until the bug in backtrader is fixed.
Here is the fix pull request: https://github.com/mementum/backtrader/pull/418.
pip uninstall matplotlib # or conda
pip install matplotlib==3.2.2
I suffered the same problem like you did, your link provided has the perfect solution. just get rid of warnings from locator.py
https://community.backtrader.com/topic/981/importerror-cannot-import-name-min_per_hour-when-trying-to-plot/8
I couldn't install matplotlib==3.2.2 nor the patch without uninstalling backtrader first.
So, this worked for me in the end:
Uninstall backtrader:
pip uninstall backtrader
Install the patch provided in the above solution:
pip install git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
If necessary, install matplotlib again:
pip install matplotlib
As pointed out above, the issue is addressed in this pull request and the patch is the latest commit to master, but there hasn't been a release since 2019-05.
You can install the patched version like so:
pip install git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
You could alternatively specify the required commit in requirements.txt like so:
-e git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
…then pip install -r requirements.txt
After installing with either method, you can confirm the versions installed with pip freeze:
...
backtrader==1.9.76.123
...
How to install from git
Mac Big Sur
for me it only worked if:
Downgrade python3.9 to python 3.8
then I downgraded matplotlib==3.2.2
For both python 3.8.x and 3.9.x, I solved the problem by using specific version of matplotlib==3.2.2
pip install matplotlib==3.2.2
By default, I used matplotlib==3.4.x version and the problem occured.
All of the above answers are fine. The problem is not with Matplotlib though. The Backtrader library hasn't kept up with the Matplotlib updates. You can do the off-label Backtrader update suggested by Joel Brigate above...or you can make a simple mod to locator.py file (backtrader.plot):
Just change:
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR,
SEC_PER_MIN, MONTHS_PER_YEAR, DAYS_PER_WEEK, SEC_PER_HOUR,
SEC_PER_DAY, num2date, rrulewrapper, YearLocator,
MicrosecondLocator, warnings)
to:
from matplotlib import warnings
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,
MONTHS_PER_YEAR, DAYS_PER_WEEK, SEC_PER_HOUR,
SEC_PER_DAY, num2date, rrulewrapper,
YearLocator, MicrosecondLocator)
You'll note that the warnings import now comes directly out of matplotlib rather than matplotlib.dates. This is the offending issue within locator.py.
Here is my solution:
python -m pip uninstall matplotlib
python -m pip uninstall backtrader
python -m pip install backtrader
python -m pip install matplotlib==3.2.2
Enjoy!
I could not install matplotlib==3.2.2 with python 3.9 .
Here is how did I fix this issue:
$ pip uninstall backtrader
$ pip install git+https://github.com/mementum/backtrader.git#0fa63ef4a35dc53cc7320813f8b15480c8f85517#egg=backtrader
Reference:
Github: Fix ImportError from matplotlib.dates
#418
Mac Big Sur. I did the same: python 3.8.5, uninstall matplotlib, install matplotlib==3.2.2
I'm new at this so I first tried the easy way, through anaconda.org, but could not find version 3.2.2. Then tried it from the Jupyter notebook with conda install... didn't work. I finally did it straight through terminal, which worked fine.
#laffuste solution of downgrading to version 3.2.2 of matplotlib solved the issue for me. PR to fix the issue is still open, you can also follow this forum for more info on the problem:
I'm trying to learn PyCaret but having a problem when trying to import it in Jupyter Lab.
I'm working in a virtualenv and installed pycaret via pip:
pip install pycaret
I can confirm its installed via pip list:
prompt-toolkit 3.0.7
protobuf 3.13.0
py 1.9.0
pycaret 2.1.2
pycparser 2.20
The very first line in the notebook is:
from pycaret.nlp import *
however this results in:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-7c206b4a9ead> in <module>
----> 1 from pycaret.nlp import *
2 import psycopg2
3 import sys, os
4 import numpy as np
5 import pandas as pd
ModuleNotFoundError: No module named 'pycaret'
I'm pulling my hair out trying to figure this out and can't find anyone else with something similar.
I've tried to import via the python shell as well and that works perfectly.
You should create a seperate environment for installing time series alpha module
after creating a new environment and switching into
pip install pycaret-ts-alpha
and then you will be able to access
https://towardsdatascience.com/announcing-pycarets-new-time-series-module-b6e724d4636c
I forgot that you had to install modules via Jupyter.
Following this guide: http://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/index.html
Installing like so:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
Got it working
First Create a new environment conda documentation
Second Download the Pycaret with this instruction
Third check your sklearn version is greater thansklearn>=0.23.2.
Because if it's greater PyCaret is not compatible with that.
Nothing works for you? Download directly from github with this command
pip install git+https://github.com/pycaret/pycaret.git#egg=pycaret
I read on the tutorial page of pycaret that to install it through a Jupyter-notebook you should add an exclamation mark in front of the python command in the Jupyter-cell:
!pip install pycaret
Hi I am following a tutorial that was using matplotlib.finance to use candlestick.ohlc. When researching I found out that that lib was deprecated and to use mlp_finance. I believe I have installed it by running the command prompt and entering the line pip install mpl_finance. The result that I get this
I tried re running the script but I still get the error:
from mpl_finance import candlestick_ohlc
ModuleNotFoundError: No module named 'mpl_finance'
I checked the python library path and I don't see a folder labeled mlp_finance(Im not sure if Im suppose to). But I do see a file labeled mpl_finance-0.10.0-py3.7.egg
Any help on resolving this issue? Downloaded the git package and ran the command prompt install
ran the command line pip install git clone https://github.com/matplotlib/mpl_finance.git mpl_finance.git
I've got the same error you told, but I resolved it as below.
First, install mpl_finance
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
Second, upgrade mpl_finance
pip install --upgrade mplfinance
Hope that this will work.
If you want to follow that tutorial on mpl_finance, you can do so by installing the new mplfinance:
pip install --upgrade mplfinance
Then every place the tutorial tells you to import from mpl_finance change the import to from mplfinance.original_flavor, for example:
change:
from mpl_finance import candlestick_ohlc
to
from mplfinance.original_flavor import candlestick_ohlc
if you using Anaconda - To install this package with conda run:
conda install -c conda-forge mplfinance
You need to install matplotlib/mpl_finance at https://github.com/matplotlib/mpl_finance
git clone https://github.com/matplotlib/mpl_finance.git mpl_finance.git
cd mpl_finance.git
python setup.py install
mpl_finance has been deprecated, just install the module as mplfinance.
pip install mlp_finance will solve the issue