Graphviz not running in jupyter notebook python = 3.6? - anaconda

I am trying to run graphviz to view dot file on jupyter notebook in have imported path to dot.exe path.
G:\anaconda3\envs\tensorflowgpu\Library\bin\graphviz
G:\anaconda3\envs\tensorflowgpu\Library\bin\graphviz\dot.exe
I am trying to run this code:
with open("tree1.dot") as f:
dot_graph = f.read()
graphviz.Source(dot_graph)
OR
graphviz.Source("tree1.dot") .view()
It is giving:
failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH
Please tell me any way to fix this or any other way to View dot file on jupyter notebook i am running python 3.6 on jupter notebook

I have been having a similar issue (different execution - but both have the same errors in Jupyter) and was able to resolve it this way:
First I uninstalled the graphviz package I had originally installed via the Anaconda prompt.
conda remove graphviz
I found in this issue thread to use the below command to install the graphviz package. Appending graphviz with python- downloads the package in lib/site-packages
conda install python-graphviz
I restarted Jupyter Notebook in order to find dot.exe since I couldn't get it to find it in my running notebook after installing the package.
I hope this helps!

if you code doesn´t work, you can use this.
import graphviz
from IPython.display import display
with open("tree1.dot") as f:
dot_graph = f.read()
display(graphviz.Source(dot_graph))

Reinstall graphviz
conda remove graphviz
conda install python-graphviz
graphviz.Source(dot_graph).view()
after you will have a small window where you have to choose where you want see your decision tree

