Graphviz executables not found. Python 3 - python-3.x

I`m trying to get this code to run:
Getting started with Graphviz and Python
http://matthiaseisen.com/articles/graphviz/
import graphviz as gv
g1 = gv.Graph(format='svg')
g1.node('A')
g1.node('B')
g1.edge('A', 'B')
print(g1.source)
this part works fine, but...
filename = g1.render(filename='img/g1')
print (filename)
-> make sure the Graphviz executables are on your systems' PATH
I found similar questions/answers, but I dont know much about the Windows registry, so I dont dare to experiment a lot there. I downloaded Graphviz as zip-file, and I did conda install graphviz at some point. Python 3.6 is installed per default. C:\Users\Oliver\Appdata\Local\Programs\Python36.
I go to Control Panel - System - Advanced System - Environment Variables, but what exactly do I have to change there?

I could finally solve this:
The graphviz zip I had direcly extracted directly in my Downloads-folder (or wherever you want to have it).
Control Panel - System - Advanced System - Environment Variables
Then in the lower half, System Variables (not User variables), double-klick Path: klick New and browse to the graphviz bin-folder.

Related

pycharm has no Qt platform plugin could be initialized error when using matplotlib

I installed my python as an independent program into my personal user folder on windows 10:
C:\Users\My.Name\AppData\Local\Programs\Python\Python39\
Then I installed all packages that I want from inside PyCharm 2021.2.3 community version via
File->Settings->Add package
It's been ok and I can run my numpy pandas data project etc. But when I add the matplotlib library and tried to do simple plot, it gave the no Qt platform plugin could be initialized error.
I searched for answers and proceed to install the following packages:
PyQt5
PyQt5-Qt5
PyQt5-sip
PyQt5-stubs
pyqt5-plugins
pyqt5-tools
qt5-applications
qt5-tools
Then I checked in these package's bin\ folders to ensure the 'platforms' folder exists and the qwindows.dll is present.
But matplotlib still fails with that no Qt platform error.
Found out that I have to put the PyQt5's lib path into my PATH environment variable like below:
First, go open the 'Edit Environment Variables for your account' dialog
Then, add the following 3 entries on TOP of the path list:
C:\Users\My.Name\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyQt5\Qt5\bin
C:\Users\My.Name\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyQt5\Qt5\plugins
C:\Users\My.Name\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyQt5\Qt5\plugins\platforms
Also, if you have a variable named: QT_PLUGIN_PATH, you want to put this line at the TOP of the list:
C:\Users\My.Name\AppData\Local\Programs\Python\Python39\Lib\site-packages\PyQt5\Qt5\plugins
After saving your environment variables, you need to restart PyCharm to have it "find" these libraries.
Well, this got me past this no Qt platform error in this case. But I have other python-qt programs that needs other python versions/install path, this will break those programs. I have found that pyqt programs usually have this problem, I still think (and sincerely hope) there is better approach than to mess with the PATH environment. I am still open to other suggestions of course.

Can anyone help me installing PYPY on windows?

I would like to know the more brief version of the installation of pypy on Windows apart from original documentation available on https://doc.pypy.org/en/latest/windows.html. Any help in showing a step by step guide would be appreciated. Thanks in advance.
The link you referenced is about building PyPy from source, so the parallel in CPython would be https://devguide.python.org/setup/.
The vast majority of users (99.99%) will not want to do this. They want to use PyPy as an interpreter to run python code, and should be looking at the (agreed, too-long) instructions on the download page. Specifically,
download the zip file, and extract it somewhere. Explorer suggests C:\Users\matti\Documents\pypy3.6-v7.3.1-win32 for me, that is fine.
Next set up the new pypyp interpreter by getting pip and setuptools installed. Click on Start and type "cmd" then click on "Comand Prompt" to open a text terminal. Once there type <path\to\pypy> -m ensurepip, so for me that would be C:\Users\matti\Documents\pypy3.6-v7.3.1-win32\pypy3.6-v7.3.1-win32\pypy3.exe -m ensurepip which should print at the end Successfully installed pip-20.0.2 setuptools-44.0.0
Open a new file in VS Code, and click on the "Python" at the far left of the status bar (bottom left corner in my default VSCode layout), and choose the path to pypy3.exe as the one to use for this file.
I think that is it? You may want to let VS Code install things like a linter or other tools, that is fine.
PyPy is also available via Conda, which is slowly building out all the packages specifically for PyPy: Numpy, Scipy and others are already available, matplotlib should be coming soon.

Where do I add Graphviz's Executable on a Mac

I'm trying to use Graphviz but am getting the error message:
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'test-output/aoc.gv.pdf'], make sure the Graphviz executables are on your systems' PATH
The code I am running is cut and pasted from the documentation:
from graphviz import Digraph, Graph
dot = Digraph(comment='The Round Table')
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/aoc.gv.pdf')
The file will output to the correct folder and the file is there and it has 170 bytes but it will not open. I have tried other extensions such as just 'gv' and they do not work either. I'm using the latest version of Graphviz which is 0.10.1 and I have tried opening this file on a PC and it does not work on PC either (I have a Mac). This problem is similar to
Graphviz's executables are not found (Python 3.4)
and
Why is pydot unable to find GraphViz's executables in Windows 8?
However, there are major stumbling blocks to my understanding these posts. Number one, I have very little understanding of how Python is executed on a computer, so I really don't even know what an environment variable is. Second, when they refer to computer's PATH I can only assume that they're talking about the directory of the file which is executing the Graphviz module, but I'm not sure about that. So I've added this line of code:
import sys
str1 = "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/graphviz/"
sys.path.append(str1)
But that is not working. Third, if I were to implement this step:
Add this string to the end of your Variable value list (including semicolon): ;C:\Program Files (x86)\Graphviz2.34\bin
Then I would have to translate that into its Mac counterpart and I'm not able to. Any help would be appreciated.
The diagnostic is saying that dot is not in your $PATH, it does not appear in any of the directories mentioned by that env var. You want to get to a point where trying the following command reports some version number:
$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)
$
$ which dot
/usr/local/bin/dot
$
$ echo $PATH | tr : ' ' | fmt -w1 | grep local
/usr/local/bin
If you are not yet using Brew, you should. It's the easiest way to get this and many other programs onto your Mac. Visit https://brew.sh/ and follow the instructions. Then type:
$ brew install graphviz
...
$ /usr/local/bin/dot -V
That should work just fine. If dot -V says "not found" then simply append the proper directory to your PATH:
$ export PATH="${PATH}:/usr/local/bin"
If your bash shell can run it, then your python program should be able to, as well.
I tried these commands to help me locate the DOT file path on my mac. It was not: "/usr/local/bin/dot" on my system.
dot -V
dot - graphviz version 2.49.2
which dot
/opt/homebrew/bin/dot
I had installed Graphviz, but I was still running into trouble finding the right path. I am using Protege, and I had to modify the path for OwlViz since it was displaying the entire hierarchy at (0,0). I copied the path that I got by running the which dot command to the OWLViz tab on the preference dialog, and restarted protege and it worked perfectly! Good luck!
Problem solved. It took me a while to figure out that I had to download some non-pythonic software before I could get the pythonic software to work.
brew install graphviz
Was step 1 and I had done that before but I was getting an error message. It told me to change ownership of some files so I did that. Then tried
brew install graphviz
again and that did the trick.

Pycharm and Python Paths on Windows with Conda

I am working with multiple versions of Python, so I don't want to put any one of them in my windows path. I discovered that I can create a virtualenv (under Settings -> Project: X -> Project Interpreter and that will allow me to specify which python exe to use, but also where to get other useful programs, like pip. The end result is that using Virtualenv I can type "pip" or "python" in the terminal in Pycharm and use it as a regular terminal.
But now I'm working with Anaconda so I don't want to use virtualenv and I want to use conda instead. This works fine, but it doesn't seem to put anything into the path. (This is particularly important because where I intend to keep my project is not near my path to the python environment conda created.)
So if I type "pip" or "python" in the pycharm terminal, it doesn't recognize them. I have to specify a huge path to get it to work right.
I've been googling around and trying to find a solution to this problem. I've found a number of supposed solutions, but so far none have worked.
So, for example, I've already tried Add Content Root under project structure. This does nothing. I've tried add local, which seems to just screw everything up. (Presumably this is a way to create a local environment that I shouldn't be touching in conda.) I've tried adding a PathConfig.pth file. So far nothing works.
Remember, I don't want to add anything into the windows path (which obviously would solve my problem) because then it won't know which specific environment I want at the moment.

SublimeCodeIntel isn't looking in python 3 paths

I installed SublimeCodeIntel package in sublime text, and I use it to code in python 3. However, the problem is that it uses python2 paths to do the import, so if a library is installed in python2 and not in python3, i won't find it when i use import or from X import y.
I did confirm that when I used the command SublimeCodeIntel: Dump Import Directories , so I saw both the files python and python3 in the directory ./codeintel/import_dir_stats and here is there content :
python
dedeeb56f744e507026fef17243da41f /home/bilal/.local/lib/python2.7/site-packages
6a1d0cac3d9e6148e2208b63a33a1e6f /home/bilal/.local/lib/python2.7/site-packages/impacket
16a4fccbb3beadfdfd72691ef8f7298c /home/bilal/.local/lib/python2.7/site-packages/mechanize
211d2b55059f6b634799fdae534decd9 /usr/lib/python2.7/dist-packages
be5448890caffe81686310f127d6efae /usr/lib/python2.7/dist-packages/_markerlib
cec69a0830a725e10ac4e364d44add8f /usr/lib/python2.7/dist-packages/appindicator
python3
dedeeb56f744e507026fef17243da41f /home/bilal/.local/lib/python2.7/site-packages
6a1d0cac3d9e6148e2208b63a33a1e6f /home/bilal/.local/lib/python2.7/site-packages/impacket
16a4fccbb3beadfdfd72691ef8f7298c /home/bilal/.local/lib/python2.7/site-packages/mechanize
211d2b55059f6b634799fdae534decd9 /usr/lib/python2.7/dist-packages
be5448890caffe81686310f127d6efae /usr/lib/python2.7/dist-packages/_markerlib
cec69a0830a725e10ac4e364d44add8f /usr/lib/python2.7/dist-packages/appindicator
I didn't put all the lines (because there is a lot), but the content of the two files is identical.
I don't understand from where is coming this problem, why SublimeCodeIntel is looking in python2 directories for the import ??!!
PS : I am using Ubuntu 15.10 (with Linux version > 4), and sublime text 3 build 3103.
Please help, I really consumed a lot of time and energy looking for this.
I would strongly recommend using the Anaconda plugin (no relation whatsoever to the Anaconda Python distribution) instead of SublimeCodeIntel. I struggled with SCI for a while on various machines, and could never get very good code completion out of it until I ran across Anaconda one day. The next day I removed SCI and have been completely satisfied ever since. It's super-easy to configure (just give it the path to your python executable and it reads sys.path and all the rest), and pretty much just works. It has linting with several different linters built-in (you can disable them if you want), has popups available for function signatures and other hints, works with virtualenvs right out of the box, and more.
(I didn't write it and I have no connection to the author(s) - it's just a great plugin!)

Resources