Tree graph with python AnyTree package - python-3.x

I need to generate a tree from a dictionary with python AnyTree package.so I have a dictionary like below structure.
data = {'name': 'xyz',
'children': [{'name': 'node1',
'children': [{'name': 'node2'}]}]}
This dictionary can grow as the program executes.issue that I'm facing right now is when i try to export the tree as a png with DotExporter(root).to_picture("data.png") it throws a file not found error like below
Traceback (most recent call last):File "C:/Users/.../data_modeling.py", line 88, in<module>creating_tree(main)
File "C:/Users/.../data_modeling.py", line 66, in creating_tree
DotExporter(root).to_picture("data.png")
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\anytree\exporter\dotexporter.py", line 229, in to_picture
check_call(cmd)
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 323, in check_call
retcode = call(*popenargs, **kwargs)
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 304, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I have graphviz package installed and i am on python 3.7 with windows.
however using DotExporter(root).to_dotfile('root.dot') I can export the tree as a dot file and using an online converter I can convert dot file to an image.
but I need to export this as a png from my program.
I have already googled for similar issues and did all the suggestions and solutions there.any help or suggestion would be great,any other tree graphing tool also would be okay.

found a solution..
problem is with the graphviz python package.when you install graphviz with pip,graphviz python wrapper doesn't contain graphviz binary files.
so to solve this you need to manually download graphviz from their website and set it to path or install graphviz using conda.
alternate to this you can use pydot as a png exporter.and you can use dot file to generate a png with pydot.also pydot can be installed with pip.

Related

when running virtualenv command on terminal

Thank you for your time.
I installed virtualenv on my mac using pip, but when I ran virtualenv env, it showed an error:
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 6, in
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 3241, in
#_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 583, in _build_master
ws.require(requires)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'importlib-resources>=1.0' distribution was not found and is required by virtualenv
Please help. I installed the latest packaghes of importlib but it still doesn't work.
Your stack shows 2.7 python.
your tag question as python-3.x
You indicated that you already have importlib.
But error is about importlib-resources.
Try to import importlib_resources:
importlib_resources is a backport of Python 3.9’s standard library importlib.resources module for Python 2.7, and 3.5 through 3.8. Users of Python 3.9 and beyond are encouraged to use the standard library module. Developers looking for detailed API descriptions should refer to the Python 3.9 standard library documentation.

Q: How to fix the missing dependancies in pyzbar

