can Agraph.write() be aimed at a particular version of graphviz - graphviz

Some folks at my web host went to the trouble of compiling graphviz 4.0.0 for me, but its twopi output was nevertheless defective. In trying to understand the problem, I wound up with multiple versions of the graphviz executables on my MacBook (MacOS 11.6). I failed to compile the latest version from source, but then got the package from conda-forge to work. So now I've got:
## Anaconda versions:
my#mac ~ % ~/opt/anaconda3/bin/twopi -V
twopi - graphviz version 2.40.1 (20161225.0304)
my#mac ~ % ~/Projects/graphing_env/bin/twopi -V
twopi - graphviz version 2.49.3 (0)
## and now:
my#mac ~ % ~/opt/anaconda3/envs/graphviz_testing/bin/twopi -V
twopi - graphviz version 4.0.0 (0)
## Local default:
my#mac ~ % /opt/local/bin/twopi -V
twopi - graphviz version 2.50.0 (20211204.2007)
## Homebrew:
my#mac ~ % /opt/homebrew/bin/twopi -V
twopi - graphviz version 3.0.0 (20220226.1711)
Using pygraphviz to create an AGraph instance and render it using twopi, There seems to be no way to point AGraph.write() at a particular twopi executable. pygraphviz, internally (in agraph.py), uses subprocess.Popen to execute a graphviz binary so I did this instead:
svg = subprocess.check_output(
['/Users/me/opt/anaconda3/envs/graphviz_testing/bin/twopi',
'-Tsvg',
'-Gbgcolor=aliceblue'],
input=Agraph_instance.to_string(),
text=True
)
This worked, but is there any way to explicitly configure pygraphviz so that it will use a defined graphviz executable?

Related

"failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems" PATH on mac in sage math

I want to use graphviz for graph vizualisation. I would like to use source from graphviz:
def display(self, verbose=False):
'''
Prints the QMDD as a dot graph.
'''
filename = '.tmp.dot'
self.save_as_dot(filename, verbose)
s = Source.from_file(filename)
s.view()
os.remove(filename)
# Can't manage to properly remove file .tmp.dot.pdf
I always experience this error message :
""failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH.""
I'm using a mac and a sage math in a jupyter notebook.
I've already tried to do pip3 install graphviz and brew install graphviz. Furthermore I had the path : "/Library/SageMath/local/lib/python3.9/site-packages/graphviz" to the system path but each solutions didn't work.
Try this:
conda install python-graphviz
It worked for me!

Getting Specific PIP Package Version on Windows 11 | I have a method but is it the best? [duplicate]

