Importing Matplotlib.pyplot: DLL load failed - python

When trying to import matplotlib.pyplot (in Spyder), I get the following error(s):
Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy as sp
>>> import numpy as np
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\figure.py", line 35, in <module>
from matplotlib import _image
ImportError: DLL load failed: Operation did not complete successfully because the file contains a virus or potentially unwanted software.
If I try to import it again, I get the following:
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\figure.py", line 35, in <module>
from matplotlib import _image
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\_image.py", line 7, in <module>
__bootstrap__()
File "C:\Users\...\Anaconda3_1\lib\site-packages\matplotlib\_image.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
File "C:\Users\...\Anaconda3_1\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
My version of Python is the following:
Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)]
I'm guessing this is a false positive by my antivirus (Avast), though I still get the second error after turning it off. Reinstalling the module or Anaconda did not work either.
Is it possible that my antivirus keeps deleting the DLL, and if so, is there a way to stop it from doing so? Or is my problem something else entirely?
Many thanks!

I had this exact same problem with Avast and matplotlib. My solution was to uninstall Anaconda, then reinstall the same version and add C:\Anaconda3 to the excepted scan directory in Avast.

Related

How to get SublimeText to load DLLs where they load fine using commandline

When using python through the commandline, I am able to import modules fine. However, when I build a python script in SublimeText3, some modules don't import. I generally receive the following error:
ImportError: DLL load failed: The specified module could not be found.
The problem looks to involve modules with dependencies on modules with a "_" prefix (_sqlite3, _ssl). For example:
File "C:\ProgramData\anaconda3\Lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\ProgramData\anaconda3\Lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
System:
Windows 10
SublimeText3 (freshly reinstalled during troubleshooting)
Python 3.7.3 [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
(freshly reinstalled during troubleshooting)
Both commandline and ST3 or pointing to same instance of Python.
This is the only python install on the machine.
Have used default Python build in ST3 and created a new build, both have same issue.
Results when using the commandline:
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import plotly
>>>
Results in ST3:
import plotly
Traceback (most recent call last):
File "C:\Users\usr\Desktop\scrap.py", line 1, in <module>
import plotly
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\__init__.py", line 32, in <module>
from plotly import (
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\graph_objs\__init__.py", line 3, in <module>
from plotly.basedatatypes import BaseLayoutType as _BaseLayoutType
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\basedatatypes.py", line 25, in <module>
from .callbacks import (Points, InputDeviceState)
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\callbacks.py", line 2, in <module>
from plotly.utils import _list_repr_elided
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\utils.py", line 262, in <module>
from chart_studio.utils import *
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\__init__.py", line 2, in <module>
from chart_studio import (plotly, dashboard_objs, grid_objs, session)
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\__init__.py", line 10, in <module>
from . plotly import (
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\plotly.py", line 38, in <module>
from chart_studio.plotly import chunked_requests
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\chunked_requests\__init__.py", line 1, in <module>
from . chunked_request import Stream
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\chunked_requests\chunked_request.py", line 4, in <module>
import ssl
File "C:\ProgramData\anaconda3\Lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
[Finished in 2.9s]
Any help much appreciated, been stuck on this for days.
For those with a similar issue in the future, I've fixed this by uninstalling the Anaconda distribution of Python and replacing it with a base Python installation from Python.org, then installing packages using pip manually. While not the ideal solution, this has solved the issue so that when I build a Python script in ST3, all modules are imported fine.

TensorFlow error: funcsigs module doesn't have signature attribute

I have installed TensorFlow and wanted to check the installation. Here is the interaction with the python console.
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 106, in <module>
from tensorflow.python.platform import test
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/platform/test.py", line 81, in <module>
import mock # pylint: disable=g-import-not-at-top,unused-import
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/mock.py", line 81, in <module>
inspectsignature = funcsigs.signature
AttributeError: 'module' object has no attribute 'signature'
>>>
Could anyone please tell what I am doing wrong? Thanks.
As Yaroslav noted, this is most likely from running too old a version of Python, or you don't have the funcsigs package installed. For the latter, try pip install funcsigs

Managed to break my venv; is it possible to fix?

I managed to break one of my virtual environments. I think I did it by installing pycrypto with pip and uninstalling it with easy_install.
This is what I get when I run python in the venv.
filip#dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$ python
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 49, in <module>
import posixpath as path
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 17, in <module>
import warnings
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/warnings.py", line 8, in <module>
import types
File "types.py", line 1, in <module>
import json
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 3, in <module>
import re
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 280, in <module>
import copy_reg
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 7, in <module>
from types import ClassType as _ClassType
ImportError: cannot import name ClassType
filip#dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$
And outside the venv everything works as expected:
Last login: Tue Apr 7 22:30:08 on ttys005
filip#dratmac:~$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How can I fix this?
You should not name your file types.py as there is a standard library module with the same name (import types).
As such, Python tries to import it as part of some standard library code but it now actually imports your local types.py file, not the module it expects.
So the problem should be fixed when you rename types.py to something else.

No module named machinery

I am trying to make exe using py2exe in Python. When I import py2exe I am getting error like this:
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import py2exe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\__init__.py", line 9, in <module>
patch_distutils()
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\patch_distutils.py", line 68, in patch_distutils
from . import distutils_buildexe
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\distutils_buildexe.py", line 91, in <module>
from . import runtime
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\runtime.py", line 3, in <module>
from .dllfinder import Scanner, pydll
File "C:\Python27\lib\site-packages\py2exe-0.9.2.0-py2.7-win32.egg\py2exe\dllfinder.py", line 7, in <module>
from importlib.machinery import EXTENSION_SUFFIXES
ImportError: No module named machinery
Can any body help me fixing this out. I am not getting machinery module any where.
I just ran into this myself. I had installed 0.9 from pypi as well. If you look at the pypi page here py2exe on pypi, you'll see that the download only supports Python 3.3 and later and you should use the 0.6 download from here. I deleted the 0.9 egg after installing 0.6 and it worked after that.
I had same issue, because i had version py2exe0.9 and it is not supported for python2.7.
I downloaded lower version from here http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.7.exe/download
and it works.

ImportError: DLL load failed - when trying to import spynner

When I run a code which imports spynner, I get the following error:
> python .\spynner-test.py
Traceback (most recent call last):
File ".\spynner-test.py", line 10, in <module>
import spynner
File "C:\Anaconda\lib\site-packages\spynner\__init__.py", line 2, in <module>
from browser import *
File "C:\Anaconda\lib\site-packages\spynner\browser.py", line 56, in <module>
from PyQt4.QtNetwork import QNetworkCookie, QNetworkAccessManager, QSslConfiguration, QSslCipher
ImportError: DLL load failed: The specified procedure could not be found.
A funny thing is that I can import those things in normal python shell without any problem:
> python
Python 2.7.5 |Anaconda 1.9.2 (64-bit)| (default, Jul 1 2013, 12:37:52) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4.QtNetwork import QNetworkCookie, QNetworkAccessManager, QSslConfiguration, QSslCipher
>>>
But after import spynner fails,
> python
Python 2.7.5 |Anaconda 1.9.2 (64-bit)| (default, Jul 1 2013, 12:37:52) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import spynner
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\spynner\__init__.py", line 2, in <module>
from browser import *
File "C:\Anaconda\lib\site-packages\spynner\browser.py", line 56, in <module>
from PyQt4.QtNetwork import QNetworkCookie, QNetworkAccessManager, QSslConfiguration, QSslCipher
ImportError: DLL load failed: The specified procedure could not be found.
>>> from PyQt4.QtNetwork import QNetworkCookie, QNetworkAccessManager, QSslConfiguration, QSslCipher
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified procedure could not be found.
>>>
Okay I figured it out. The problem is that spynner first tries to import PySide, and it gets an error in importing QSslConfiguration from PyQt4.QtNetwork. And then it switches to PyQt4, and apparently the previously imported PySide makes the PyQt4 import fail. When I remove the try: part in browser.py I could import spynner fine.

Categories

Resources