dtreeviz: from graphviz.backend cannot import name 'run' - python

dtreeviz library, ImportError: cannot import name 'run'
I tried to follow this instruction on Github to install and import the dtreeviz library.
When I run the where dot and dot -V command both seem to work fine as you can see here Lines in Windows Terminal.
However when I try to import dtreeviz in Python (Anaconda, version 3.6.5) I get the following error:
from dtreeviz.trees import *
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-fd764fe550c7> in <module>()
1 from sklearn import tree
----> 2 from dtreeviz.trees import *
C:\Users\marcb\Anaconda3\lib\site-packages\dtreeviz\trees.py in <module>()
6 from pathlib import Path
7 from sklearn import tree
----> 8 from graphviz.backend import run, view
9 import matplotlib.pyplot as plt
10 from dtreeviz.shadow import *
ImportError: cannot import name 'run'
I hope that someone can help me as I want to use this library to visualize single trees in Python and this library offers much more features than the original graphviz package.
Note: This is my first post on Stackoverflow, so feedback on this is also welcome.

I don't know if you are still looking for an awser, but i had exactly the same problem and fixed it this way:
In ~/.local/lib/python3.8/site-packages/dtreeviz/trees.py' i replaced the line
79: execute(' '.join(cmd), capture_output=True, check=True, quiet=False)
by
79: os.system(' '.join(cmd)).

Related

Can anyone help in fixing this constant "ModuleNotFoundError" on Google Colaboratory?

here is my code to import some python libraries:
from radmc3dPy import *
from radmc3dPy.image import *
from radmc3dPy.analyze import *
from radmc3dPy.natconst import *
import matplotlib.pyplot as plt
import numpy as np
import os
from astropy.io import fits
import matplotlib.gridspec as gridspec
On running the cell, I receive the following error even after factory resetting the runtime:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-225d47afe30d> in <module>()
----> 1 from radmc3dPy import *
2 from radmc3dPy.image import *
3 from radmc3dPy.analyze import *
4 from radmc3dPy.natconst import *
5 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'radmc3dPy'
you need to download and install the library before you can use it. I saw that there is a github for your package here: https://github.com/dullemond/radmc3d-2.0
in colab, you can install it with:
!git clone https://github.com/dullemond/radmc3d-2.0.git
%cd ./radmc3d-2.0/python/radmc3dPy/
!python setup.py install
%cd ~/../content
! and % are required.
The comand clones the desired directory from git, changes into the python directory, runs the setup of your package and changes your working directory back. Directly running the setup.py with the full path, did not work, hence changing the directory.

No module named hyppo._utils when importing models

My issue is when trying to import the DCSBM model:
Code:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import hyppo
from hyppo.time_series import _utils as _utils
from graspy.embed import AdjacencySpectralEmbed
from graspy.models import DCSBMEstimator
from graspy.models import EREstimator
from graspy.models import SBMEstimator
from graspy.models.sbm import _block_to_full, _get_block_indices
from graspy.simulations import er_np, sbm
Error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-33-287386449480> in <module>()
8 from hyppo.time_series import _utils as _utils
9 from graspy.embed import AdjacencySpectralEmbed
---> 10 from graspy.models import DCSBMEstimator
11 from graspy.models import EREstimator
12 from graspy.models import SBMEstimator
2 frames
/usr/local/lib/python3.7/dist-packages/graspy/inference/latent_distribution_test.py in <module>()
26 from sklearn.metrics.pairwise import PAIRWISE_KERNEL_FUNCTIONS
27 from hyppo.ksample import KSample
---> 28 from hyppo._utils import gaussian
29
30 _VALID_DISTANCES = list(PAIRED_DISTANCES.keys())
ModuleNotFoundError: No module named 'hyppo._utils'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
I think hyppo._utils doesn't exist and has been replaced by hyppo.time_series and inside that folder there exists the required _utils package.
How do we fix this?
I was just trying to run the tutorial: https://docs.neurodata.io/notebooks/pedigo/graspologic/2020/09/24/latent_model_tutorial.html
Run on Google colab
This line
from hyppo.time_series import _utils as _utils was added from me trying to fix the issue, but doesn't work.
Looks like you're using an old version of the package - it's called "graspologic" now. If you pip install graspologic, from graspologic.models import DCSBMEstimator should work fine. Just replace everything in that code that says "graspy" with "graspologic".
we're happy to answer questions on github issues as well! (I'm one of the people who contributes to the package)

Regarding python Module in anaconda environment

