While importing pyplot from matplotlib it hangs - macos

I am trying to import pyplot but my python code will not run and gets stuck at the following spot:
from matplotlib import pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "matplotlib/pyplot.py", line 24, in <module>
import matplotlib.colorbar
File "matplotlib/colorbar.py", line 29, in <module>
import matplotlib.collections as collections
File "matplotlib/collections.py", line 23, in <module>
import matplotlib.backend_bases as backend_bases
File "matplotlib/backend_bases.py", line 50, in <module>
import matplotlib.textpath as textpath
File "matplotlib/textpath.py", line 11, in <module>
import matplotlib.font_manager as font_manager
File "matplotlib/font_manager.py", line 1356, in <module>
_rebuild()
File "matplotlib/font_manager.py", line 1341, in _rebuild
fontManager = FontManager()
File "matplotlib/font_manager.py", line 989, in __init__
self.ttffiles = findSystemFonts(paths) + findSystemFonts()
File "matplotlib/font_manager.py", line 318, in findSystemFonts
for f in get_fontconfig_fonts(fontext):
File "matplotlib/font_manager.py", line 275, in get_fontconfig_fonts
output = pipe.communicate()[0]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 791, in communicate
stdout = _eintr_retry_call(self.stdout.read)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
return func(*args)
I have tried uninstalling matplotlib using pip so that I can reinstall the package but that also throws a lengthy list of errors. I am running this on my Mac OSX 10.11.

Better use Conda.
I had this problem too [in windows]. I uninstalled and reinstalled python completely. Then, it was perfect. I think, it is because of corrupt files. Still, I moved to conda environment. It is more smooth and comfortable.
Download Anaconda from Scipy page
Open Conda command prompt
Use the code: -conda install pymc pymc
This code installs Conda environment, Scipy, Pymc, Numpy, matplotlib and setup tools
If you want only matplotlib, you can use pip install matplotlib.
It works good for me.
If you want to re-work on existing framework, better uninstall python setup and reinstall. Then try pip install. It works smoothly.
Hope this helps.

I ran into from matplotlib import pyplot as plt hanging on a remote Linux machined due to having X11 forwarding setup on the remote (client), but forgetting to start the X11 server locally. On Windows, I started XMing and was able to proceed.

Related

Class RunLoopModeTracker is implemented in both locations. Can't open Spyder

I have no idea what I'm doing.
MacOS Version 10.13.4 and Python 3.7.3
I had anaconda installed and was using spyder fine, but I thought I'd install spyder-terminal using command pip install spyder-terminal because I thought that's how I'd get the terminal to show? Anyways now when I try opening spyder, I get this error:
objc[1685]: Class RunLoopModeTracker is implemented in both /anaconda3/lib/python3.7/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (0x117d8e270) and /anaconda3/lib/libQt5Core.5.dylib (0x11fabda80). One of the two will be used. Which one is undefined.
Traceback (most recent call last):
File "/anaconda3/bin/spyder", line 11, in <module>
sys.exit(main())
File "/anaconda3/lib/python3.7/site-packages/spyder/app/start.py", line 186, in main
from spyder.app import mainwindow
File "/anaconda3/lib/python3.7/site-packages/spyder/app/mainwindow.py", line 90, in <module>
from qtpy import QtWebEngineWidgets # analysis:ignore
File "/anaconda3/lib/python3.7/site-packages/qtpy/QtWebEngineWidgets.py", line 22, in <module>
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ValueError: PyCapsule_GetPointer called with incorrect name
I tried uninstalling anaconda and then re-installing/updating and re-installing spyder, but I'm still unable to open. Anyone know how to fix this?

sklearn: ImportError: DLL load failed: The specified module could not be found

