Getting matplotlib backends for python 3.6 - qt

I installed ipython and matplotlib with pip (9.0.1) under python 3.6 (in Xubuntu 16.04), but no images are showing when I try to plot something.
starting ipython with ipython3 --matplotlib qt gives the following error:
ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5,
or PySide package to be installed, but it was not found.
I tried to install these with pip, but it fails:
$ pip3.6 install PySide
Collecting PySide
Downloading PySide-1.2.4.tar.gz (9.3MB)
100% |████████████████████████████████| 9.3MB 12.8MB/s
Complete output from command python setup.py egg_info:
only these python versions are supported: [(2, 6), (2, 7), (3, 2), (3, 3), (3, 4)]
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bzzpzy5q/PySide/
$ pip3.6 install PyQT
Collecting PyQT
Could not find a version that satisfies the requirement PyQT (from versions: )
No matching distribution found for PyQT
$ pip3.6 install PyQT4
Collecting PyQT4
Could not find a version that satisfies the requirement PyQT4 (from versions: )
No matching distribution found for PyQT4
$ pip3.6 install PyQT5
Collecting PyQT5
Could not find a version that satisfies the requirement PyQT5 (from versions: )
No matching distribution found for PyQT5
If I try ipython3 --matplotlib gtk, the error is:
ImportError: Gtk* backend requires pygtk to be installed.
But:
$ pip3.6 install pygtk
Collecting pygtk
Could not find a version that satisfies the requirement pygtk (from versions: )
No matching distribution found for pygtk
I seem to understand that something called PyGobject or PyGI replaced pygtk for python 3. And indeed, ipython3 --matplotlib gtk3 results in:
ImportError: Gtk3 backend requires pygobject to be installed.
But:
$ pip3.6 install pygobject
Collecting pygobject
Could not find a version that satisfies the requirement pygobject (from versions: )
No matching distribution found for pygobject
$ pip3.6 install PyGObject
Collecting PyGObject
Could not find a version that satisfies the requirement PyGObject (from versions: )
No matching distribution found for PyGObject
Finally, pip3.6 install PyGI succeeds!
But matplotlib still complains about GTK things not being installed.
What else should I try?

Getting the Tk backend to work
As #ImportanceOfBeingErnest suggested, at least one backend should be available: the Tk based one.
This is true provided the Tk development libraries were available when python was compiled. This was not the case for me (I suppose a pre-compiled python distribution should be Tk-enabled).
When I tried to start ipython with Tk as matplotlib backend (ipython3 --matplotlib tk), I had an error message similar to the following one:
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
A comment to the following answer explains how to get the Tk development libraries in Ubuntu: apt install tk-dev.
After doing this and recompiling python 3.6, an ipython3 --matplotlib tk session started without errors and could display graphics.
Setting the default backend choice
The matplotlib documentation gives an example of configuration file, which I downloaded as ~/.config/matplotlib/matplotlibrc. In that file I set backend : TkAgg.
Other backends
The comments in the above-mentioned configuration file mention the existence of yet another GUI backend based on WX, which, like PyGTK and PyQT, doesn't seem to be installable using pip for python 3.6 as of january 2017 (at least in Linux):
$ pip3.6 install wxpython
Collecting wxpython
Could not find a version that satisfies the requirement wxpython (from versions: )
No matching distribution found for wxpython

Related

Azure Machine Learning notebooks: ModuleNotFound error

