import matplotlib.pyplot failing: _tkagg.pyd not found but IS in the directory of calling module - python-3.x

Python 3.4
Windows 8.1
Installed modules:
matplotlib 1.3.1 for py 3.4
numpy-MLK 1.9.0b1 for py 3.4
dateutil 2.2 for py 3.4
six 1.7.3 for py 3.4
tcl
tkinter
Also msvcp71.dll is in C:\Windows\System32 (installation docs said it needed to be)
Upon running:
import matplotlib.pyplot as plt
I get the following error message:
Traceback (most recent call last):
File "<pyshell#284>", line 1, in <module>
import matplotlib.pyplot as plt
File "D:\Downloaded Programs\Python\lib\site-packages\matplotlib\pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "D:\Downloaded Programs\Python\lib\site-packages\matplotlib\backends\__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "D:\Downloaded Programs\Python\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 11, in <module>
import matplotlib.backends.tkagg as tkagg
File "D:\Downloaded Programs\Python\lib\site-packages\matplotlib\backends\tkagg.py", line 2, in <module>
from matplotlib.backends import _tkagg
ImportError: DLL load failed: The specified module could not be found.
Point being: Python\lib\site-packages\matplotlib\backends\tkagg.py is trying to
execute
from matplotlib.backends import _tkagg
but failing to do so. However _tkagg.pyd file does exist in the directory
Python\lib\site-packages\matplotlib\backends
Why is this not working then?