Using pip, is it possible to figure out which version of a package is currently installed?
I know about pip install XYZ --upgrade but I am wondering if there is anything like pip info XYZ. If not what would be the best way to tell what version I am currently using.
As of pip 1.3, there is a pip show command.
$ pip show Jinja2
---
Name: Jinja2
Version: 2.7.3
Location: /path/to/virtualenv/lib/python2.7/site-packages
Requires: markupsafe
In older versions, pip freeze and grep should do the job nicely.
$ pip freeze | grep Jinja2
Jinja2==2.7.3
I just sent a pull request in pip with the enhancement Hugo Tavares said:
(specloud as example)
$ pip show specloud
Package: specloud
Version: 0.4.4
Requires:
nose
figleaf
pinocchio
Pip 1.3 now also has a list command:
$ pip list
argparse (1.2.1)
pip (1.5.1)
setuptools (2.1)
wsgiref (0.1.2)
and with --outdated as an extra argument, you will get the Current and Latest versions of the packages you are using :
$ pip list --outdated
distribute (Current: 0.6.34 Latest: 0.7.3)
django-bootstrap3 (Current: 1.1.0 Latest: 4.3.0)
Django (Current: 1.5.4 Latest: 1.6.4)
Jinja2 (Current: 2.6 Latest: 2.8)
So combining with AdamKG 's answer :
$ pip list --outdated | grep Jinja2
Jinja2 (Current: 2.6 Latest: 2.8)
Check pip-tools too : https://github.com/nvie/pip-tools
You can also install yolk and then run yolk -l which also gives some nice output. Here is what I get for my little virtualenv:
(venv)CWD> /space/vhosts/pyramid.xcode.com/venv/build/unittest
project#pyramid 43> yolk -l
Chameleon - 2.8.2 - active
Jinja2 - 2.6 - active
Mako - 0.7.0 - active
MarkupSafe - 0.15 - active
PasteDeploy - 1.5.0 - active
Pygments - 1.5 - active
Python - 2.7.3 - active development (/usr/lib/python2.7/lib-dynload)
SQLAlchemy - 0.7.6 - active
WebOb - 1.2b3 - active
account - 0.0 - active development (/space/vhosts/pyramid.xcode.com/project/account)
distribute - 0.6.19 - active
egenix-mx-base - 3.2.3 - active
ipython - 0.12 - active
logilab-astng - 0.23.1 - active
logilab-common - 0.57.1 - active
nose - 1.1.2 - active
pbkdf2 - 1.3 - active
pip - 1.0.2 - active
pyScss - 1.1.3 - active
pycrypto - 2.5 - active
pylint - 0.25.1 - active
pyramid-debugtoolbar - 1.0.1 - active
pyramid-tm - 0.4 - active
pyramid - 1.3 - active
repoze.lru - 0.5 - active
simplejson - 2.5.0 - active
transaction - 1.2.0 - active
translationstring - 1.1 - active
venusian - 1.0a3 - active
waitress - 0.8.1 - active
wsgiref - 0.1.2 - active development (/usr/lib/python2.7)
yolk - 0.4.3 - active
zope.deprecation - 3.5.1 - active
zope.interface - 3.8.0 - active
zope.sqlalchemy - 0.7 - active
The python function returning just the package version in a machine-readable format:
from importlib.metadata import version
version('numpy')
Prior to python 3.8:
pip install importlib-metadata
from importlib_metadata import version
version('numpy')
The bash equivalent (here also invoked from python) would be much more complex (but more robust - see caution below):
import subprocess
def get_installed_ver(pkg_name):
bash_str="pip freeze | grep -w %s= | awk -F '==' {'print $2'} | tr -d '\n'" %(pkg_name)
return(subprocess.check_output(bash_str, shell=True).decode())
Sample usage:
# pkg_name="xgboost"
# pkg_name="Flask"
# pkg_name="Flask-Caching"
pkg_name="scikit-learn"
print(get_installed_ver(pkg_name))
>>> 0.22
Note that in both cases pkg_name parameter should contain package name in the format as returned by pip freeze and not as used during import, e.g. scikit-learn not sklearn or Flask-Caching, not flask_caching.
Note that while invoking pip freeze in bash version may seem inefficient, only this method proves to be sufficiently robust to package naming peculiarities and inconsistencies (e.g. underscores vs dashes, small vs large caps, and abbreviations such as sklearn vs scikit-learn).
Caution: in complex environments both variants can return surprise version numbers, inconsistent with what you can actually get during import.
One such problem arises when there are other versions of the package hidden in a user site-packages subfolder. As an illustration of the perils of using version() here's a situation I encountered:
$ pip freeze | grep lightgbm
lightgbm==2.3.1
and
$ python -c "import lightgbm; print(lightgbm.__version__)"
2.3.1
vs.
$ python -c "from importlib_metadata import version; print(version(\"lightgbm\"))"
2.2.3
until you delete the subfolder with the old version (here 2.2.3) from the user folder (only one would normally be preserved by `pip` - the one installed as last with the `--user` switch):
$ ls /home/jovyan/.local/lib/python3.7/site-packages/lightgbm*
/home/jovyan/.local/lib/python3.7/site-packages/lightgbm-2.2.3.dist-info
/home/jovyan/.local/lib/python3.7/site-packages/lightgbm-2.3.1.dist-info
Another problem is having some conda-installed packages in the same environment. If they share dependencies with your pip-installed packages, and versions of these dependencies differ, you may get downgrades of your pip-installed dependencies.
To illustrate, the latest version of numpy available in PyPI on 04-01-2020 was 1.18.0, while at the same time Anaconda's conda-forge channel had only 1.17.3 version on numpy as their latest. So when you installed a basemap package with conda (as second), your previously pip-installed numpy would get downgraded by conda to 1.17.3, and version 1.18.0 would become unavailable to the import function. In this case version() would be right, and pip freeze/conda list wrong:
$ python -c "from importlib_metadata import version; print(version(\"numpy\"))"
1.17.3
$ python -c "import numpy; print(numpy.__version__)"
1.17.3
$ pip freeze | grep numpy
numpy==1.18.0
$ conda list | grep numpy
numpy 1.18.0 pypi_0 pypi
You can use the grep command to find out.
pip show <package_name>|grep Version
Example:
pip show urllib3|grep Version
will show only the versions.
Metadata-Version: 2.0
Version: 1.12
There's also a tool called pip-check which gives you a quick overview of all installed packages and their update status:
Haven't used it myself; just stumbled upon it and this SO question in quick succession, and since it wasn't mentioned...
pip show works in python 3.7:
pip show selenium
Name: selenium
Version: 4.0.0a3
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: c:\python3.7\lib\site-packages\selenium-4.0.0a3-py3.7.egg
Requires: urllib3
Required-by:
The easiest way is this:
import jinja2
print jinja2.__version__
pip list can also be told to format its output as json.
It could be a safer approach to parse the version.
pip list --no-index --format=json | \
jq -r '.[] | select(.name=="Jinja2").version'
# 2.10.1
On windows, you can issue command such as:
pip show setuptools | findstr "Version"
Output:
Version: 34.1.1
To do this using Python code:
Using importlib.metadata.version
Python ≥3.8
import importlib.metadata
importlib.metadata.version('beautifulsoup4')
'4.9.1'
Python ≤3.7
(using importlib_metadata.version)
!pip install importlib-metadata
import importlib_metadata
importlib_metadata.version('beautifulsoup4')
'4.9.1'
Using pkg_resources.Distribution
import pkg_resources
pkg_resources.get_distribution('beautifulsoup4').version
'4.9.1'
pkg_resources.get_distribution('beautifulsoup4').parsed_version
<Version('4.9.1')>
Credited to comments by sinoroc and mirekphd.
For Windows you can
open cmd and type python, press enter.
type the import and press enter.
type ._version__ and press enter.
As you can see in screen shot here I am using this method for checking the version of serial module.
In question, it is not mentioned which OS user is using (Windows/Linux/Mac)
As there are couple of answers which will work flawlessly on Mac and Linux.
Below command can be used in case the user is trying to find the version of a python package on windows.
In PowerShell use below command :
pip list | findstr <PackageName>
Example:- pip list | findstr requests
Output : requests 2.18.4
import pkg_resources
packages = [dist.project_name for dist in pkg_resources.working_set]
try:
for count, item in enumerate(packages):
print(item, pkg_resources.get_distribution(item).version)
except:
pass here
The indentations might not be perfect. The reason I am using a Try- Except block is that few library names will throw errors because of parsing the library names to process the versions. even though packages variable will contain all the libraries install in your environment.

