Problem with graphviz, ExecutableNotFound error - python

I have a problem with installing graphviz in PyCharm. Im using windows. I already installed graphviz library onto my PyCharm project, however error occurs when executing dot.render:
graphviz.backend.execute.ExecutableNotFound: failed to execute WindowsPath('dot')
I tried adding
import os
os.environ["PATH"] += os.pathsep + 'D:/Program Files (x86)/Graphviz2.38/bin/'
as said here: "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38
but it still doesent work?
any ideas?
Im new to pycharm and advanced coding in general, go easy please...

This is a very common problem. While it may have several causes (see suggestions above), the solution you found is out-of-date.
Unfortunately, there are two software systems named Graphviz. You need both.
Go here https://graphviz.gitlab.io/download/ and download the appropriate version.
To check that you have installed the "real" Graphviz package, bring up a cmd window & type dot -V

Related

Can't solve "No module named 'numpy'" after hours of digging

I know this is a problem that's been asked here before, but I have tried all the solutions I found and not solved it. It's possible I'm not understanding the solutions, but I have tried my best.
I am teaching myself Python and it is slow going, so I don't understand a lot yet. I'm using VSCode as an IDE, Python version 3.10, and Windows 10. I only have the Python extension installed for VSCode. My project files are on a flash drive, D. I replaced a couple folder names with [Default Names] in the text below.
I keep trying to debug/run some code in VSCode and the very first line
import numpy as np
gives me the error
Exception has occurred: ModuleNotFoundError - No module named 'numpy'.
But I know that's not true:
`PS D:\0-Career\Programming\PythonCoding\[ProjectFolder]> py -m pip install numpy
Requirement already satisfied: numpy in c:\users\[UserID]\appdata\local\programs\python\python310\lib\site-packages (1.23.1)`
I tried the solution of going to
environment variables > system variables > "Path" > edit > new >
c:\users\[UserID]\appdata\local\programs\python\python310\
as well as
C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Lib\site-packages\
and
C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Scripts\
and I also tried adding a user variable called Python. Nothing appears to have changed as a result of these additions.
Some history if it's helpful:
I first started by installing Python using the Microsoft Store. I used IDLE for a bit, and I used my command line to install pip and numpy. They worked for a little while. I later installed Visual Studio Code IDE. I ultimately have uninstalled the Microsoft Store version and installed the application from the Python site for Windows instead. I have also uninstalled and reinstalled it several times trying to fix my issues, and same for numpy. I also searched my C drive for "python" and burned everything from the past couple days and reinstalled and repaired it out of desperation. No luck.
I have tried to the best of my ability to uninstall everything and reinstall everything to start fresh, because numpy worked ever so briefly early on in IDLE, I think until I had installed the web download version of Python. I don't really understand environment variables, so I'm not sure what I'm doing or if I'm doing that wrong, or what needs to be restarted when I try something new, so it's possible I missed something.
Answers a 10 year old could understand would be appreciated! Or terminology I can easily research for an explanation of how to do it.
Ctrl+Shift+P open Command Palette
choose Python:Select Interpreter
Choose the right interpreter
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Also Check 64 bit or 32 bit
Download the latest version
and open the location where you downloaded the NumPy module now press the 'SHIFT' key and press right-click on the mouse then a menu will open where you find open PowerShell. open it now PowerShell window opens in the folder now type pip install and the file name and press the TAB button and click enter. then the NumPy module will be installed.
Have Fun
Try adding the variable PYTHONPATH to your system variables and add the following paths to this variable.
C:\PATH_TO_YOUR_PYTHON_INSTALL
C:\PATH_TO_YOUR_PYTHON_INSTALL\DLLs
C:\PATH_TO_YOUR_PYTHON_INSTALL\Lib
C:\PATH_TO_YOUR_PYTHON_INSTALL\Scripts
It should look something like this.
Screenshot of Environment Variables
After you added the variable restart your VS Code and it should work.
I hope this helps.

Installed module is not working (windows)

So long story short. I want to use requests and bs4 modules in my code. I installed them using pip install requests, pip install bs4. I double checked everything, even found installation folder and saw that the files is here, but my vs code is not detecting it and giving a error. I'm a quite new to this programming language so possibly it's a common issue. But i searched and mostly found posts about this problems on diffrent versions of linux, not windows.
Error i'm getting in vscode btw
Import "requests" could not be resolved from source
And when i'm launching the program through cmd the error is
ModuleNotFoundError: No module named 'requests'
First, you should add more information for us to know how your computer and IDE are configured. The first thing you should do is to check that VS Code is using the Python version where you have pip installed the modules. That is, clicking at the bottom-left space as in the picture below. Then checking that the modules are within that path.
Otherwise, check out virtualenv. With this tool you can create virtual environments within your project's folder and makes it easier to manage packages.

Python, not able to graph trees using graphviz with the anytree package