the following worked for me (removal in Jupyter via 'conda remove graphviz' didn't work):
go to Anaconda Navigator Console:
-->Environments--> Search for graphviz --> deinstall
-->Environments --> install python-graphviz

Related

Kernel Error in R Jupyter Notebook due to Anaconda?

I need to bundle R scripts into some Notebook such as Jupyter Notebook. My OSX setup contains Homebrew, Rstudio and Anaconda. Next I try to get R in Jupyter Notebook working. I am getting the following error
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/Cellar/r/3.3.3_1/R.framework/Resources/bin/R': '/usr/local/Cellar/r/3.3.3_1/R.framework/Resources/bin/R'
that shows that paths are somehow messed up. Also, the Jupyter Notebook shows Kernel Error in Red. The path /Users/hhh/anaconda3/envs/ is a Anaconda path so this must be an issue with Anaconda and Jupyter Notebook.
How to get R running in Jupyter Notebook under Conda? How to resolve the Kernel error?
Questions separated about potential Conflicts
Potential conflicts due to Homebrew and Anaconda here.
Your conda manages your bindings to R. You need to install the IRkernel package via conda such that
$ conda install -c r r-irkernel
to resolve the error.

Basemap library using Anaconda Jupyter Notebooks - KeyError: PROJ_LIB

I'm trying to install and import the Basemap library into my Jupyter Notebook, but this returns the following error:
KeyError: 'PROJ_LIB'
After some research online, I understand I'm to install Basemap on a separate environment in Anaconda. After creating a new environment and installing Basemap (as well as all other relevant libraries), I have activated the environment. But when importing Basemap I still receive the same KeyError.
Here's what I did in my MacOS terminal:
conda create --name Py3.6 python=3.6 basemap
source activate Py3.6
conda upgrade proj4
env | grep -i proj
conda update --channel conda-forge proj4
Then in Jupyter Notebook I run the following:
from mpl_toolkits.basemap import Basemap
Can anyone tell me why this results in a KeyError?
Need to set the PROJ_LIB environment variable either before starting your notebook or in python with os.environ['PROJ_LIB'] = '<path_to_anaconda>/share/proj'
Ref. Basemap import error in PyCharm —— KeyError: 'PROJ_LIB'
In Windows 10 command line: first find the directory where the epsg file is stored:
where /r "c:\Users\username" epsg.*
...
c:\Users\username\AppData\Local\conda\conda\envs\envname\Library\share\epsg
...
then either in command line:
activate envname
SET PROJ_LIB=c:\Users\username\AppData\Local\conda\conda\envs\envname\Library\share
(make sure there are no leading on trailing spaces in the path!) and then
jupyter notebook
or add this to your jupyter notebook (as suggested by john ed):
import os
os.environ['PROJ_LIB'] = r'c:\Users\username\AppData\Local\conda\conda\envs\envname\Library\share'
The problem occurs as the file location of "epsg" and PROJ_LIB has been changed for recent versions of python, but somehow they forgot to update the init.py for Basemap. If you have installed python using anaconda, this is a possible location for your espg file:
C:\Users\(xxxx)\AppData\Local\Continuum\anaconda3\pkgs\proj4-5.1.0-hfa6e2cd_1\Library\share
So you have to add this path at the start of your code in spyder or whatever field you are using.
import os
os.environ['PROJ_LIB'] = r'C:\Users\(xxxx)\AppData\Local\Continuum\anaconda3\pkgs\proj4-5.1.0-hfa6e2cd_1\Library\share'
from mpl_toolkits.basemap import Basemap
If you can not locate epsg file at all, you can download it here:
https://raw.githubusercontent.com/matplotlib/basemap/master/lib/mpl_toolkits/basemap/data/epsg
And copy this file to your PATH, e.g. to:
os.environ['PROJ_LIB'] = 'C:\Users\username\Anaconda3\pkgs\basemap-1.2.0-py37h4e5d7af_0\Lib\site-packages\mpl_toolkits\basemap\data\'
This is the ONLY solution that worked for me on Windows 10 / Anaconda 3.
Launch Jupyter Notebook from command prompt and it won't throw the same error. It somehow works for me!

keras plot_model tells me to install pydot

I'm using python 3.6.3 on a windows 10 machine. I installed pydot and graphviz using pip install via:
py -m pip install pydot
py -m pip install graphviz
I also went to the graphviz website and downloaded and installed the windows version here: http://www.graphviz.org/Download_windows.php which default installed to program files(x86). But when I go to plot my model in keras, I still get the error saying I have to install pydot and graphviz and that the import failed. I can do
import pydot
import graphviz
on my python console just fine, they throw no errors. What else should I do to be able to graph my neural net?
The path(s) to the installed GraphViz executables (dot, neato, etc.) need to be in the PATH environment variable, in order for pydot to find them. pydot used to search for those executables in earlier versions, but not any more.
Also:
pydot is a Python package.
GraphViz is a collection of tools written in C for computing graph layouts
graphviz is a Python package entirely unrelated to pydot. These two Python packages do not interact in any way with each other. Installing one of them should suffice (together with GraphViz).
See also:
https://github.com/erocarrera/pydot/issues/126
https://github.com/erocarrera/pydot/commit/812e3c40dac1e0225391481073c64da5bafba93e#commitcomment-18236709
https://github.com/erocarrera/pydot/commit/812e3c40dac1e0225391481073c64da5bafba93e#commitcomment-18222580
and links from there.
Complementing #Ioannis answer, you have to install GraphViz executables via conda (conda install GraphViz).
For my case, after installing GraphViz I tried with the latest pydot (pip install pydot) and the error was resolved.
Just to complete the #dataLeo 's solution, Python 3 users can use pydotplus package instead of pydot-ng package. To summarize:
install pydot+graphviz and pydotplus by commands "conda install pydot" and "conda install -c conda-forge pydotplus".
Go to the vis_utils.py file and change line 11 from import pydot to
import pydotplus as pydot.
PS: You can locate the vis_utils.py file by checking help for plot_model command in ipython console, i.e. after from keras.utils import plot_model, type ??plot_model in ipython console.
Tested on Windows 10-64 bit with Anaconda python-3.6
I solved this problem by installing the packages with :
conda install graphviz
conda install pydot
conda install pydotplus

ijavascript will not install

I have been trying to run Javascript from a Jupyter Notebook on Windows 10 but failed miserably. It seems I cannot install IJavascript to make it available.
All installation guides say to use Anaconda for IJavascript - so I did, but I CANNOT FIND IJAVASCRIPT anywhere within Anaconda, only the js packages, i searched everywhere there was a search bar available. So, because I am stubborn i tried the hard way:
Installed all javascript packages except mocha (which cannot be found) listed here:
https://anaconda.org/javascript/repo
then tried
npm install -g ijavascript
but keep getting this error:
c:\users\ryuuzako\anaconda3\scripts\node_modules\ijavascript\node_modules\nan\nan_json.h(89): error C2660: 'v8::JSON::P
arse': function does not take 2 arguments [C:\Users\ryuuzako\Anaconda3\Scripts\node_modules\ijavascript\node_modules\ze
romq\build\zmq.vcxproj]
"Javascript" type does not appear when creating a new file in Jupyter, my guess is because ijavascript is not installed..
ANY suggestion to make it work is greatly appreciated.
I can provide the whole npm log but it is humongous.
Feel free to assume i am a complete idiot who didn't work with node before.
I've just forked ijavascript and edited the documentation for the Windows installation section as shown below.
Windows
Install Python3 or the Anaconda3 Python distribution.
In the command line:
pip3 install --upgrade pip
pip3 install jupyter
npm install -g ijavascript
ijsinstall
If the ijinstall command is not recognized, you can execute it manually by navigating to your npm install directory and running the ijinstall batch file. If you do not know where your npm install is located, try looking for it in the default install location: C:\Users\USERNAME\AppData\Roaming\npm.
Then you can run jupyter notebook in your terminal to load Jupyter Notebook. When you create a new Jupyter Notebook, you should see the Javascript (Node) kernel available.
If using the Anaconda alternative to the standard Python distribution, it comes pre-installed with Jupyter Notebook. If using Anaconda, you can skip the pip3 install jupyter step.
This picture might also help, when it comes to the ijinstall part.
I struggled with this as well. After installing by running commands:
pip install jupyter
npm install -g ijavascript
You will need to update the environment variable named 'Path' in the 'System Variables' section.
In Windows 10, Python 3.10, the path to add looks like:
C:\Users\your-windows-user\AppData\Roaming\Python\Python310\Scripts
After changing the environment variable, you will need to re-start the computer for it to take effect.
Once this is done, run:
ijsinstall
in the command prompt and you should be good to go.
This also happeed to me.
First thing install anaconda after that(by default you have installed jupyter),
then search in your menu apps for anaconda prompt, then install ijavascript from anaconda prompt:
npm install -g ijavascript
ijsinstall
then run jupyter from anaconda prompt
jupyter notebook