I am very new to python and i am trying to follow the cs231n course by doing coding examples using python.
I created the virtual environment ,based on this tutorial http://cs231n.github.io/setup-instructions/
After that i changed the environment in anaconda navigator also as follows,
Still , when i try to import the relevent packages i am getting a error.
import random
import numpy as np
from cs231n.data_utils import load_CIFAR10
import matplotlib.pyplot as plt
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-19cb248684d4> in <module>
1 import random
2 import numpy as np
----> 3 from cs231n.data_utils import load_CIFAR10
4 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'cs231n'
Can anyone help me to figure this out ? I tried myself to fix this but i couldn't find a solution.
Thank you

is fastai.structured still a part of fast ai library

Why i am getting the error fastai.structured is not a module?.
i have tried installing previous versions of fastai. but nothing helped.
from fastai.imports import *
from fastai.structured import *
#from pandas_summary import DataFrameSummary
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from IPython.display import display
from sklearn import metrics
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-17-35432a48f631> in <module>()
1 from fastai.imports import *
----> 2 from fastai.structured import *
3
4 #from pandas_summary import DataFrameSummary
5 from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
ModuleNotFoundError: No module named 'fastai.structured'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
That module is no longer included in fastai's default python packages. Your default setup commands for using fastai packages will no longer includes that module. You may need to download it from the GitHub master, save it to your working directory, and import from your working directory to your jupyter notebook.
Here's a note from the fastai forum:
The structured.py has been moved to folder “old” (in anticipation to fastai_v1).
https://github.com/fastai/fastai/blob/master/old/fastai/structured.py
--- Andrei Oct '18
When importing from your working directory:
from structured import *
This will replace:
from fastai.structured import *
The module’s name has been changed to “tabular”. So use “from fastai.tabular import *” instead.
see this >> https://forums.fast.ai/t/modulenotfounderror-no-module-named-fastai-structured/36904

Numpy & Matplotlib suddenly cannot be imported in Atom although it works fine in the Terminal

I'm regularly importing Matplotlib Numpy PySide2 in Atom. They unexpectedly cannot be import for an unknown reason and then appear to be again re-importable, again unexplained.
When trying to import matplotlib with the following command
import matplotlib.pyplot as plt
This scripts runs without problems when I run in a Jupyter notebook or through the Terminal. But When trying to run on Hydrogen in Atom, I get the following error message:
File "<ipython-input-3-3dc8365ef973>", line 6
ModuleNotFoundError: No module named 'matplotlib.backends'; 'matplotlib' is not a package
^
SyntaxError: invalid syntax
I get the same error with Pyside2 when trying to run the line
from PySide2.QtWidgets import QApplication, QLabel
I get the error message
ModuleNotFoundError: No module named 'PySide2.QtWidgets'; 'PySide2' is not a package
Here is the path of python (after having typed which python in the Terminal): /anaconda3/bin/python
I checked that the matplotlib is installed by running the command conda list in the Terminal and got (among all the other packages) those lines:
matplotlib 2.1.2 py36h6d6146d_0
matplotlib 2.2.2 <pip>
PySide2 5.9.0a1.dev1525348214
I tried to run the following command in the Terminal but didn't solve the problem
sudo apt-get install python3-matplotlib
sudo pip3 install matplotlib
I had a similar issue with numpy when trying to import import numpy. Although import numpy was not a problem an hour ago, I get now the following error message (it seems it wants to connect to a previously used script in which numpy was used, to open numpy itself):
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-592c151f282b> in <module>()
1 # from numpy import genfromtxt as gft
----> 2 import numpy
~/Downloads/numpy.py in <module>()
----> 1 from numpy import genfromtxt
2 my_data = genfromtxt('/Users/mymac/Documents/PyQt/image_viewer/csv_file_generator/eggs.csv',
3 delimiter=',',
4 dtype=None,
5 encoding=None)
ImportError: cannot import name 'genfromtxt'
I had the same issue when tryin to import opencv2: I got the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import---------------------------
------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-8f6675581547> in <module>()
5 from PySide2.QtCore import *
6 from PySide2.QtGui import *
----> 7 import cv2
8 import numpy
9 import csv
ImportError: numpy.core.multiarray failed to import
I visited the following site which didn't help me (or I didn't understand how to implement exactly the steps to fix the problem)
ImportError: No module named matplotlib.pyplot
Importing matplotlib.pyplot in atom editor
matplotlib Error: No module named matplotlib even though it is installed
I'm running on/with
python 3.6.5
macOS 10.13.4
Atom 1.27.0 x64
Hydrogen 2.4.1

Categories

Resources