pip install dgl failed even with pip search and whl

I tried to install dgl(https://github.com/dmlc/dgl)
There were several ways to install it.(https://docs.dgl.ai/install/index.html#install-from-source)
pip
conda
from git source
from whl
and I failed with error message when I tried pip
$ pip install dgl-cu101
ERROR: Could not find a version that satisfies the requirement dgl-cu101 (from versions: none)
ERROR: No matching distribution found for dgl-cu101
even pip search spot the package
$ pip search dgl
dgl (0.4.1) - Deep Graph Library
dgl-bots.py (1.1.0) - A python wrapper for https://bots.discord.gl
dgl-cu100 (0.4.1) - Deep Graph Library
dgl-cu92 (0.4.1) - Deep Graph Library
dgl-cu90 (0.4.1) - Deep Graph Library
dgl-cu101 (0.4.1) - Deep Graph Library
dgl-cu102 (0.5a200108) - Deep Graph Library
conda also does not work
$ conda install -c dglteam dgl-cuda10.1
Solving environment: failed
PackagesNotFoundError:
The following packages are not available from current channels:
- dgl-cuda10.1
Current channels:
- https://conda.anaconda.org/dglteam/linux-ppc64le
- https://conda.anaconda.org/dglteam/noarch
- https://repo.anaconda.com/pkgs/main/linux-ppc64le
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/free/linux-ppc64le
- https://repo.anaconda.com/pkgs/free/noarch
- https://repo.anaconda.com/pkgs/r/linux-ppc64le
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/pro/linux-ppc64le
- https://repo.anaconda.com/pkgs/pro/noarch
- https://conda.anaconda.org/conda-forge/linux-ppc64le
- https://conda.anaconda.org/conda-forge/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
install with source code is not available option because I am the remote client to the server and has no root access
install with whl seems nice but also occurred error.(https://pypi.org/project/dgl/#files)
$ pip install dgl_cu101-0.4.1-cp37-cp37m-manylinux1_x86_64.whl
ERROR: dgl_cu101-0.4.1-cp37-cp37m-manylinux1_x86_64.whl is not a supported wheel on this platform.
I read almost every articles and most of them said it would be the environment problem,
but as far as I know, they match!
My env server
CentOS 7
python 3.7
64 bit
minsky
4 GPUs
designed for ML
My env client
macos
iterm2
no root access
access from different city
How can I solve this problem?
Please help.
Your conda channel
https://conda.anaconda.org/dglteam/linux-ppc64le
gives the clue. Your system seems to be based on a ppc64le CPU, not the most frequently seen x86_64.
As you can see On the conda page, only linux-64 (i.e. x86_64) is available. Same goes for the pypi project.
So your setup does not match.
install with source code is not available option because I am the remote client to the server and has no root access
You should not need root access to compile the source code. The requirements listed in the guide are
gcc-c++ python3-devel make cmake
which, if not available yet could be installed using conda:
conda install -c conda-forge make cmake libgcc

Installation of modules Perl 6 failed - No compiler available for Perl v6.c

I installed Rakudo, the Perl 6 interpreter, by:
sudo apt-get install rakudo
I am following a tutorial about installation of Perl 6 modules:
http://perl6maven.com/how-to-install-perl6-modules
And in the last step I get this error:
perl6 bootstrap.pl===SORRY!=== Error while compiling /home/daniel/test/panda/bootstrap.pl
No compiler available for Perl v6.c
at /home/daniel/test/panda/bootstrap.pl:3
------> use v6.c⏏;
Information about versions:
Ubuntu 16.04.2 LTS
This is perl6 version 2015.11 built on MoarVM version 2015.11
How do I install the lacking compiler?
Warning: This solution can be used for development, but for production it is recommended to manually compile the interpreter until the Ubuntu repository will not be updated.
Panda described in the linked tutorial is depreciated. I should use zef to install Perl modules.
My build of Perl was too old. I realized this after reading issue 380 about not working version 6.c.
The correct tutorial about installation of the newest Perl, 6.c, on Ubuntu is here:
http://linuxtot.com/installing-perl-6-on-debian-or-ubuntu/
Now my rakudo -v prints:
This is Rakudo version 2017.07-132-gabf1cfe built on MoarVM version 2017.07-318-g604da4d
implementing Perl 6.c.
And everything works great.
The below commands are extracted from a tutorial linked below:
apt-get install build-essential git libssl-dev
git clone https://github.com/tadzik/rakudobrew ~/.rakudobrew
echo 'export PATH=~/.rakudobrew/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
rakudobrew build moar
rakudobrew build zef
Now to install the perl6 module:
zef install Module::Name
If you are comfortable installing your own software from source, then try the following (update the URL for the latest Rakudo Star from https://rakudo.perl6.org/downloads/star/):
wget -O rakudo-star-2017.07.tar.gz https://rakudo.perl6.org/downloads/star/rakudo-star-2017.07.tar.gz
tar -xvf rakudo-star-2017.07.tar.gz
cd rakudo-star-2017.07
perl Configure.pl --backend=moar --gen-moar
make
make rakudo-test
make install
Then add the following paths to your $PATH (replacing /path/to with the actual path, of course):
/path/to/rakudo-star-2017.07/install/bin
/path/to/rakudo-star-2017.07/install/share/perl6/site/bin
I use a module file for this:
#%Module1.0
## Metadata ###########################################
set this_module rakudo-star
set this_version 2017.07
set this_root /path/to/$this_module/$this_module-$this_version/install
set this_docs http://rakudo.org/documentation/
#######################################################
## Module #############################################
proc ModulesHelp { } {
global this_module this_version this_root this_docs
puts stderr "$this_module $this_version"
puts stderr "****************************************************"
puts stderr " $this_docs"
puts stderr "****************************************************\n"
}
module-whatis "Set up environment for $this_module $this_version"
prepend-path PATH $this_root/bin
prepend-path PATH $this_root/share/perl6/site/bin

dask_dot RuntimeError visualizing

I'm following the dask documentation and have installed dask[complete] and graphviz with pip, and graphviz as a system install.
where dot gives ...\Anaconda3\envs\compute\Library\bin\dot.bat which points to the proper executable location.
Now running this fails:
import dask.array as da
x = da.ones((5,15),chunks=(5,5))
d = (x+1).dask
from dask.dot import dot_graph
dot_graph(d)
with
RuntimeError: failed to execute ['dot', '-Tpng'], make sure the Graphviz executables are on your systems' path
I'm running python 3 and dask 0.14.3 on Windows 10.
According to the anaconda packagers this should now work if you run the following:
conda install python-graphviz
Alternatively you can always install graphviz yourself using normal Windows methods. Make sure that you pip install graphviz afterwards.

Resources