Pydot error: file format "png" not recognized - python

I need to build a pythonic graph solution through pydot and when tried to run a simple code like:
import pydot
graph = pydot.Dot(graph_type='graph')
i=1
edge = pydot.Edge("A", "B%d" % i)
graph.add_edge(edge)
graph.write_png('graph.png')
Which is designed to build a simple graph (A-B1) on the png file.
After fixing a lot of misconfigurations, now I got:
Traceback (most recent call last):
File "/Users/zallaricardo/Documents/Python/test_png.py", line 7, in <module>
graph.write_png('graph.png')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1809, in <lambda>
lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1911, in write
dot_fd.write(self.create(prog, format))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 2023, in create
status, stderr_output) )
pydot.InvocationException: Program terminated with status: 1. stderr follows: Format: "png" not recognized. Use one of:
logout
And till now could not find a straight solution to my particular environment.
Any hint about how can I fix it?
Need to work for python 2.7 and mac os x 10.9.
My current installed packages:
cycler==0.9.0
decorator==4.0.4
graphviz==0.4.7
matplotlib==1.5.0
networkx==1.10
numpy==1.10.1
pydot2==1.0.33
pyparsing==1.5.7
PyPDF2==1.25.1
python-dateutil==2.4.2
pytz==2015.7
six==1.10.0
wheel==0.26.0
I just would like to reach the same result shown in https://pythonhaven.wordpress.com/2009/12/09/generating_graphs_with_pydot/

Could you try uninstalling pydot2 and install pydot?
$ pip uninstall pydot2
$ pip install pydot>=1.2.3
Without any change in the script, I got the following output

Related

pdfplumber to_image() OSError: exception: access violation writing 0x0000000000000008 in Windows 10

