fschulze / sqlalchemy_schemadisplay

Other
140 stars 37 forks source link

Impossible to use the library #45

Closed Flaventino closed 1 week ago

Flaventino commented 1 month ago

Hi guys! Your work sounds amazing but unfortunately I never succeed to make it work... I tried to install pydot and graphviz but always got error messages when trying to generate the erd from my SQLAchemy model.

I do believe a more detailed installation process, including dependencies, would be necessary and appreciated at least.

RagingRoosevelt commented 1 month ago

Did you make sure the exes for graphviz and dot were on your system PATH? I ran into issues with that preventing this library from working.

Flaventino commented 4 weeks ago

I do believe yes but obviously not. Are we supposed to install graphviz as the python library (i.e. poetry add graphviz) or with the windows ".exe" setup file or eventually both methods ?

Then, when talking about "exes for graphviz and dot" which files am I supposed to look for exactly ? This way I can get the name and path of the directories I have to add to the system path ?

Zlopez commented 4 weeks ago

Could you post here the error messages?

I'm using sqlalchemy_schemadisplay only on Linux and it's enough to install graphviz and pydot in the system. I should probably look at the README and update it or improve poetry, so you just need to do poetry install and it will do the rest for you.

Flaventino commented 3 weeks ago

Yes for sure. It sounds that "graph = grapgh_create_schema" function produces no exceptions but "graph.write_png('dbschema.png')" does. My computer is running on windows 10, and below is the error message I get when trying to generate the erd.

Traceback (most recent call last): File "D:\DataScience\Projects\Scraping\Movies.venv\Lib\site-packages\pydot\core.py", line 1799, in create stdout_data, stderr_data, process = call_graphviz( ^^^^^^^^^^^^^^ File "D:\DataScience\Projects\Scraping\Movies.venv\Lib\site-packages\pydot\core.py", line 222, in call_graphviz process = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "C:\ProgramData\anaconda3\Lib\subprocess.py", line 1026, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\ProgramData\anaconda3\Lib\subprocess.py", line 1538, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\DataScience\Projects\Scraping\Movies\Databases\schema.py", line 268, in graph.write_png('dbschema.png') # write out the file ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\DataScience\Projects\Scraping\Movies.venv\Lib\site-packages\pydot\core.py", line 177, in __write_method self.write(path, format=f, prog=prog, encoding=encoding) File "D:\DataScience\Projects\Scraping\Movies.venv\Lib\site-packages\pydot\core.py", line 1708, in write s = self.create(prog, format, encoding=encoding) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\DataScience\Projects\Scraping\Movies.venv\Lib\site-packages\pydot\core.py", line 1808, in create raise OSError(*args) FileNotFoundError: [WinError 2] "dot" not found in path.

Zlopez commented 3 weeks ago

I'm not expert on Windows 10, but found this guide for getting dot.exe working on Windows 7. Could you try it and see if that helps?

Flaventino commented 3 weeks ago

Hi Zlopez and RagingRoosevelt, many many thanks to both of you for your help and time spent trying to solve the issue I was facing. I finally found the solution and I will share it here right below.

The fundamental problem is incredibly stupid. I do believe that after typing that post I will hide myself whithin a deep cave in a deep forest, somewhere very lost on earth...

FIRST OF ALL : Well it is not needed to install python libraries for "dot" or "graphviz" (i.e "pip install pydot graphviz" worths nothing) The only thing you need is just installing your OS dedicated package for "graphviz". For me, working on windows 10, I just had to execute "windows_10_cmake_Release_graphviz-install-12.1.0-win64.exe" which I downloaded from "graphviz" website (https://graphviz.org/download)

BUT PLEASE PAY ATTENTION TO WHAT FOLLOWS : During "graphviz" installation process, you are asked to choose whether graphviz is to be added to the system path or not. I selected yes (for current user only). That's why I was pretty sure that this specific issue regarding environment variables and system paths was solved and not relevant anymore. But I was wrong...

THE FINAL "silly" SOLUTION : Whithin my python script I just added the two following lines :

import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files/Graphviz/bin'

Now, the png file of my my database ERD is properly created whithout any error.

fschulze commented 3 weeks ago

@Flaventino glad you were able to solve the issue. There is nothing "silly" about this. From what you describe you did the right thing, but the graphviz installer didn't seem actually to update the PATH, or you have to restart the Terminal or even Windows before it works. The installer might have told you about that, but even if it did, it is something easy to miss. These are problems even professionals sometimes stumble over or forget to check.

Zlopez commented 1 week ago

@Flaventino It seems that the installer missed to update PATH for python and you couldn't see that. I'm glad the issue is solved for you. I will close it as solved now :-)