I'm working through a Python exercise using Azure Machine Learning notebooks. I'm unable to import torch even after !pip install torch.
Notebook says Requirement already satisfied, then errors out with:
!pip install torch
import torch
data = torch.tensor(encode(text), dtype=torch.long)
print(data.shape, data.dtype)
print(data[:100])
4 sec
ModuleNotFoundError: No module named 'torch'
Requirement already satisfied: torch in /anaconda/envs/azureml_py38/lib/python3.8/site-packages (1.12.0)
Requirement already satisfied: typing-extensions in /anaconda/envs/azureml_py38/lib/python3.8/site-packages (from torch) (4.4.0)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [22], in <cell line: 4>()
1 # Encode the entire dataset and store it into a torch.Tensor
3 get_ipython().system('pip install torch')
----> 4 import torch
5 data = torch.tensor(encode(text), dtype=torch.long)
6 print(data.shape, data.dtype)
ModuleNotFoundError: No module named 'torch'
I opened up a terminal in Azure ML Studio and tried pip install torch too, same Requirement already satisfied message showed.
How do I get torch (and any other Python modules where this occurs) working in AML notebooks?
I've found creating environments and installing packages through the terminal to be a much more reliable experience than doing it from an AML notebook.
I suggest using one of the provided terminals (either the one available in the compute instance's details, or the one available in JupyterLab) to create a new conda environment which you can customize to your liking.
Something like:
conda create -n my_tutorial python=3.10
conda activate my_tutorial
pip install --user ipykernel
python -m ipykernel install --user --name=my_tutorial
# Do a complete install of PyTorch, take a look at the available versions here https://pytorch.org/get-started/previous-versions/
conda install pytorch=1.13 torchvision=0.14 torchaudio=0.13 pytorch-cuda=11.7 -c pytorch -c nvidia -y
Afterwards, just make sure your notebooks use the my_tutorial kernel and you should be good to go. Whenever you want to pip install something new, just go back to the terminal, activate your kernel, and install the thing, then it should be available in your notebooks as well.
The issue was lined out in the docs here. Don't use !pip within the notebook. Instead use %pip.

Getting Altair to work with Jupyter Notebook

Trying to get Altair to work with Jupyter Notebook, I installed it using
conda install -c conda-forge altair vega_datasets notebook vega
But when I try to do an example plot
import altair as alt
from vega_datasets import data
# for the notebook only (not for JupyterLab) run this command once per session
alt.renderers.enable('notebook')
iris = data.iris()
alt.Chart(iris).mark_point().encode(
x='petalLength',
y='petalWidth',
color='species'
)
as seen in their quick start guide, I get
ValueError:
To use the 'notebook' renderer, you must install the vega package
and the associated Jupyter extension.
See https://altair-viz.github.io/getting_started/installation.html
for more information.
even though I have installed vega using Conda. I can make vega example plots though. I am unable to enable the Jupyter extension though, as Jupyter says it is incompatible.
Any help is appreciated.
For the current release of altair (Version 2.2), use
conda install -c conda-forge vega=1.3
or
pip install vega==1.3
and then restart the notebook.
The vega python extension was mistakenly updated this week to only support vega-lite 3.0, which is not yet released and thus not yet supported by Altair.
See https://github.com/altair-viz/altair/issues/1114 for the initial bug report.

OpenMDAO installation

I need openmdao on windows 8 to run an aerostructutal optimization code that uses it but I’m having issues in the installation process. I installed numpy and scipy through pip in the cmd and then also openmdao using pip install openmdao but when I try to run a .py with copied inside the code at the bottom of this page, I get an error about “Component” not being found to import. What am I doing wrong ?
Some codes are written for a specific version of OpenMDAO. If you are using OpenAeroStruct, it requires OpenMDAO 1.7.4, not OpenMDAO 2.2.x.
To obtain the correct version, you would need to use the command pip install openmdao==1.7.4 or to download and install the source directly from here: https://github.com/OpenMDAO/openmdao1, following the instructions on the README, not on readthedocs.

PyQT5 error: could not find or load Qt platform plugin xcb

Up until Anaconda3 (which contains Python 3.4) was re-installed on my RedHat 6.5 workstation, I have been able to develop Python apps that use PyQT5.
Post re-install of Anaconda I receive an error message:
....could not find or load Qt platform plugin xcb
The only difference between Anaconda installs is the folder name: /usr/local/ananaconda3 vs /usr/local/anaconda_py3
I checked libqxcb.so has no missing dependencies.
I rebuilt PyQT5.
I tried explicitly adding location of site-packages of PyQT5:
import site
site.addsitedir("...path.../python3.4")
Any other suggestions?
How does re-installing Python impact the use of PyQT5?
This is an error caused by having two different versions of Qt under the same installation/environment.
Check the packages installed and their versions in your environment (if for some reason you're not working in a virtual environment, you can skip the first line):
source activate yourenvname
conda list
If you see pyqt and qt both with version 4.X.X then remove them (assuming you want to work in Qt v5):
conda remove qt
conda remove pyqt
I had an issue that seems to match what happened here.
But in my case the solution was to "sudo rm -rf user/anaconda3" and reinstall it with "bash anaconda....sh", because I had previously installed it using sudo ("sudo bash anaconda....sh")

Error installing PyQt5

I am trying to install PyQt 5 on my Mac osx 10.9, so I did the following:
I downloaded SIP and installed it.
I downloaded QT 5.3.2 and installed it by its installer, so now its installed in
/Users/username/Qt
so i have added it to the path by doing this
PATH=/Users/gollahalli/Qt/5.3/clang_64/bin:$PATH
and
export PATH
Next i tried installing PyQt by doing the following
python3 configure.py --qmake /Users/username/Desktop/PyQt
but i still get this error
Error: PyQt5 requires Qt v5.0 or later. You seem to be using v3. Use the --qmake flag to specify the correct version of quake.
Any idea what went wrong?
You could point --qmake directly to the binary rather than the toplevel directory. In my case this was:
python3 configure.py --qmake ~/Qt5.4.1/5.4/clang_64/bin/qmake

Resources