Cannot import name array - python

Traceback (most recent call last):
File "try5.py", line 3, in <module>
from matplotlib import pyplot as plt
File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/matplotlib/__init__.py", line 129, in <module>
from matplotlib.externals.six.moves.urllib.request import urlopen
File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/matplotlib/externals/six.py", line 90, in __get__
result = self._resolve()
File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/matplotlib/externals/six.py", line 158, in _resolve
module = _import_module(self.mod)
File "/home/zaverichintan/miniconda2/lib/python2.7/site-packages/matplotlib/externals/six.py", line 80, in _import_module
__import__(name)
File "/home/zaverichintan/miniconda2/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/home/zaverichintan/miniconda2/lib/python2.7/httplib.py", line 69, in <module>
from array import array
ImportError: cannot import name array
I have imported numpy , scipy , matplotlib and opencv.
The code getting executed on windows 7 machine but after upgrading to ubuntu 16.04, getting error like this.
the python version shows 2.7 but on the ubuntu site it is showing python 3.
Any help is appreciated.

Related

I'm trying to run a Python SDK and am getting errors from runpy.py. How to fix it?

(base) kiin#kiin ~ % python3 -m anki_vector.configure
Traceback (most recent call last):
File "/Users/kiin/opt/anaconda3/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Users/kiin/opt/anaconda3/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/Users/kiin/.local/lib/python3.9/site-packages/anki_vector/__init__.py", line 22, in <module>
from . import messaging
File "/Users/kiin/.local/lib/python3.9/site-packages/anki_vector/messaging/__init__.py", line 43, in <module>
from . import client
File "/Users/kiin/.local/lib/python3.9/site-packages/anki_vector/messaging/client.py", line 23, in <module>
from .alexa_pb2_grpc import *
File "/Users/kiin/.local/lib/python3.9/site-packages/anki_vector/messaging/alexa_pb2_grpc.py", line 2, in <module>
import grpc
File "/Users/kiin/.local/lib/python3.9/site-packages/grpc/__init__.py", line 22, in <module>
from grpc import _compression
File "/Users/kiin/.local/lib/python3.9/site-packages/grpc/_compression.py", line 15, in <module>
from grpc._cython import cygrpc
ImportError: dlopen(/Users/kiin/.local/lib/python3.9/site-packages/grpc/_cython/cygrpc.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace (_CFRelease)
I've tried uninstalling and reinstalling the SDK, as well as downgrade to Python 3.8. Same errors for both.

ImportError about Numpy when using Manim

I want to try Manim.
So I installed (using pip) and created a project with the Quickstart tutorial.
RuntimeError, ImportError
But when running it, a bunch of errors show up:
RuntimeError: module compiled against API version 0xf but this version of NumPy is 0xe
Traceback (most recent call last):
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\Scripts\manim.exe\__main__.py", line 4, in <module>
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\manim\__init__.py", line 24, in <module>
from .animation.animation import *
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\manim\animation\animation.py", line 6, in <module>
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\manim\mobject\opengl\opengl_mobject.py", line 17, in <module>
from manim.utils.bezier import integer_interpolate, interpolate
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\manim\utils\bezier.py", line 28, in <module>
from scipy import linalg
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\__init__.py", line 217, in __getattr__
return _importlib.import_module(f'scipy.{name}')
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\linalg\__init__.py", line 197, in <module>
from ._misc import *
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\linalg\_misc.py", line 3, in <module>
from .blas import get_blas_funcs
File "C:\Users\mitja\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\linalg\blas.py", line 213, in <module>
from scipy.linalg import _fblas
ImportError: numpy.core.multiarray failed to import
I've already tried reinstalling/upgrading the newest version.
How do I solve this and get it running?

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

I've seen that a lot of questions have already asked this, but it seems to be very specific as none of the answers seem to work.
Let me explain the steps that I have taken to install everything:
I started with installing Python 3.7.4 and installed tensorflow after that. The command I ran is: pip install -q tensorflow=2.0.0-alpha0. This didn't seem to work and I soon figured out that this is because of the version of Python. Tensorflow doesn't support 3.7 yet, so I installed Python 3.6.0.
I then installed tensorflow again with the following command: pip3.6 install tensorflow. Note the explicit pip3.6. I then select python 3.6 in the configuration of Visual Code's Python Debugger. I ran the following code (single line) and gave me the following error:
Python
import tensorflow as tf
Output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python36\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Program Files\Python36\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Program Files\Python36\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Program Files\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Program Files\Python36\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified module could not be found.
After some searching, someone said that uninstalling tensorflow-estimator and tensorflow-gpu may work, because of unsupported gpu's. Even though I doubted this since I have an RTX 2080, I decided to give it a go, but I still got the same result.
I'm hoping any of you would be able to help me with this.
Thanks in advance!
UPDATE
After installing Anaconda and using conda to install my packages with (instead of pip) this issue has been resolved. However, a nice issue occurs. With the someline of code I get the following error (pretty much the same as the last one, but a different package module):
Traceback (most recent call last):
File "c:\Users\Meine Zeinstra\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\Meine Zeinstra\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\Meine Zeinstra\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Meine Zeinstra\Documents\Projects\Python_Neural_Networks\Tutorial_1\Tutorial_1.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\tensorflow\__init__.py", line 34, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
import numpy as np
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
I hope you can help me with this new issue.

ABI incompatibility while importing `scipy.sparse`

I'm running a script in a virtual environment on a new machine. Running the script gives me the following traceback.
Traceback:
Traceback (most recent call last):
File "zoneMapRGB.py", line 11, in <module>
from skimage import io, color
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/io/__init__.py", line 11, in <module>
from ._io import *
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/io/_io.py", line 7, in <module>
from ..color import rgb2grey
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/color/__init__.py", line 1, in <module>
from .colorconv import (convert_colorspace,
File "/opt/python/3.6/lib/python3.6/site-packages/skimage/color/colorconv.py", line 368, in <module>
rgb_from_xyz = linalg.inv(xyz_from_rgb)
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/linalg/basic.py", line 947, in inv
a1 = _asarray_validated(a, check_finite=check_finite)
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/_lib/_util.py", line 228, in _asarray_validated
import scipy.sparse
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/sparse/__init__.py", line 229, in <module>
from .csr import *
File "/opt/python/3.6/lib/python3.6/site-packages/scipy/sparse/csr.py", line 15, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: /opt/matlab/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /opt/python/3.6/lib/python3.6/site-packages/scipy/sparse/_sparsetools.cpython-36m-x86_64-linux-gnu.so)
It seems scipy is trying to get libstdc++.so.6 from a matlab folder instead of the python directory. Is there any way to correct this behavior?

How to resolve import matplotlib.pyplot as plt error?

I am having trouble getting my matplotlib library to work. I am running it on a virual environment, and I have installed numpy, and matplotlib. I first open my virtual environment, activate python, then I enter,
import matplotlib
everything goes fine, but then I enter,
import matplotlib.pyplot as plt
I get the error,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
I have tried a number of different solutions to no avail. What could be the problem?
Use the below mentioned commands:
import matplotlib
matplotlib.use(‘TkAgg’)
import matplotlib.pyplot as plt
This worked for me. I hope it helps.

Categories