In my terminal window, i open the ipython enviroment, and then type in import matplotlib.pyplot as plt. The error message I get from doing this is:
ImportError Traceback (most recent call last)
<ipython-input-1-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
25
26 import matplotlib
---> 27 import matplotlib.colorbar
28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
35 import matplotlib.colors as colors
36 import matplotlib.contour as contour
/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
25 import matplotlib.artist as artist
26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
28 import matplotlib.path as mpath
29 from matplotlib import _path
/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
54
55 import matplotlib.tight_bbox as tight_bbox
---> 56 import matplotlib.textpath as textpath
57 from matplotlib.path import Path
58 from matplotlib.cbook import mplDeprecation
/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
20 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
21 from matplotlib.ft2font import LOAD_TARGET_LIGHT
---> 22 from matplotlib.mathtext import MathTextParser
23 import matplotlib.dviread as dviread
24 from matplotlib.font_manager import FontProperties
/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py in <module>()
61
62 import matplotlib.colors as mcolors
---> 63 import matplotlib._png as _png
64 ####################
65
ImportError: dlopen(/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: #loader_path/../../../libpng15.15.dylib
Referenced from: /Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: image not found
I would truly appreciate a way to resolve this issue. All I want to do is get on with my physics, and all this constant computational setback is quite cumbersome and annoying. I should thus appreciate an expedited response from anyone who may be willing to assist.
Continuum recently updated libpng, which caused this breakage. Sorry for the inconvenience.
The way to fix this error is to run in a terminal
conda update qt
conda update matplotlib
ImportError: dlopen(/Users/arazipinhas/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2):
Library not loaded: #loader_path/../../../libpng15.15.dylib
really simple: Your matplotlib was linked against libpng15, but that isn't found by your run-time. So you might search for that file, libpng15.15.dylib.
If it's missing, your installation is incomplete and you're probably missing the version of libPNG that was used to build matplotlib.
Related
When I try to import the beginning of this code I am faced with this error:
ImportError: DLL load failed while importing _imaging: The specified module could not be found.
My code is:
# Basic Imports
import numpy as np
import matplotlib.pyplot as plt
from glob import glob
from PIL import Image
# Imports for Building CNN
from keras.layers import Input, Lambda, Dense, Flatten
from keras.models import Model
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential, load_model
from tensorflow.keras.preprocessing.image import load_img
# Ignore Warnings
import warnings
warnings.filterwarnings("ignore")
The error (from jupyter notebook) appeared as:
``
ImportError Traceback (most recent call last)
Input In [5], in <cell line: 3>()
1 # Basic Imports
2 import numpy as np
3 import matplotlib.pyplot as plt
4 from glob import glob
5 from PIL import Image
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\matplotlib_init_.py:109, in
105 from packaging.version import parse as parse_version
107 # cbook must import matplotlib only within function
108 # definitions, so it is safe to import from it here.
109 from . import _api, _version, cbook, docstring, rcsetup
110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
111 from matplotlib.cbook import mplDeprecation # deprecated
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\matplotlib\rcsetup.py:27, in
25 from matplotlib import _api, cbook
26 from matplotlib.cbook import ls_mapper
27 from matplotlib.colors import Colormap, is_color_like
28 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
29 from matplotlib._enums import JoinStyle, CapStyle
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\matplotlib\colors.py:51, in
49 from numbers import Number
50 import re
51 from PIL import Image
52 from PIL.PngImagePlugin import PngInfo
54 import matplotlib as mpl
File D:\Black\miniconda3\envs\tensorflow\lib\site-packages\PIL\Image.py:100, in
91 MAX_IMAGE_PIXELS = int(1024 * 1024 * 1024 // 4 // 3)
94 try:
95 # If the _imaging C module is not present, Pillow will not load.
96 # Note that other modules should not refer to _imaging directly;
97 # import Image and use the Image.core variable instead.
98 # Also note that Image.core is not a publicly documented interface,
99 # and should be considered private and subject to change.
100 from . import _imaging as core
102 if version != getattr(core, "PILLOW_VERSION", None):
103 raise ImportError(
104 "The _imaging extension was built for another version of Pillow or PIL:\n"
105 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
106 f"Pillow version: {version}"
107 )
ImportError: DLL load failed while importing _imaging: The specified module could not be found.
``
I think something is outdated? if that is the case, what can I do to solve this issue?
After running runas /netonly /user:domain\username "ipython" on windows cmd, IPython 3.8.8 (installed via Anaconda) successfully launches but as soon as I start importing packages, I get DLL load failed errors. For example if I run import nltk or import matplotlib.pyplot I get the following error messages respectively:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-1d2184025e54> in <module>
----> 1 import nltk
~\Anaconda3\lib\site-packages\nltk\__init__.py in <module>
147 from nltk.tag import *
148 from nltk.tokenize import *
--> 149 from nltk.translate import *
150 from nltk.sem import *
151 from nltk.stem import *
~\Anaconda3\lib\site-packages\nltk\translate\__init__.py in <module>
21 from nltk.translate.bleu_score import sentence_bleu as bleu
22 from nltk.translate.ribes_score import sentence_ribes as ribes
---> 23 from nltk.translate.meteor_score import meteor_score as meteor
24 from nltk.translate.metrics import alignment_error_rate
25 from nltk.translate.stack_decoder import StackDecoder
~\Anaconda3\lib\site-packages\nltk\translate\meteor_score.py in <module>
8
9
---> 10 from nltk.stem.porter import PorterStemmer
11 from nltk.corpus import wordnet
12 from itertools import chain, product
~\Anaconda3\lib\site-packages\nltk\stem\__init__.py in <module>
27 from nltk.stem.isri import ISRIStemmer
28 from nltk.stem.porter import PorterStemmer
---> 29 from nltk.stem.snowball import SnowballStemmer
30 from nltk.stem.wordnet import WordNetLemmatizer
31 from nltk.stem.rslp import RSLPStemmer
~\Anaconda3\lib\site-packages\nltk\stem\snowball.py in <module>
27 import re
28
---> 29 from nltk.corpus import stopwords
30 from nltk.stem import porter
31 from nltk.stem.util import suffix_replace, prefix_replace
~\Anaconda3\lib\site-packages\nltk\corpus\__init__.py in <module>
64 from nltk.tokenize import RegexpTokenizer
65 from nltk.corpus.util import LazyCorpusLoader
---> 66 from nltk.corpus.reader import *
67
68 abc = LazyCorpusLoader(
~\Anaconda3\lib\site-packages\nltk\corpus\reader\__init__.py in <module>
103 from nltk.corpus.reader.categorized_sents import *
104 from nltk.corpus.reader.comparative_sents import *
--> 105 from nltk.corpus.reader.panlex_lite import *
106 from nltk.corpus.reader.panlex_swadesh import *
107
~\Anaconda3\lib\site-packages\nltk\corpus\reader\panlex_lite.py in <module>
13
14 import os
---> 15 import sqlite3
16
17 from nltk.corpus.reader.api import CorpusReader
~\Anaconda3\lib\sqlite3\__init__.py in <module>
21 # 3. This notice may not be removed or altered from any source distribution.
22
---> 23 from sqlite3.dbapi2 import *
~\Anaconda3\lib\sqlite3\dbapi2.py in <module>
25 import collections.abc
26
---> 27 from _sqlite3 import *
28
29 paramstyle = "qmark"
ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.
AND
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-864e826dab68> in <module>
----> 1 import matplotlib.pyplot
~\Anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
172
173
--> 174 _check_versions()
175
176
~\Anaconda3\lib\site-packages\matplotlib\__init__.py in _check_versions()
157 # Quickfix to ensure Microsoft Visual C++ redistributable
158 # DLLs are loaded before importing kiwisolver
--> 159 from . import ft2font
160
161 for modname, minver in [
ImportError: DLL load failed while importing ft2font: The specified module could not be found.
However, imports such as import numpy or import pandas run fine.
Furthermore, when launching "ipython" without runas all imports run perfectly.
Any ideas on what's going on here?
EDIT:
I can confirm that it is not an administrative thing.
I installed python independently from Anaconda - and now when I run runas /netonly /user:domain\username "C:\somenewpath\python", importing nltk and matplotlib are successful. However, this is not necessarily ideal for two reasons: 1) because I have to manually install a host of packages, and 2) now I have 2 separate python IDLEs sitting in my environment.
# lstm model
import tensorflow as tf
from numpy import mean
from numpy import std
from numpy import dstack
from pandas import read_csv
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import LSTM
from tensorflow.keras.utils import to_categorical
from matplotlib import pyplot
When i run this cell iam getting the below error, I am using jupyter notebook using anaconda, using anaconda every packages will be installed related to python but in this it is showing regarding tensorflow problem while the importing libraries, I am using latest version of python 3.9,would anyone help to resolve the issue
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10616/748904884.py in <module>
1 # lstm model
----> 2 import tensorflow as tf
3 from numpy import mean
4 from numpy import std
5 from numpy import dstack
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\__init__.py in <module>
39 import sys as _sys
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\__init__.py in <module>
44
45 # Bring in subpackages.
---> 46 from tensorflow.python import data
47 from tensorflow.python import distribute
48 # from tensorflow.python import keras
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\data\__init__.py in <module>
23
24 # pylint: disable=unused-import
---> 25 from tensorflow.python.data import experimental
26 from tensorflow.python.data.ops.dataset_ops import AUTOTUNE
27 from tensorflow.python.data.ops.dataset_ops import Dataset
~\AppData\Roaming\Python\Python39\sitepackages\tensorflow\python\data\experimental\__init__.py
in <module>
96
97 # pylint: disable=unused-import
---> 98 from tensorflow.python.data.experimental import service
99 from tensorflow.python.data.experimental.ops.batching import dense_to_ragged_batch
100 from tensorflow.python.data.experimental.ops.batching import dense_to_sparse_batch
~\AppData\Roaming\Python\Python39\site-
packages\tensorflow\python\data\experimental\service\__init__.py in <module>
372 from __future__ import print_function
373
--> 374 from tensorflow.python.data.experimental.ops.data_service_ops import distribute
375 from tensorflow.python.data.experimental.ops.data_service_ops import from_dataset_id
376 from tensorflow.python.data.experimental.ops.data_service_ops import register_dataset
~\anaconda3\envs\mygpu\lib\site-
packages\tensorflow\python\data\experimental\ops\data_service_ops.py in <module>
23
24 from tensorflow.python import tf2
---> 25 from tensorflow.python.data.experimental.ops import compression_ops
26 from tensorflow.python.data.experimental.ops.distribute_options import AutoShardPolicy
27 from tensorflow.python.data.experimental.ops.distribute_options import
ExternalStatePolicy
~\anaconda3\envs\mygpu\lib\site-
packages\tensorflow\python\data\experimental\ops\compression_ops.py in <module>
18 from __future__ import print_function
19
---> 20 from tensorflow.python.data.util import structure
21 from tensorflow.python.ops import gen_experimental_dataset_ops as ged_ops
22
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\data\util\structure.py in <module>
24 import wrapt
25
---> 26 from tensorflow.python.data.util import nest
27 from tensorflow.python.framework import composite_tensor
28 from tensorflow.python.framework import ops
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\data\util\nest.py in <module>
38 import six as _six
39
---> 40 from tensorflow.python.framework import sparse_tensor as _sparse_tensor
41 from tensorflow.python.util import _pywrap_utils
42 from tensorflow.python.util import nest
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\sparse_tensor.py in
<module>
26 from tensorflow.python import tf2
27 from tensorflow.python.framework import composite_tensor
---> 28 from tensorflow.python.framework import constant_op
29 from tensorflow.python.framework import dtypes
30 from tensorflow.python.framework import ops
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\constant_op.py in
<module>
27 from tensorflow.core.framework import types_pb2
28 from tensorflow.python.eager import context
---> 29 from tensorflow.python.eager import execute
30 from tensorflow.python.framework import dtypes
31 from tensorflow.python.framework import op_callbacks
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\eager\execute.py in <module>
25 from tensorflow.python import pywrap_tfe
26 from tensorflow.python.eager import core
---> 27 from tensorflow.python.framework import dtypes
28 from tensorflow.python.framework import ops
29 from tensorflow.python.framework import tensor_shape
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\dtypes.py in <module>
30 from tensorflow.python.util.tf_export import tf_export
31
---> 32 _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
33
34
TypeError: Unable to convert function return value to a Python type! The signature was
() -> handle
First try to install each package one by one and you will be able to use it at once.
I was having this issue on m1 macbook, turns out my tensorflow dependency was not in sync with my tensorflow-macos package. This would be a good place to check, In this page the version they give is 2.6.0 but the newest version for tf-macos when running this command python -m pip install tensorflow-macos gives 2.8.0 thus the error. If you just updated your tensorflow version this could very well be there case, go through you tensorflow dependencies and see if there's a mix up.
If that doesn't solve it, then yeah install tokenizer first then transformer, see if that solves the issue
Even though I have installed both the libraries several times using different orders in different virtual environments, I'm still facing an issue where I'm not able to import and use certain geospatial libraries like esda and libpysal. The following error shows up:
ImportError Traceback (most recent call last)
C:\Users\SLAADM~1\AppData\Local\Temp/ipykernel_35328/2667884714.py in <module>
3 import numpy as np
4 import matplotlib.pyplot as plt
----> 5 import esda
6 import libpysal as lps
7 import pysal
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\esda\__init__.py in <module>
5
6 """
----> 7 from . import adbscan
8 from .gamma import Gamma
9 from .geary import Geary
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\esda\adbscan.py in <module>
8 import pandas
9 import numpy as np
---> 10 from libpysal.cg.alpha_shapes import alpha_shape_auto
11 from scipy.spatial import cKDTree
12 from collections import Counter
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\__init__.py in <module>
25 Tools for creating and manipulating weights
26 """
---> 27 from . import cg
28 from . import io
29 from . import weights
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\cg\__init__.py in <module>
9 from .sphere import *
10 from .voronoi import *
---> 11 from .alpha_shapes import *
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\libpysal\cg\alpha_shapes.py in <module>
22
23 try:
---> 24 import pygeos
25
26 HAS_PYGEOS = True
c:\users\sla admin\appdata\local\programs\python\python39\lib\site-packages\pygeos\__init__.py in <module>
----> 1 from .lib import GEOSException # NOQA
2 from .lib import Geometry # NOQA
3 from .lib import geos_version, geos_version_string # NOQA
4 from .lib import geos_capi_version, geos_capi_version_string # NOQA
5 from .decorators import UnsupportedGEOSOperation # NOQA
ImportError: DLL load failed while importing lib: The specified procedure could not be found.
Would really appreciate any help in making this work. Please throw any suggestions you might have at me.
install pygeos i.e conda install pygeos
it worked for me
I found same issue when running example code from a couple of years ago. The pysal API has changed.
Import libpysal first then import the esda libraries eg
import libpysal
from esda.moran import Moran
from esda.smaup import Smaup
see
https://pysal.org/esda/generated/esda.Moran.html
I am trying to run a simple code and I have all the dependencies for matplotlib and numpy installed in my Canopy. Still I am getting error.
import cv2
import numpy as np
import matplotlib.pyplot as plt
x = cv2.imread('jay.jpg')
plt.imshow(x, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
Error:
%run "c:\users\jay\appdata\local\temp\tmppvibq9.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:\users\jay\appdata\local\temp\tmppvibq9.py in <module>()
2 import numpy as np
3 import matplotlib.cbook
----> 4 import matplotlib.pyplot as plt
5
6 x = cv2.imread('jay.jpg')
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\pyplot.py in <module>()
27 from cycler import cycler
28 import matplotlib
---> 29 import matplotlib.colorbar
30 from matplotlib import style
31 from matplotlib import _pylab_helpers, interactive
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\Lib\site-packages\matplotlib\artist.py in <module>()
9 import numpy as np
10 import matplotlib
---> 11 import matplotlib.cbook as cbook
12 from matplotlib.cbook import mplDeprecation
13 from matplotlib import docstring, rcParams
AttributeError: 'module' object has no attribute 'cbook'
Dependencies I have installed for numpy and matplotlib:
1.) libsvm-3.17.win64-py2.7
2.) pyparsing-2.0.3-1.win64-py2.7
3.) python-dateutil-2.4.2-2.win64-py2.7
4.) pytz-2015.7-1.win64-py2.7
5.) six-1.10.0-1.win64-py2.7
6.) scipy-0.13.3.win64-py2.7
7.) numpy-MKL-1.9.2-2.win64-py2.7
8.) Matplotlib 1.5.1-win64-py2.7
9.) pip 8.0.2-1.win64-py2.7
Try this:
Close your jupyter notebook and terminate ipython.
Restart Terminal
Enter this command in Terminal:
export LANG=en_US.UTF-8;export LC_ALL=en_US.UTF-8
Re-run your ipython / Jupyter notebook now. It works like a charm.
conda install matplotlib --force
I don't know for sure that this is causing your problem, but you are running your code in the wrong Python environment:
C:\Users\Jay\AppData\Local\Enthought\Canopy\System\
You should be running it in
C:\Users\Jay\AppData\Local\Enthought\Canopy\User
See
https://support.enthought.com/entries/23646538-Make-Canopy-User-Python-be-your-default-Python
and
http://docs.enthought.com/canopy/configure/faq.html#where-are-all-of-the-python-packages-in-my-user-python-environment
You can find which 'matplotlib.py' is imported and then open that file and check if it has 'cbook' or not.
import imp
imp.find_module("matplotlib")
i had the same problem and it was because of this line :
from sys import stdout
i deleted this import and the problem is gone now