Import Error Python (dlopen() symbol not found) - python

I have a simple import in python code (import matplotlib.pyplot as plt), but I keep getting this error, any idea how to solve it? (Using it on VS Code, on an Apple M1 pro chip).
Traceback (most recent call last):
File "/Users/mk/Desktop/courses spring 22/EECE 433/assignment 1/code/code.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/Users/mk/Library/Python/3.8/lib/python/site-packages/matplotlib/__init__.py", line 109, in <module>
from . import _api, _version, cbook, docstring, rcsetup
File "/Users/mk/Library/Python/3.8/lib/python/site-packages/matplotlib/rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "/Users/mk/Library/Python/3.8/lib/python/site-packages/matplotlib/colors.py", line 51, in <module>
from PIL import Image
File "/Users/mk/Library/Python/3.8/lib/python/site-packages/PIL/Image.py", line 89, in <module>
from . import _imaging as core
ImportError: dlopen(/Users/mk/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_xcb_connect'

Related

ImportError: cannot import name '_assert_shallow_structure' from 'tree'

I am getting that error while importing tensorflow_probability in IDLE(Default python editor). I don't get that error if use same code in VS code. Works perfectly fine in VS code.
Here are my imports
import numpy as np
import tensorflow.compat.v1 as tf
import tensorflow_probability as tfp
tf.disable_v2_behavior()
Here is complete error
Traceback (most recent call last):
File "C:\Python Scripts\pos_tagging.py", line 4, in <module>
import tensorflow_probability as tfp
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\__init__.py", line 77, in <module>
from tensorflow_probability.python import * # pylint: disable=wildcard-import
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\__init__.py", line 21, in <module>
from tensorflow_probability.python import bijectors
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\__init__.py", line 23, in <module>
from tensorflow_probability.python.bijectors.absolute_value import AbsoluteValue
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\absolute_value.py", line 23, in <module>
from tensorflow_probability.python.bijectors import bijector
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\bijectors\bijector.py", line 31, in <module>
from tensorflow_probability.python.internal import distribution_util
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\distribution_util.py", line 28, in <module>
from tensorflow_probability.python.internal import prefer_static
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\prefer_static.py", line 30, in <module>
from tensorflow_probability.python.internal.backend import numpy as nptf
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\__init__.py", line 21, in <module>
from tensorflow_probability.python.internal.backend.numpy import bitwise
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\bitwise.py", line 23, in <module>
from tensorflow_probability.python.internal.backend.numpy import _utils as utils
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\_utils.py", line 26, in <module>
from tensorflow_probability.python.internal.backend.numpy import nest
File "C:\Users\aaaa\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow_probability\python\internal\backend\numpy\nest.py", line 34, in <module>
from tree import _assert_shallow_structure
ImportError: cannot import name '_assert_shallow_structure' from 'tree' (C:\Users\aaaa\AppData\Local\Programs\Python\Python38\Lib\idlelib\tree.py)
Python Version:3.8.5 64 bit
Windows machine
Look at where it's importing from (C:\Users\aaaa\AppData\Local\Programs\Python\Python38\Lib\idlelib\tree.py) I think you meant to import from dm-tree.
Here's my solution:
if you don't have dm-tree installed
pip install dm-tree
if you do, install PyCharm and use that to run the code. It wont have the conflict that IDLE would on the tree.py

cannot import numpy when script located in a subdirectory

I have a folder structure like so
root/
A0/
A1/
B0/
B1/
Lets say I have a file called test.py. In it, I import numpy like so
import numpy as np
That is all that is contained in the file. This works without issue when it is located in root, subfolder A0,A1,B0 but raises an error in subfolder B1. Is error raised is as follows:
Traceback (most recent call last):
File "pose/utils/test.py", line 1, in <module>
import numpy as np
File "/home/adrian/.local/lib/python3.6/site-packages/numpy/__init__.py", line 187, in <module>
from .testing import Tester
File "/home/adrian/.local/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/usr/lib/python3.6/unittest/__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "/usr/lib/python3.6/unittest/case.py", line 6, in <module>
import logging
File "/home/adrian/Projects/lpr-pose-estimation/pose/utils/logging.py", line 3, in <module>
from pose.utils.utils import mkdir_if_missing
File "/home/adrian/Projects/lpr-pose-estimation/pose/utils/utils.py", line 4, in <module>
from scipy.misc import imresize
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/misc/__init__.py", line 68, in <module>
from scipy.interpolate._pade import pade as _pade
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/interpolate/__init__.py", line 175, in <module>
from .interpolate import *
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/interpolate/interpolate.py", line 32, in <module>
from .interpnd import _ndim_coords_from_arrays
File "interpnd.pyx", line 1, in init scipy.interpolate.interpnd
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/spatial/__init__.py", line 98, in <module>
from .kdtree import *
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/spatial/kdtree.py", line 8, in <module>
import scipy.sparse
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/sparse/__init__.py", line 230, in <module>
from .base import *
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/sparse/base.py", line 9, in <module>
from scipy._lib._numpy_compat import broadcast_to
File "/home/adrian/.local/lib/python3.6/site-packages/scipy/_lib/_numpy_compat.py", line 16, in <module>
_assert_warns = np.testing.assert_warns
AttributeError: module 'numpy' has no attribute 'testing'
Importing as modules (e.g cv2) also leads to errors, but only wrt to numpy:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "pose/utils/test.py", line 1, in <module>
import cv2 as cv
File "/home/adrian/.local/lib/python3.6/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
What may be the cause of such an error?
If your start script is located in .../pose/utils then every absolute import looks for modules there, too. This directory contains a module named logging (like the one in the standard library).
During the initialization of the numpy package (executing its __init__.py) and before numpy.testing is available the usual chain of imports happens (as can be seen in the traceback) which leads to the wrong logging module which in turn leads to import of _numpy_compat which tries to access numpy.testing too early.
To avoid this circular import problem you can either rename your logging module or move the start script to another directory.

Module not found when using scipy

I have recently properly installed numpy and scipy. The following line runs without error.
import scipy
I am experiencing difficulty using scipy.io.wavefile. I have been trying to use the code from the "best answer" of this post.
However, when I try the first line,
from scipy.io import wavfile
I receive the following error and traceback,
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from scipy.io import wavfile
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\__init__.py", line 97, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\matlab\__init__.py", line 13, in <module>
from .mio import loadmat, savemat, whosmat
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\matlab\mio.py", line 12, in <module>
from .miobase import get_matfile_version, docfiller
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\matlab\miobase.py", line 22, in <module>
from scipy.misc import doccer
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\misc\__init__.py", line 68, in <module>
from scipy.interpolate._pade import pade as _pade
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\interpolate\__init__.py", line 175, in <module>
from .interpolate import *
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\interpolate\interpolate.py", line 21, in <module>
import scipy.special as spec
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
from ._ufuncs import *
File "_ufuncs.pyx", line 1, in init scipy.special._ufuncs
ImportError: DLL load failed: The specified module could not be found.
I also receive an error and traceback if I try the following line instead,
import scipy.io.wavfile
receiving a different response,
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import scipy.io.wavfile
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\__init__.py", line 97, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\matlab\__init__.py", line 13, in <module>
from .mio import loadmat, savemat, whosmat
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\matlab\mio.py", line 12, in <module>
from .miobase import get_matfile_version, docfiller
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\io\matlab\miobase.py", line 22, in <module>
from scipy.misc import doccer
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\misc\__init__.py", line 68, in <module>
from scipy.interpolate._pade import pade as _pade
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\interpolate\__init__.py", line 175, in <module>
from .interpolate import *
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\interpolate\interpolate.py", line 21, in <module>
import scipy.special as spec
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\special\__init__.py", line 642, in <module>
from .basic import *
File "C:\Users\Me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\special\basic.py", line 15, in <module>
from ._ufuncs import (ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma,
ImportError: cannot import name 'ellipkm1' from 'scipy.special._ufuncs' (unknown location)
I do not understand why the module can not be found, if scipy is properly installed and can be imported by itself. I am using python 3.7.1. Could the code from the post be depreciated?
Apologies in advance for the long post.
Both error messages are complaining about the scipy.special._ufuncs module and a quick search revealed a few other posts, like this one, that suggest making sure you have the Visual C++ Redistributable Packages installed: https://www.microsoft.com/en-us/download/details.aspx?id=48145

matplotlib ticker error on remote cluster

I have a Python code that works properly on my local machine. But when I run the same code on a remote cluster I get the following error:
Traceback (most recent call last):
from matplotlib import ticker as mtick # Import mtick for tick locating and formatting.
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/ticker.py", line 158, in <module>
from matplotlib import transforms as mtransforms
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
The source of error is from matplotlib import ticker as mtick, but it works properly on my local machine. matplotlib version on both local and remote cluster is 1.4.3. Why does this error occur and how to fix it?
Update
When I comment that line I backend_pdf creates the following error:
from matplotlib.backends.backend_pdf import PdfPages # Import PDF matplotlib backend.
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.py", line 35, in <module>
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 45, in <module>
import matplotlib.transforms as transforms
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: /home/nxkr/.local/lib/python2.7/site-packages/matplotlib/_path.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
Commenting that causes pyplot to throw this error:
import matplotlib.pyplot as plt # Import matplotlib for plotting.
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: /home/nxkr/.local/lib/python2.7/site-packages/matplotlib/_path.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
Why is that the same version of matplotlib is creating problems on different machines?

Plotting a simple graph

I am trying to plot a simple graph using python.
the code i used is as follows
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
It throws me an error called (Import Error : NO module called _path)
the error message is as follows.,
Traceback (most recent call last):
File "C:/Users/s siddharth kumar/Desktop/graph2.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\matplotlib\pyplot.py", line 26, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Python27\lib\matplotlib\figure.py", line 24, in <module>
import matplotlib.artist as martist
File "C:\Python27\lib\matplotlib\artist.py", line 7, in <module>
from transforms import Bbox, IdentityTransform, TransformedBbox, \
File "C:\Python27\lib\matplotlib\transforms.py", line 35, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: No module named _path
Do i need to change the path of my running python in system variables or anything., ? I installed numpy,matplotlib and everything but still then I was not able to plot this simple values on the graph.

Categories