Error no module named tensorflow in Anaconda for mac

I installed tensorflow as described for Anaconda installation in the tensorflow.org. I could run the tensorflow in the Mac terminal just typing,
$ source activate tensorflow
$ python
import tensorflow as tf
But, when I run iPython notebook, it does not work by showing an error of no module named tensorflow. I felt like tensorflow was correctly installed but iPython notebook could not recognize it. Is there any way to fix it?
Please have a look at your path. When you do the command 'source activate tensorflow', your path may have changed. The example is following.
sherrie#sherrie-PC:~/tensorflow/tensorflow/examples/udacity$ source activate tensorflow
discarding /home/sherrie/anaconda2/bin from PATH
prepending /home/sherrie/anaconda2/envs/tensorflow/bin to PATH
Tensorflow is installed in the first path, instead of the second one.
The most important step comes. Open your directory of 'anaconda' --> find the 'envs' --> open 'tensorflow' --> copy all files in 'sitepack0ages' to 'anaconda/lib/python2.7/sitepack-ages'. Done.
My answer is based on this other answer: Trouble with TensorFlow in Jupyter Notebook. I had the exact same problem, and I solved it by doing this:
Once your environment is activated, run "which jupyter" and verify if the path returned points to the /bin folder under your environment, something like /my_environments_path/my_tensorflow_environment_name/bin/jupyter. If this is already the case, your scenario is different from the one I had;
Run "which pip" and/or "which pip3". Odds are, you are executing pip or pip3 from a different location, so Jupyter is not being installed inside your environment. In my case, Python version was 3.6, but pip3 was being called from a different location. I ran "pip install jupyter", since pip was inside the /bin folder in my environment. Once I called the correct pip, I checked again the "which jupyter" command, and this time Jupyter was under my environment and I could import Tensorflow inside my notebooks. If no pip's path points to your environment, install pip inside it by running "conda install pip".
I hope this works, along with the additional information on the link above.

Resources