Tensorflow shows errors after importing using python - python

I installed Tensorflow using pyenv. But whenever i import it gives me this error.I am using Debian in raspberry pi4.My python version is 3.7.12 and tensorflow version is 2.5.0.
''' pi#raspberrypi:~/project $ python
Python 3.7.12 (default, Mar 22 2022, 14:27:41)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
File "", line 1, in
File "/home/pi/.pyenv/versions/3.7.12/lib/python3.7/site-packages/tensorflow/init.py", line 41, in
from tensorflow.python.tools import module_util as _module_util
File "/home/pi/.pyenv/versions/3.7.12/lib/python3.7/site-packages/tensorflow/python/init.py", line 40, in
from tensorflow.python.eager import context
File "/home/pi/.pyenv/versions/3.7.12/lib/python3.7/site-packages/tensorflow/python/eager/context.py", line 37, in
from tensorflow.python.client import pywrap_tf_session
File "/home/pi/.pyenv/versions/3.7.12/lib/python3.7/site-packages/tensorflow/python/client/pywrap_tf_session.py", line 23, in
from tensorflow.python._pywrap_tf_session import *
ImportError: SystemError: <built-in method contains of dict object at 0x7f741852d0> returned a result with an error set
'''

The error message tries to say that Tensorflow needs a recent version of numpy. So,try to upgrade numpy pip3 install --upgrade numpy

Related

No module named 'mediapipe.python._framework_bindings'

I installed Docker on raspberry PI 3b. I want to configure a Python image with Mediapipe.
The basic image is demosense/raspberrypi3-opencv.
The way I installed mediapipe is
apt-get update
apt update
apt-get update
pip install mediapipe-rpi3 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
And then I realized that there was this mistake
root#ce01ec797bf6:/# python
Python 3.6.4 (default, Feb 13 2018, 04:59:47)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import mediapipe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/mediapipe/__init__.py", line 16, in <module>
from mediapipe.python import *
File "/usr/local/lib/python3.6/site-packages/mediapipe/python/__init__.py", line 17, in <module>
from mediapipe.python._framework_bindings import resource_util
ModuleNotFoundError: No module named 'mediapipe.python._framework_bindings'

Installing Python package h5py in MinGW/MSYS2 throws ImportError

I installed h5py through the package mingw64-i686-python-h5py in MSYS2. Importing it in a MinGW shell throws the following error:
Python 3.8.2 (default, Apr 9 2020, 14:12:45) [GCC 9.3.0 32 bit] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:/msys64/mingw32/lib/python3.8/site-packages/h5py/__init__.py", line 34, in <module>
from . import version
File "C:/msys64/mingw32/lib/python3.8/site-packages/h5py/version.py", line 17, in <module>
from . import h5 as _h5
File "h5py/h5.pyx", line 1, in init h5py.h5
ImportError: DLL load failed while importing defs: The specified procedure could not be found.
Reinstalling the package did not fix it. I installed numpy the same way and it works just fine.

Cycling between "No module named functools_lru_cache" and "cannot import name cbook" errors

I am completely new to Python but I enjoyed it very much. I start with Python 2.7 before migrating to Python 3 since many applications for work have to do with Python 2.7.
I have quite sadly many version of python2.7 on my MacBook. One from Apple, one from Homebrew, one from Anaconda. I have pip version 18.0 installed.
I wanted to install many modules (scipy in particular) and I ran into the following problem.
On the console:
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 20:59:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import matplotlib
I get the error message:
Traceback (most recent call last):
File "", line 1, in
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 130, in
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 28, in
from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache
I looked on the web and found the solution for that by typing:
pip install --user matplotlib
Now when I do:
>>> import matplotlib
I get the message:
Traceback (most recent call last):
File "", line 1, in
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 126, in
from . import cbook
ImportError: cannot import name cbook
There is a confusion on the web about how to solve this problem. Is there still hope I can get back running?

ImportError: DLL load failed: The specified module could not be found when importing keras

When I run
from keras.preprocessing import image
it shows the error as below.
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from keras.preprocessing import image
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python352\lib\site-packages\keras\preprocessing\image.py", line 10, i
n <module>
from scipy import linalg
File "C:\Python352\lib\site-packages\scipy\linalg\__init__.py", line 175, in <
module>
from .misc import *
File "C:\Python352\lib\site-packages\scipy\linalg\misc.py", line 5, in <module
>
from .blas import get_blas_funcs
File "C:\Python352\lib\site-packages\scipy\linalg\blas.py", line 155, in <modu
le>
from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.
>>>
I failed to install keras using pip install keras. So I download scipy and keras whl from here and install it. How can I solve my problem?
Better install Anaconda (roughly speaking a python with alot of prebuilt packages Windows-ready) https://docs.anaconda.com/anaconda/install/windows.html
then pip install -U tensorflow tensorflow-gpu keras
I was having a similar problem. My problem was solved when I uninstalled the current tensorflow version and installed tensorflow==2.0.
pip uninstall tensorflow
pip install tensorflow==2.0

sklearn/sci-py on Windows (Python 3.5) DLL errors on import

I am trying to use sklearn in Windows 7 with Python 3.5, via the pre-compiled Windows binaries at http://www.lfd.uci.edu/~gohlke/pythonlibs/
I have installed
dask-0.7.5-py2.py3-none-any.whl
scikit_learn-0.17-cp35-none-win_amd64.whl
scipy-0.16.1-cp35-none-win_amd64.whl
numpy-1.9.3+mkl-cp35-none-win_amd64.whl
pandas-0.17.1-cp35-none-win_amd64.whl
without any errors at install time. Following another SO thread with the same error, I made sure that C:/python35 is both in my Path and is set as the PYTHONPATH.
I also have Visual Studio 2013 C++ installed.
When I go to import sklearn I get this error:
C:\Users\user>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python35\lib\site-packages\sklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:\Python35\lib\site-packages\sklearn\base.py", line 9, in <module>
from scipy import sparse
File "C:\Python35\lib\site-packages\scipy\sparse\__init__.py", line 213, in <module>
from .csr import *
File "C:\Python35\lib\site-packages\scipy\sparse\csr.py", line 13, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: DLL load failed: The specified module could not be found.
Update: BrianCain's suggestion to upgrade Visual Studio C++ to version 2015 worked!

Categories