Ive updated my Python version from 3.5.4 to 3.6.6 (in Anaconda 3) and now the line
from sklearn.metrics.pairwise import cosine_similarity
causes the following error:
Traceback (most recent call last):
File "<ipython-input-3-743ac88bcf9a>", line 1, in <module>
from sklearn.metrics.pairwise import cosine_similarity
File "F:\Program Files\lib\site-packages\sklearn\__init__.py", line 64, in <module>
from .base import clone
File "F:\Program Files\lib\site-packages\sklearn\base.py", line 13, in <module>
from .utils.fixes import signature
File "F:\Program Files\lib\site-packages\sklearn\utils\__init__.py", line 13, in <module>
from .validation import (as_float_array,
File "F:\Program Files\lib\site-packages\sklearn\utils\validation.py", line 22, in <module>
from ..utils.fixes import signature
File "F:\Program Files\lib\site-packages\sklearn\utils\fixes.py", line 83, in <module>
from scipy.special import boxcox # noqa
File "F:\Program Files\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
Im on Windows 7, 64-bit; previously the line worked fine, and other packages (Pandas, Numpy etc) still work, so it doesn't appear to be a PATH issue as some have suggested.
Ive seen numerous similar questions but all solutions have so far failed. E.g.
roll the installation back to Python 3.5.4,
uninstall & re-install Pandas, Numpy, Scipy and Sklearn, also update MKL/MKL-RT.
The changes suggested in Error when trying to import sklearn modules : ImportError: DLL load failed: The specified module could not be found
were already implemented
Does anyone have any further suggestions (specific to Anaconda etc)?
I solved it, and (in my case) the problem was scipy, not sklearn.
What i did was uninstall scipy with conda: conda remove --force scipy, and then install it with pip: pip install scipy. That worked for me.

Keras installed but not working

I am using keras with theano as the back end to build a neural network on windows 10. My python version is 2.7. The problem is that when I try and use keras I keep getting a path error.
$python
>>import keras
Gives me the error
Problem occurred during compilation with the command line below:
"g++" -shared -g -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -I"C:\Python27\lib\site-packages\numpy\core\include" -I"C:\Python27\include" -I"C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof" -L"C:\Python27\libs" -L"C:\Python27" -o C:\Users\Patrick\AppData\Local\Theano\compiledir_Windows-10-10.0.14393-Intel64_Family_6_Model_61_Stepping_4_GenuineIntel-2.7.11-64\lazylinker_ext\lazylinker_ext.pyd C:\Users\Patrick\AppData\Local\Theano\compiledir_Windows-10-10.0.14393-Intel64_Family_6_Model_61_Stepping_4_GenuineIntel-2.7.11-64\lazylinker_ext\mod.cpp -lpython27
The system cannot find the path specified.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\__init__.py", line 3, in <module>
from . import activations
File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\activations.py", line 4, in <module>
from . import backend as K
File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\backend\__init__.py", line 70, in <module>
from .theano_backend import *
File "C:\Python27\lib\site-packages\keras-2.0.3-py2.7.egg\keras\backend\theano_backend.py", line 3, in <module>
import theano
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\__init__.py", line 66, in <module>
from theano.compile import (
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\compile\__init__.py", line 10, in <module>
from theano.compile.function_module import *
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\compile\function_module.py", line 21, in <module>
import theano.compile.mode
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\compile\mode.py", line 10, in <module>
import theano.gof.vm
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof\vm.py", line 662, in <module>
from . import lazylinker_c
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof\lazylinker_c.py", line 127, in <module>
preargs=args)
File "C:\Python27\lib\site-packages\theano-0.9.0-py2.7.egg\theano\gof\cmodule.py", line 2316, in compile_str
(status, compile_stderr.replace('\n', '. ')))
. ception: Compilation failed (return status=1): The system cannot find the path specified.
>>>
I can tell that I need to add to my system variables paths (at least I think so...) but no matter what I add I still get the error. I have tried adding
C:\Python27\lib
C:\Python27\lib\site-packages
Basically any of the paths it said could not be specified. Something to note would be that I had a lot of trouble getting scipy installed and had to get the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy not sure if that helps at all. Well that's my issue.
I was also facing the same issue and resolved with removing other python versions. Make sure that you have only 1 python installed. If there is multiple, thing sometimes don't work very well.
What i would suggest is use keras in a separate environment using conda.
Suppose you want to create an env named "myenv"
1.Open Anaconda promt and type the following:
conda create --name myenv
2.To activate the environment:
conda activate myenv
3.Now you can install keras and other dependencies:
pip install keras
Install tensorflow as follows.
pip install tensorflow==2.0.0

Version upgrade to scikit-learn

I wanted to do LDA on some data and so followed this example:
http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html#example-decomposition-plot-pca-vs-lda-py
however, on trying:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
I got an import error. Huh, maybe this is a new function, I thought. So I updated scikit-learn via conda from 0.15.2 to 0.17. But now I can't even import sklearn:
import sklearn
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "//anaconda/lib/python2.7/site-packages/sklearn/base.py", line 9, in <module>
from scipy import sparse
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/__init__.py", line 213, in <module>
from .csr import *
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/csr.py", line 13, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import
I tried updating numpy and scipy using both pip and conda to no avail. I then tried a complete clean re-install of anaconda by:
rm -rf ~/anaconda
and a subsequent download of the .pkg from http://docs.continuum.io/anaconda/install#anaconda-install
Still I get the same error. Here are my OS and package details:
Mac OSX 10.5.2
bash-3.2$ conda -V
conda 3.18.6
scipy==0.16.0
numpy==1.9.1
scikit-learn==0.17
The last of these via pip freeze since I can't import it. I'm going nuts here. Any help much appreciated.
Try:
conda install numpy=1.10.1
I've had that module compiled against API version a but this version of numpy is 9 error before, and this solved it for me.

import matplotlib.pyplot not working

I am new to python and just trying to set everything up. I've tried reinstalling but still keep getting an error when I try "import matplotlib.pyplot as plt", anyone know what this means?
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import matplotlib.pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py", line 23, in <module>
from matplotlib.figure import Figure, figaspect
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 16, in <module>
import artist
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 6, in <module>
from transforms import Bbox, IdentityTransform, TransformedBbox, TransformedPath
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/transforms.py", line 34, in <module>
from matplotlib._path import affine_transform
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_path.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_path.so: no matching architecture in universal wrapper
Thanks!
I've run into a similar problem when installing python and matplotlib on multiple Mac OSs. What I ended up doing was reinstalling with Python2.6 and also getting compatible packages. It took a little while to figure out which combination works with which architecture, but eventually I got everything to run.
The matplotlib website even mentions these issuse:
"The build situation on OSX is complicated by the various places one can get the png and freetype requirements from (darwinports, fink, /usr/X11R6) and the different architectures (x86, ppc, universal) and the different OSX version (10.4 and 10.5)."

Resources