I am currently using spyder via anaconda with python 3.8.5 on windows 10 and I am trying to use the pyzbar package to make a barcode reader. When I try to run the script I get this error message when trying to run from pyzbar.pyzbar import decode and from pyzbar import pyzbar:
Traceback (most recent call last):
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 58, in load
dependencies, libzbar = load_objects(Path(''))
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 50, in load_objects
deps = [
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp>
cdll.LoadLibrary(str(directory.joinpath(dep)))
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<ipython-input-1-95ae0761f4b5>", line 1, in <module>
from pyzbar.pyzbar import decode
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\pyzbar.py", line 7, in <module>
from .wrapper import (
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 139, in <module>
zbar_version = zbar_function(
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 136, in zbar_function
return prototype((fname, load_libzbar()))
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 115, in load_libzbar
libzbar, dependencies = zbar_library.load()
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 60, in load
dependencies, libzbar = load_objects(Path(__file__).parent)
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 50, in load_objects
deps = [
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp>
cdll.LoadLibrary(str(directory.joinpath(dep)))
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.
When trying to run just import pyzbar it will compile, but it will not be able to access any of the function. When I try I get this message:
Traceback (most recent call last):
File "<ipython-input-3-26272af93b8a>", line 1, in <module>
pyzbar.pyzbar.decode()
AttributeError: module 'pyzbar' has no attribute 'pyzbar'
I have looked up the documentation for pyzbar on github which states "The zbar DLLs are included with the Windows Python wheels", but have not found this anywhere. The closest to "Windows Python wheels" I have found is the wheel package which does not contain any information about pyzbar.
Any advice on how to fix this?
Visit https://pypi.org/project/pyzbar/#files to download pyzbar-0.1.8-py2.py3-none-win_amd64.whl.
You can find all the DLL files inside the wheel package.
I have just encountered this problem.
If your OS & python are x64 version, it's just because of lack of vc 2013 x64 runtime.
You can find Visual C++ Redistributable Packages for Visual Studio 2013 here
download & install.
I was facing similar issue just installed Visual
C++ 64 bit version on my computer and restarted. Choose between vcredist_x86.exe or vcredist_x64.exe based on your machine.
https://www.microsoft.com/en-us/download/confirmation.aspx?id=40784. Hope this solves your issue as well.

Bundle Ghostscript using Pyinstaller to python tool?

I am using Windows-10, Python 3.7, Pillow version 6.0.0, tkinter.
I developed a GUI tool which saves tkinter canvas as a PostScript using tkitner library, then converts it to PNG file using PIL (Pillow) library. On my Computer, I already have Ghostscript installed and my tool works just fine.
After distributing my tool with my collages, they can save the canvas as PostScript fine, but the tool then can't convert to PNG file and a anError arise regarding Ghostscript.
OSError: Unable to locate Ghostscript on paths
I would like to enable my Colleges of running the tool without the need of downloading Ghostscript on there machines.
I though then of including (bundling) the Ghostscript when creating py_app.exe using Pyinstaller.
Does anyone know how to do this, or have any other suggestions.
Below is the error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1705, in __call__
File "user_input.py", line 49, in save_as
File "drawing_func.py", line 1232, in save_as_png
File "site-packages\PIL\Image.py", line 1973, in save
File "site-packages\PIL\Image.py", line 628, in _ensure_mutable
File "site-packages\PIL\Image.py", line 621, in _copy
File "site-packages\PIL\EpsImagePlugin.py", line 333, in load
File "site-packages\PIL\EpsImagePlugin.py", line 139, in Ghostscript
OSError: Unable to locate Ghostscript on paths

Convert IPython notebook to PDF

I have written a very long IPython notebook and need to convert it to PDF for distribution. I've read this thread but the solution didn't work for me.
I've tried the following:
If I use the Print button in my browser, I have all the IPython menu
etc. showing, which I can't accept.
If I use Print Preview from the IPython menu, none of the LaTeX equations render. They are all still just LaTeX code.
If I use ipython nbconvert --to latex --post pdf myfile.ipynb I get a FileNotFoundError. Traceback follows:
[NbConvertApp] Using existing profile dir: 'C:\\Users\\blokeley\\.ipython\\profile_default'
[NbConvertApp] Converting notebook myfile.ipynb to latex
[NbConvertApp] Support files will be in myfile_files\
[NbConvertApp] Loaded template article.tplx
[NbConvertApp] Writing 72246 bytes to myfile.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running pdflatex 3 times: ['pdflatex', 'myfile.tex']
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\ipython-script.py", line 5, in <module>
sys.exit(start_ipython())
File "C:\Anaconda3\lib\site-packages\IPython\__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "C:\Anaconda3\lib\site-packages\IPython\config\application.py", line 564,
launch_instance
app.start()
File "C:\Anaconda3\lib\site-packages\IPython\terminal\ipapp.py", line 367, in start
return self.subapp.start()
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\nbconvertapp.py",
line 268, in start
self.convert_notebooks()
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\nbconvertapp.py",
line 311, in convert_notebooks
self.postprocessor(write_resultes)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\base.py",
line 28, in __call__
self.postprocess(input)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 140, in postprocess
cont = self.run_latex(filename)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 104, in run_latex
self.latex_count, log_error)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 84, in run_command
p = subprocess.Popen(command, stdout=stdout, stdin=null)
File "C:\Anaconda3\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Anaconda3\lib\subprocess.py", line 1111, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
I'm using the latest updates from Anaconda in Python 3.4 64-bit on Windows 7 Professional.
Your issue is that you do not have LaTeX installed on your computer. When subprocess tries to call pdflatex myfile.tex it therefore fails as it cannot find pdflatex.
Whilst it's true that you can create .tex files from IPython notebooks without needing LaTeX, these are just files that contain the LaTeX code. To compile them to create PDFs you need a version of LaTeX.
Installing LaTeX on Windows is not difficult, MiKTeX is one possible installation.

install scikit-learn for python 3.3 on windows 7

I am really new to the use of Python and the associated packages that can be installed.
As a biologist I am looking for a lot of new packages that would help me model species systems, ecological change etc.. and after a lot of "Google-ing" I came across scikit-learn.
However, I am having trouble installing it. And I will take this moment now to apologise for the length of this post.
I am using 64bit Python 3.3 and have the associated NumPy (MKL 1.7.0) and SciPy. I installed distribute which worked fine and allows me to use easy_install.
So to install scikit-learn, I tried using the cmd prompt (Windows) run in administrator mode, and then also through Python command line.
I placed the downloaded and extracted tar.gz file in the Lib\site-packages folder.
When I run the command
easy_install scikit-learn
in cmd prompt.
Then this is the following output:
C:\Python33\Lib\site-packages>easy_install -U scikit-learn
Searching for scikit-learn
Reading http://pypi.python.org/simple/scikit-learn/
Reading http://scikit-learn.org
Reading http://sourceforge.net/projects/scikit-learn/files/
Reading http://scikit-learn.sourceforge.net
Best match: scikit-learn 0.12.1
Downloading http://pypi.python.org/packages/source/s/scikit-learn/scikit-learn-0
.12.1.tar.gz#md5=7e8b3434f9e8198b82dc3774f8bc9394
Processing scikit-learn-0.12.1.tar.gz
Writing c:\users\nuvraj~1\appdata\local\temp\easy_install-kvr2q0\scikit-learn-0.
12.1\setup.cfg
Running scikit-learn-0.12.1\setup.py -q bdist_egg --dist-dir c:\users\nuvraj~1\a
ppdata\local\temp\easy_install-kvr2q0\scikit-learn-0.12.1\egg-dist-tmp-l618ie
Traceback (most recent call last):
File "C:\Python33\Scripts\easy_install-script.py", line 9, in <module>
load_entry_point('distribute==0.6.33', 'console_scripts', 'easy_install')()
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1937, in main
with_ei_usage(lambda:
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1918, in with_ei_usage
return f()
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1941, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "C:\Python33\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python33\lib\distutils\dist.py", line 917, in run_commands
self.run_command(cmd)
File "C:\Python33\lib\distutils\dist.py", line 936, in run_command
cmd_obj.run()
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
358, in run
self.easy_install(spec, not self.no_deps)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
598, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
628, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
823, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1103, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1089, in run_setup
run_setup(setup_script, args)
File "C:\Python33\lib\site-packages\setuptools\sandbox.py", line 34, in run_se
tup
lambda: exec(compile(open(
File "C:\Python33\lib\site-packages\setuptools\sandbox.py", line 82, in run
return func()
File "C:\Python33\lib\site-packages\setuptools\sandbox.py", line 37, in <lambd
a>
{'__file__':setup_script, '__name__':'__main__'})
File "setup.py", line 33, in <module>
File "c:\users\nuvraj~1\appdata\local\temp\easy_install-kvr2q0\scikit-learn-0.
12.1\sklearn\__init__.py", line 86
print "I: Seeding RNGs with %r" % _random_seed
^
SyntaxError: invalid syntax
C:\Python33\Lib\site-packages>
So the little ^ seems to be pointing at the " after RNGS with %r. Which from what I can tell is in the 'init' file from the sklearn folder found in the .tar.gz file.
I also get the same result when running it in the Python GUI and command line.
How can I install scikit-learn with Python 3.3? Is there some way of building it or editing the file to get past this invalid syntax error?
Any help would be greatly appreciated. And I am very sorry for it being such a long post. I was just trying to get all the details in there.
Thanks
Simon
scikit-learn does not support Python 3 yet. For now you need Python 2.7.
Proper support for Python 3 is expected for the 0.14 release scheduled for Q2-2013.
I am no expert, but in my understanding the print statement in Python 3.* is now a function, called like: print(). So, a quick solution in this case is to change
print "I: Seeding RNGs with %r" % _random_seed
to
print("I: Seeding RNGs with %r" % _random_seed)

Resources