I know this is an old thread, but I just ran into the same problem and I found a solution, so I decided to answer it.
By taking a look at matplotlib install documentation, it says:
For Python 3.5 the Visual C++ Redistributable for Visual Studio 2015 needs to be installed.
I installed it's 64 bit version from it's Microsoft website (as I use 64 bit Python 3.6.3, and now the import works fine.
I hope it helps anyone that may face the same issue in the future.

Related

I am getting an error when I load Pandas and Numpy in

I am getting below error when execute below:
import numpy as np
The full stack trace:
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 14, in <module>
from . import multiarray
ImportError: DLL load failed: The specified module could not be found.
Process finished with exit code 1
This looks like some of the dependencies are missing for the package numpy. The DLL load failed error points towards either incorrectly installed and/or missing files for package numpy. You should just try installing numpy again through Anaconda CLI using the following command:
conda install numpy
This works most of the times, if your python environments are sorted correctly. Do make sure that the python installation you're using for Anaconda, is the same one as your coding environment. Conflicting versions can sometimes lead to corrupted packages.
You could also try the following command to update the Anaconda Environment just to make sure that the installations are up to date, and not conflicting with older versions..
conda update -y -all

Can't get opencv working with a gtk backend on my mac

I am trying to do some human pose estimation with a cool library that can be found here:
https://github.com/DeNA/Chainer_Realtime_Multi-Person_Pose_Estimation
I have it working on still images using the tkagg backend, set via the following lines:
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
Unfortunately, to do the live webcam tracking it seems tkagg will not work. When I run the code to do live web cam tracking i get the following error:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 583
This seems to be telling me to use the GTK backend, which makes sense as that is what the original repo said to use. The issue is when i change the matplotlib.use line to GTK like so:
import matplotlib
matplotlib.use('GTK')
import matplotlib.pyplot as plt
This gives an error with the following trace:
Traceback (most recent call last):
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 14, in
import gobject
ImportError: No module named 'gobject'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "camera_pose_demo.py", line 4, in <module>
from pose_detector import PoseDetector, draw_person_pose
File "/Users/mark/Downloads/Chainer_Realtime_Multi-Person_Pose_Estimation-master/pose_detector.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 18, in <module>
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
This is obviously saying my program can't find the GTK backend. I have installed it via brew, but I have read of other people having this problem too - just withouth a clear answer. It seems as though I need to find GTK on my machine and explicitly tell my python program/virtualenv where that is, although i am not sure how to do this.
You need to install PyGTK (python wrapper for GTK) which in turn require pygobject (python wrapper for GObject).
PyGTK seems to be rather old (2011 year), I am not sure it works with Python 3.

error of import scipy.stats for windows 7

I use windows 7 and installed python 3.5 32bit. I installed numpy 1.11 + mkl win32 whl version for python 3.5 from http://www.lfd.uci.edu/~gohlke/pythonlibs/
and installed scipy 0.17.0 from the same site same way. I use pip install. No problem import numpy and scipy, but see error when import scipy.stats or from scipy import stats, etc... Here is the error message:
if from scipy import stats:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from scipy import stats
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
import scipy.special as special
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 627, in <module>
from ._ufuncs import *
File "scipy\special\_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:26242)
ImportError: DLL load failed: The specified module could not be found.
If use import scipy.stats see below error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import scipy.stats
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
import scipy.special as special
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 629, in <module>
from .basic import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\basic.py", line 14, in <module>
from ._ufuncs import (ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta,
ImportError: cannot import name 'ellipkm1'
I have searched for solution from websites but could not find an answer. Please help. This is really frustrating...
Thanks
Rocky
Ok, finally I solved this myself. At the beginning I knew I needed the 2015 visual C++ redistribution and had it installed, the problem is I installed the 64bit one while obviously I should have used 32 bit one since my python and numpy, scipy were all 32 bit.
Hope this helps for other people

beautifulsoup 4.4 on python 3.5

I am having issues on a new PC and cannot find an answer anywhere. I am trying to get beautifulsoup 4.4 to work on python 3.5. I am using pyCharm - I am reading that they may not be compatible but I have the same setup on my laptop and it works perfectly - only difference is the PC I am trying get BS to work on is Windows 7 where my laptop is Windows 8.
When I go into settings and look at Project Interpreter I do see BS 4.4.1 but when I try and run something I am getting this error:
Traceback (most recent call last):
File "C:/Users/PP/PycharmProjects/Shark/NOCO.py", line 3, in <module>
from bs4 import BeautifulSoup
File "C:\Users\PP\AppData\Local\Programs\Python\Python35-32\lib\site-packages\bs4\__init__.py", line 29, in <module>
from .builder import builder_registry
File "C:\Users\PP\AppData\Local\Programs\Python\Python35-32\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
from . import _htmlparser
File "C:\Users\PP\AppData\Local\Programs\Python\Python35-32\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
from html.parser import (
ImportError: cannot import name 'HTMLParseError'
You are not running BeautifulSoup 4.4.1; your traceback shows you have an older version.
In 4.4.1, that section looks like this:
try:
from html.parser import HTMLParseError
except ImportError as e:
# HTMLParseError is removed in Python 3.5. Since it can never be
# thrown in 3.5, we can just define our own class as a placeholder.
class HTMLParseError(Exception):
pass
Line 7 is try:. This change was made in 4.4.0, so you have 4.3.2 or older installed instead.
Upgrade your installed package. PyCharm can do this, or you can use pip:
python3 -m pip install -U beautifulsoup4

from pandas import * -- Python issue

I am trying to run the following code in python 3.3
from pandas import *
and I receive the following error:
Traceback (most recent call last):
File "C:\Users\Tom\Desktop\ProgrammingStuff\Python\FXCointegrationBacktesting.py", line 9, in <module>
cannot import name text_type
from pandas import *
File "C:\Python33\lib\site-packages\pandas\__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "tslib.pyx", line 31, in init pandas.tslib (pandas\tslib.c:48782)
File "C:\Python33\lib\site-packages\dateutil\parser.py", line 24, in <module>
from six import text_type, binary_type, integer_types
ImportError: cannot import name text_type
Not sure what the problem is, I am fairly new to python and I cannot currently find any solutions to this problem on stack overflow.
Thanks!
You're using a version of dateutil that depends on six.
In dateutil <= 1.5 you don't need six, but those versions are not compatible with Python >= 3.0. So, the solution is to install six. However you do that is up to you.
You could do
pip install six
If you choose not to use pip it will depend on your system's package manager how you go about installing it.

Resources