So I have installed the anytree package (after great effort; I had to add some environment variables on my system). Having done this I can use almost all functionalities of the anytree package - just not the one I want. I wish to use graphviz in conjunction with the anytree package in order to graph trees using the 'DotExporter' command.
I have installed graphviz; its path is C:\Users\joel\Anaconda3_2\Lib\site-packages\graphviz, and I have also added the line of code 'from anytree.exporter import DotExporter' to my Python document (in addition to the other anytree imports needed to make trees).
Therefore, having defined the root node 'root' of my tree, I should now be able to produce pngs and dot files of the tree using either of the commands 'DotExporter(root).to_picture('root.png')', however I get the following error message:
'FileNotFoundError: [WinError 2] The system cannot find the file specified'.
Does anybody know what is going on? I am using Python 3.6.2 with the engine Spyder as a part of the Anaconda distribution (I have Anaconda 3.2). I am 99% certain I have the most recent versions of anytree and graphviz.
UPDATE: So I learned that there has been a big compatibility issue between Anaconda and graphviz for about a year now and assumed that this was the problem. After trying all the solutions people suggested I still wasn't able to get my program to work so I ended up uninstalling Anaconda and instead started using PyCharm together with the standard Python interpreter. However the program still wouldn't work, so even though there are compatibility issues between Anaconda and graphviz, it turns out that wasn't the problem. I tried the program on my housemate's machine which also uses Anaconda and got the same error I had been getting.
In the end I found the following workaround: I couldn't get the 'DotExporter(root).to_picture('root.png')' command to work, but the 'DotExporter(root).to_dotfile('root.dot')' command was working. '.dot' files contain code and can be opened in Notepad (other word processing softwares will work too). Therefore I just had to find a way to graph the tree using the dot file instead of using the 'DotExporter(root).to_picture('root.png')' command. The easiest way to do this is via either of the online tools http://www.webgraphviz.com/ and http://sandbox.kidstrythisathome.com/erdos/. Just open your dot file in Notepad, copy its contents and paste it into the websites and hit generate.
Here is my workaround. I was working the examples of "getting started" with the following initial steps:
Create a tree object as udo and then trying DotExporter(udo).to_picture("udo.png"). This was where I got the same error as OP.
Assuming you have already installed graphviz and python-graphviz (e.g conda install -c anaconda graphviz python-graphviz) you can output the graph (first saving a dotfile) with this:
DotExporter(udo).to_dotfile('udo.dot')
from graphviz import Source
Source.from_file('udo.dot')
Then save image file with this:
from graphviz import render
render('dot', 'png', 'udo.dot')

Error while trying to install sklearn from Pycharm | arrayobject.h cannot be absolute

Complete error statement:
ValueError: path '/home/andy/anaconda3/lib/python3.5/sitepackages/numpy/core/include/numpy/arrayobject.h' cannot be absolute
I have installed Scipy and numpy (mkl) version by downloading the compiled wheel files from this link and then installing it from the cmd using pip.
I'm more of a python noob, my focus is primarily machine learning. Kindly help me out.
I encountered today a similar problem.
Do you use Python 3.6 (Latest version)?
If you do, you might consider downgrading (reinstalling actually) to Python 3.5.. apparently, sklearn has few problems supporting Python 3.6 at the moment.
I also installed NumPy and SciPy from link and got the same error when trying to install scikit-learn from PyPI. Installation scikit-learn from the same link solved the problem.
This is an error due to absolute paths to include files being found in the source, which cannot be automatically converted by distutils to the correct system path when compiling on windows.
The easiest way to fix this particular issue is to add a few lines of code to "util.py" in PYTHONPATH\lib\distutils\util.py. Add to the beginning of the function "convert_path"..
if pathname.startswith('/usr/local/lib/python3.5/dist-packages/numpy/core/include/numpy/'):
paths = pathname.split('/')
return 'C:\\Python36\\Lib\\site-packages\\numpy\\core\include\\numpy\\'+paths[-1]
hmm..maybe it wants a relative path i.e. ../include/numpy/ and not the absolute path which contains ../arrayobject.h

The PIL library import fails

Being a complete begginer in python, I decided to install the python interpreter 3.4.4, and also PyDev plugin for eclipse IDE. I am also using windows 10.
I have encountered a problem regarding certain imports, namely : from PIL import Image, ImageTk, which is apparently an unresolved import.
I have looked at certain questions which were similar to my situation, but most of them gave a solution like installing packaged from the linux apt-get. Here are some topics I visited :
Uninstalling and reinstalling Pillow and pip,
Installing pillow-imaging-tk on Ubuntu,
This topic which left me very confused,
This one seemed helpful, but is on Unix OS again
So please, could someone explain to me why I am seeing this error, and how could I correct it if I absolutely want to use Eclipse, Pydev, windows 10 and Python 3.
Found the solution, here's what I did:
Set the PYTHONPATH like it is shown in this article, make sure python.exe is accessible via cmd,
Via cmd, type pip install pillow. Alternatively, you can enter the same command from Windows+R,
(Not sure if relevant step) Via eclipse, Windows->Preferences->PyDev->PythonInterpreterremove your interpreter to re-add it,
Restart eclipse.
For Python import problems in PyDev, the project web site has a page on interpreter configuration that is a good place to start. I recently had a similar problem that I solved by adding a module to the forced builtins tab.

Categories

Resources