I was trying to use pdfplumber library in python (ver. 3.10.6) to convert some pdf pages to images but pdfplumber to_image() method throws the following error:
import pdfplumber
>>> myDOc = pdfplumber.open("CV.pdf")
>>> myImg = myDOc.pages[0].to_image(resolution=300)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jjjku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pdfplumber\page.py", line 381, in to_image
return PageImage(self, **kwargs)
File "C:\Users\jjjku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pdfplumber\display.py", line 93, in __init__
self.original = get_page_image(
File "C:\Users\jjjku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pdfplumber\display.py", line 54, in get_page_image
with WandImage(
File "C:\Users\jjjku\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\wand\image.py", line 9306, in __init__
wand = library.NewMagickWand()
OSError: exception: access violation writing 0x0000000000000008
Initially I tried to use this method from PyCharm but thiserror occurred, after that I assumed that maybe something is wrong with PyCharm configuration, so I tried the same from cmd and the result is above (the same error as in PyCharm). I suspect that there is something wrong with my Image Wand or Ghostscript configuration. I have Windows 10 on my computer. I tried some ideas from the net but without results.
Does anyone have any idea what can be the cause of this error and how to make it work?
So, following the advice, I reported it as a bug on pdfplumber project GitHub and I got a response that this is related to some problems with Wand library dependencies. The issue was resolved after I installed the following package:
pip install -U wand
In PyCharm I added Wand package to Python Interpreter Packages (make sure to have version 0.6.10, for 0.6.9 the error still occurred from what I observed)

Cannot produce an eps or pdf chart in Python's Plotyl in Ubuntu

I am using the python library called plotly on Ubuntu 18.04 and Python 3.6.
I need to export the graphs as .eps or .pdf files.
I use this sample code:
import plotly.graph_objects as go
import decimal
import plotly
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'
x = ['Product A', 'Product B', 'Product C']
y = [(20/80)*100, (14/80)*100, round(decimal.Decimal(2.256),2)]
# Use textposition='auto' for direct text
fig = go.Figure(data=[go.Bar(
x=x, y=y,
text=y,
textposition='auto',
)])
fig.show()
fig.write_image("fig1.eps")
But the figure is shown in a new tab in the browser. It is not written as eps. Also, in the command line where I run the python file, I see:
/usr/local/lib/python3.6/site-packages/pandas/compat/__init__.py:84: UserWarning:
Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
Traceback (most recent call last):
File "sample.py", line 15, in <module>
fig.write_image("fig1.eps")
File "/usr/local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 2688, in write_image
return pio.write_image(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1705, in write_image
fig, format=format, scale=scale, width=width, height=height, validate=validate
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1482, in to_image
ensure_server()
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1344, in ensure_server
validate_executable()
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1139, in validate_executable
raise ValueError(err_msg)
ValueError:
The orca executable is required in order to export figures as static images,
but the executable that was found at '/usr/bin/orca'
does not seem to be a valid plotly orca executable. Please refer to the end of
this message for details on what went wrong.
If you haven't installed orca yet, you can do so using conda as follows:
$ conda install -c plotly plotly-orca
Alternatively, see other installation methods in the orca project README at
https://github.com/plotly/orca.
After installation is complete, no further configuration should be needed.
If you have installed orca, then for some reason plotly.py was unable to
locate it. In this case, set the `plotly.io.orca.config.executable`
property to the full path of your orca executable. For example:
>>> plotly.io.orca.config.executable = '/path/to/orca'
After updating this executable property, try the export operation again.
If it is successful then you may want to save this configuration so that it
will be applied automatically in future sessions. You can do this as follows:
>>> plotly.io.orca.config.save()
If you're still having trouble, feel free to ask for help on the forums at
https://community.plot.ly/c/api/python
Here is the error that was returned by the command
$ /usr/bin/orca --help
[Return code: -11]
Note that I installed the orca using: pip3 install orca. I also added this line in the code:
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'
But this did not result in producing the eps file.
You do not have Orca properly installed. Unfortunately you cannot install Orca with pip. Instead follow Orca's installation method 4: standalone binaries:
Download the .AppImage with wget from Orca's release page. At the time of writing it was: wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage
Follow the Linux install instructions. Make sure you really follow the troubleshooting guides as well (both) - it wasn't easy.

Tokenizing mutliple language text in python

I am trying to tokenize text. For it to work, I was trying Polygot and installed the way, has been mentioned in the documentation. After installing it, I have been trying to make the simple script run:
import polyglot
from polyglot.text import Text, Word
text = Text("\"သမၼတဦးဝင္းျမင့္ရဲ႕ ျခင္းခတ္ကစားဟန္\"\n\nႏိုင္ငံေတာ္သမၼတ ဦးဝင္းျမင့္ ျမန္မာ့ရိုးရာဝိုင္းျခင္းခတ္ ေနတဲ့ပုံေတြ ဟာ ဒီကေန႕ ညေနပိုင္းမွာထြက္ရိွလာပါတယ္။\n\nဒီကေန႕ ညေနပိုင္းမွာ သမၼတအိမ္ေတာ္ဝင္းအတြင္းမွာ သမၼတဟာ သူရဲ႕မိတ္ေဆြေတြနဲ႕ ျခင္းခတ္ခဲ့တာလို႕ သိရပါတယ္။\n\nသမၼတနဲ႕ဝိုင္းျခင္းခတ္တဲ့သူေတြထဲမွာေတာ့ အမ်ိဳးသားလႊတ္ေတာ္ကိုယ္စားလွယ္ ဦးေက်ာ္သီဟ ၊ အစိုးရ ရဲ႕ၿငိမ္းခ်မး္ေရးေကာ္မရွင္အဖြဲ႕ဝင္ ဦးေအာင္စိုးတို႕ပါဝင္ၾကပါတယ္။\n\nသမၼတ ဦးဝင္းျမင့္ဟာ သမၼတတာဝန္မထမ္းေဆာင္မီ လႊတ္ေတာ္ကိုယ္စားလွယ္အျဖစ္ ေနျပည္ေတာ္က စည္ပင္ဧည္႕ရိပ္သာဝင္းအတြင္း ေနထိုင္စဥ္ကတည္းက အမ်ိဳးသားဒီမိုကေရစီအဖြဲ႕ခ်ဳပ္ ပါတီဝင္လႊတ္ေတာ္ကိုယ္စားလွယ္အခ်ိဳ႕နဲ႕ ညေနပိုင္းေတြမွာ ျခင္းခတ္ေလ့ရိွပါတယ္။\n\nကိုယ္လက္လႈပ္ရွားအားကစားအျဖစ္ ျခင္းခတ္ေလ့ရိွတဲ့သူေတြထဲမွာ ေတာ့ လက္ရိွ မႏၱေလးတိုင္းဝန္ႀကီးခ်ဳပ္ ေဒါက္တာေဇာ္ျမင့္ေမာင္ ၊ ဧရာဝတီတိုင္းဝန္ႀကီးခ်ဳပ္ေဟာင္း မန္းေဂ်ာ္နီတို႕လည္း ပါဝင္ေလ့ရိွပါတယ္။ ")
print(text.words)
but have been getting an error saying:
Traceback (most recent call last):
File "tkn.py", line 2, in <module>
from polyglot.text import Text, Word
File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/polyglot/text.py", line 9, in <module>
from polyglot.detect import Detector, Language
File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "/home/ubuntu/anaconda3/envs/python3/lib/python3.6/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
ModuleNotFoundError: No module named 'icu'
To resolve this, I tried multiple steps mentioned here and few answers as given here but it has not solved the problem. I am working with Ubuntu.
Also, if I try to install pip install pyicu as some of the posts suggest, I get an error while trying to install it saying Failed building wheel for pyicu and error: command 'gcc' failed with exit status 1.
I am not sure how to proceed from here. How could I resolve the related error and make the script work?
I also downloaded and installed icu (building it manually for Ubuntu)but no help.
curl -LO http://download.icu-project.org/files/icu4c/63.1/icu4c-63_1-src.tgz
tar xzvf icu4c-63_1-src.tgz
cd icu/source
chmod +x runConfigureICU configure install-sh
./runConfigureICU Linux
make
sudo make install
sudo cp -r common/unicode /usr/local/include/

Error Installing imgseek on Mac Os

I am trying to install imgseek- the server version (http://www.imgseek.net/) to do image analysis.I am able to install all the dependencies successfully using:
sudo port install swig
sudo port install swig-python
sudo easy_install twisted
sudo port install imagemagick
sudo easy_install epydoc
Then I download isk-daemon from the downloads(isk-daemon-0.9.3.tar.gz) and build and install it. Everything runs succesfully.
But when I run iskdaemon.py from the command prompt, i get the following error:
sk-daemon : WARNING | no config file (isk-daemon.conf) found. Looked at local dir, home user dir and /etc/iskdaemon. Using defaults for everything.
root : ERROR Unable to load the C++ extension "_imgdb.so(pyd)" module.
root : ERROR See http://www.imgseek.net/isk-daemon/documents-1/compiling
Traceback (most recent call last):
File "/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/imgSeekLib/ImageDB.py", line 35, in
import imgdb
File "/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/imgSeekLib/imgdb.py", line 28, in
_imgdb = swig_import_helper()
File "/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/imgSeekLib/imgdb.py", line 20, in swig_import_helper
import _imgdb
ImportError: dlopen(/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/_imgdb.so, 2): Symbol not found: __ZNSs4_Rep20_S_empty_rep_storageE
Referenced from: /Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/_imgdb.so
Expected in: dynamic lookup
Please help!
I had the same problem when I was trying to install iskdaemon on my Mac (osx yosemite).
The problem in my case was that when I was building it, the c++ compiler threw two errors on using min function in imgdb.cpp
The error was because the types of the variables in the min function were not the same. Consequently the build failed and the imgdb module wasn't produced.
I fixed it by adding a simple typecast to the variables passed to the min function:
I changed: min(sz, numres) to min(sz, (long int)numres) on line 1003,
and min((V.size()/2), numres) to min((int)(V.size()/2), numres) on line 1327
I built again and it is working now.
Check if you get any errors when you build, maybe you are facing the same issue.

pygraphviz error: program neato not found in path

I'm running Windows 7, and using python version 2.7.
I've been trying to use pygraphviz, but whenever I use G.layout() on a graph, I get the error message;
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
G.layout()
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1305, in layout
data=self._run_prog(prog,' '.join([args,"-T",fmt]))
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1251, in _run_prog
runprog=r'"%s"'%self._get_prog(prog)
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1239, in _get_prog
raise ValueError("Program %s not found in path."%prog)
ValueError: Program neato not found in path.
I know, however, that the Graphviz files are installed, and the directory is in my path (I've manually gone and added it).
I've tried the simlink solution given here but all I get when I enter that into the command line (administrator mode) is a message saying it is not recognized as an internal or external command, operable program, or batch file. I'm not experienced enough to know whether there's something I'm failing to do with that though.
Is there something I can do to make this work?
I had the same problem with conda. Apparently there is something wrong with the libraries. This comment in here worked for me:
https://github.com/conda/conda/issues/1851#issuecomment-314924385
In the Anaconda prompt do both:
conda install -c anaconda graphviz
and
conda install -c anaconda python-graphviz
Then import graphviz will work.

Categories

Resources