matplotlib figure does not open since update - matplotlib

After an update to ipython 5.0.0 figures do not open in interactive mode anymore. At least for me. They do open in a normal python shell though.
So this works, i.e. a window with a plot opens:
me#box:~$ python
Python 3.5.2 |Anaconda 2.4.1 (64-bit)| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> plt.plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x7fc5fdbbae48>]
While this does not work:
me#box:~$ ipython
Python 3.5.2 |Anaconda 2.4.1 (64-bit)| (default, Jul 2 2016, 17:53:06)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
In [1]: import matplotlib.pyplot as plt
In [2]: plt.ion()
In [3]: plt.plot([1,2,3])
Out[3]: [<matplotlib.lines.Line2D at 0x7fab81f31da0>]
A window does open, when I hit Ctrl+D to leave ipython or when I type plt.pause(0.1).
I should add, that it does work when I use ipython --pylab.
So the question is: What important things does ipython --pylab do apart from:
import matplotlib.pyplot as plt
plt.ion()

Related

Can't install packages via pip, with error: ERROR: Could not find a version that satisfies the requirement, but can import via python console?

I am getting essentially the same errors on multiple packages install via pip on Ubuntu 20.04 using python3.8.10:
ERROR: Could not find a version that satisfies the requirement (from versions: none)
ERROR: No matching distribution found for
However, if I run python3 in the console, i can import these packages that are not shown up on pip list and can't be installed. How to fix?:
python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> import logging
>>> import re
>>> import traceback
>>> import subprocess
>>> dir(subprocess)
['CalledProcessError', 'CompletedProcess', 'DEVNULL', 'PIPE', 'Popen', 'STDOUT', 'SubprocessError', 'TimeoutExpired', '_PIPE_BUF', '_PopenSelector', '_USE_POSIX_SPAWN', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_active', '_args_from_interpreter_flags', '_cleanup', '_mswindows', '_optim_args_from_interpreter_flags', '_posixsubprocess', '_time', '_use_posix_spawn', 'builtins', 'call', 'check_call', 'check_output', 'contextlib', 'errno', 'getoutput', 'getstatusoutput', 'io', 'list2cmdline', 'os', 'run', 'select', 'selectors', 'signal', 'sys', 'threading', 'time', 'warnings']
>>>
Please advise on how to fix it so Pip would synch with what i am able to import at runtime, ie. python console.
Do i need to set PYTHONPATH variable?

ImportError: cannot import name 'TFBertModel' from 'transformers' (unknown location)

I'm trying to use a tensorflow model with huggingface transformers. No success so far... Any hint would be appreciated !
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__version__
'2.0.0'
>>> from transformers import TFBertModel
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TFBertModel' from 'transformers' (unknown location)
>>>

import tensorflow in a Jython session?

I am wondering whether importing Tensorflow in a jython session is feasible and if so, how shall I configure my environment to get it running.
Of course, using python, importing Tensorflow works as expected. Is Tensorflow compatible with Jython ?
[mata] /home/mata/mlp > python
imPython 2.7.12 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:42:40) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow as tf
>>>
whereas with Jython
[mata] /home/mata/mlp > jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_101
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow
>>>
Update:
I tried to load the libtensorflow JAR but still, I seem to be missing something here...
>>> import sys
>>> sys.path.append("libtensorflow-1.2.1.jar")
>>> help(tf) # OK
but I must be missing some obvious step to get the hello Tensorflow case work...
No, Jython won't work with Python modules that use C/C++.
The jar you're trying to use is for the Java API (over JNI), so guess you've already seen https://www.tensorflow.org/install/install_java

unable to figure out which package update lead to change of CA certs location for python requests package

I am trying to figure out which package update could have lead to change in the default CA location for python requests package. Listed below is my findings on 2 different nodes running RHEL 7.
One can check what cert-store is being used by requests package as specified below:
[root#compute-01 test]# python -mrequests.certs
/etc/pki/tls/certs/ca-bundle.crt
[root#compute-01 test]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root#compute-01 test]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.7.0'
The same thing on the other node is as follows:-
[root#compute-25 test]# python -m requests.certs
/usr/lib/python2.7/site-packages/requests/cacert.pem
[root#compute-25 test]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root#compute-25 test]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.7.0'
I am unable to figure out which package might have got upgraded which lead to this. I am unable to figure out what next I should check. Kindly advise.
One version of requests (the former) was installed by your system package manager and the latter was installed by pip.

Mac Lion Python install: Matplotlib ends in mysql error

I am setting up python/numpy/scipy/matplotlib/mysql on my Mac Lion. I first installed Python 2.7.3 and mysqldb. I then updated to XCode 4.3.3 and used the ScipySuperpack to install numpy, scipy, etc.
at this point I am able to import several packages in python without incident but matplotlib dies as follows:
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import _mysql
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg/_mysql.py:3:
UserWarning: Module _mysql was already imported from
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg/_mysql.pyc, but
/Users/myname/pypy is being added to sys.path
>>> import matplotlib
Error 2002: Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2)
Sorry if the question is basic but I don't understand the warning, or what it may have to
do with the eventual error...
Strange. There is probably some internal namespace collision going on (given that this doesn't happen if you are in the mysql build directory). Matplotlib does not use mysql in any way, I checked this from a clone of the matplotlib source with:
$> grep -ir mysql *
And got no hits. But I guess the obvious answer is not to import matplotlib from within the mysql build directory...