Error when "import tensorflow as tf" in colab - tensorflow

When I "import tensorflow as tf" in google colab I am getting the following error. Any idea how to fix it ?
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-37-07e0f991eb97> in <module>()
----> 1 import tensorflow as tf
2
3 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/client/pywrap_tf_session.py in <module>()
17 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
18 from tensorflow.python import pywrap_tensorflow
---> 19 from tensorflow.python.client._pywrap_tf_session import *
20 from tensorflow.python.client._pywrap_tf_session import _TF_SetTarget
21 from tensorflow.python.client._pywrap_tf_session import _TF_SetConfig
ImportError: SystemError: <built-in method __contains__ of dict object at 0x7f79368db0a0> returned a result with an error set
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

This issue has been fixed now in 2.8.0 stable version. If it still persists ,please install Numpy 1.21.5 manually and Try again.

I've post a similar error on tensorflow github issue.
Tensorflow 2.8.0 | Error Message: ImportError: SystemError.
My solution (since I'm using conda environment on Windows 10), is to downgrade the Tensorflow version to 2.7.0. Hope help helps.

Related

import cupy error: .../nvrtc.cpython-39-x86_64-linux-gnu.so: undefined symbol: nvrtcGetNVVMSize, version libnvrtc.so.11.2

I'm using GTX2080 on Ubuntu 22.04
here's the output of nvcc --version:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0
so I installed cupy using:
pip install cupy-cuda117
However, when I run import cupy it returns an import error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
File ~/anaconda3/lib/python3.9/site-packages/cupy/__init__.py:18, in <module>
17 try:
---> 18 from cupy import _core # NOQA
19 except ImportError as e:
File ~/anaconda3/lib/python3.9/site-packages/cupy/_core/__init__.py:1, in <module>
----> 1 from cupy._core import core # NOQA
2 from cupy._core import fusion # NOQA
File cupy/_core/core.pyx:1, in init cupy._core.core()
File ~/anaconda3/lib/python3.9/site-packages/cupy/cuda/__init__.py:8, in <module>
7 from cupy._environment import get_hipcc_path # NOQA
----> 8 from cupy.cuda import compiler # NOQA
9 from cupy.cuda import device # NOQA
File ~/anaconda3/lib/python3.9/site-packages/cupy/cuda/compiler.py:18, in <module>
17 from cupy_backends.cuda.api import runtime
---> 18 from cupy_backends.cuda.libs import nvrtc
19 from cupy import _util
ImportError: /home/sam/anaconda3/lib/python3.9/site-packages/cupy_backends/cuda/libs/nvrtc.cpython-39-x86_64-linux-gnu.so: undefined symbol: nvrtcGetNVVMSize, version libnvrtc.so.11.2
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import cupy
File ~/anaconda3/lib/python3.9/site-packages/cupy/__init__.py:20, in <module>
18 from cupy import _core # NOQA
19 except ImportError as e:
---> 20 raise ImportError(f'''
21 ================================================================
22 {_environment._diagnose_import_error()}
23
24 Original error:
25 {type(e).__name__}: {e}
26 ================================================================
27 ''') from e
30 from cupy import cuda # NOQA
31 # Do not make `cupy.cupyx` available because it is confusing.
ImportError:
================================================================
Failed to import CuPy.
If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.
On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm.
On Windows, try setting CUDA_PATH environment variable.
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
Original error:
ImportError: /home/sam/anaconda3/lib/python3.9/site-packages/cupy_backends/cuda/libs/nvrtc.cpython-39-x86_64-linux-gnu.so: undefined symbol: nvrtcGetNVVMSize, version libnvrtc.so.11.2
================================================================
it says "On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm." I've edit the .bashrc file to include the path of cuda:
export PATH="/usr/local/cuda-11.7/bin:$PATH"
export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
but still no luck, same import error. I tried reboot but same result... Thanks for any help!

Dropbox ModuleNotFoundError: No module named 'stone'

Im trying to import Dropbox with the line:
import dropbox
on Google Colab but im getting the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-26-fac67f6fa745> in <module>()
28 import math
29 import io
---> 30 import dropbox
31 from keras.models import Sequential
32 from keras.layers import Dense
2 frames
/usr/local/lib/python3.6/dist-packages/dropbox/auth.py in <module>()
5 # pylint: skip-file
6 from __future__ import unicode_literals
----> 7 from stone.backends.python_rsrc import stone_base as bb
8 from stone.backends.python_rsrc import stone_validators as bv
9
ModuleNotFoundError: No module named 'stone'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
It was working perfectly normal a day ago
The problem is that a new release of Dropbox API was out today and it has that glitch. Just used the version before today by using
pip install dropbox==10.10.0

CuPy on AMD GPU causing an ImportError

I'm trying to use/test the (experimental) AMD GPU support of CuPy (8.1.0). In short: I'm having an ImportError.
I followed the instructions for installing ROCm on a Ubuntu focal machine (with a gfx906/Radeon VII (Vega 20) card).
From the doc I set the mentioned variables (with adjusted HCC_AMDGPU_TARGET), the ROCM_HOME and export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin.
pip3 install -v --no-cache-dir cupy succeeded without any complaints. Just a few compiler notes and warnings because of the -v option
Now when I try to import cupy it's throwing an ImportError.
In [1]: import cupy
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/cupy/__init__.py in <module>
19 message='can\'t resolve package from __spec__')
---> 20 from cupy import core # NOQA
21 except ImportError as e:
/usr/local/lib/python3.8/dist-packages/cupy/core/__init__.py in <module>
----> 1 from cupy.core import core # NOQA
2 from cupy.core import internal # NOQA
3
cupy/core/core.pyx in init cupy.core.core()
cupy/core/_routines_manipulation.pyx in init cupy.core._routines_manipulation()
cupy/core/_routines_indexing.pyx in init cupy.core._routines_indexing()
cupy/core/_routines_math.pyx in init cupy.core._routines_math()
cupy/core/_reduction.pyx in init cupy.core._reduction()
cupy/core/_cub_reduction.pyx in init cupy.core._cub_reduction()
ModuleNotFoundError: No module named 'cupy.cuda.cub'
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last)
<ipython-input-1-329ec5cf1bc8> in <module>
----> 1 import cupy
/usr/local/lib/python3.8/dist-packages/cupy/__init__.py in <module>
39 original error: {}'''.format(_exc_info[1])) # NOQA
40
---> 41 raise ImportError(_msg) from e
42
43
ImportError: CuPy is not correctly installed.
If you are using wheel distribution (cupy-cudaXX), make sure that the version of CuPy you installed matches with the version of CUDA on your host.
Also, confirm that only one CuPy package is installed:
$ pip freeze
If you are building CuPy from source, please check your environment, uninstall CuPy and reinstall it with:
$ pip install cupy --no-cache-dir -vvvv
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
original error: No module named 'cupy.cuda.cub'
What should I do next? What should I look for in the compilation process? Thanks in advance
EDIT On request here the complete stdout and stderr of the installation process and a few io's of the console: https://seafile.cloud.uni-hannover.de/d/68862cd1057e47d180aa/
To summarize the discussion in the comments so far:
For CuPy v8.x (the latest stable releases): Up to v8.1 the offending cupy.cuda.cub module is not built in ROCm/HIP environments, which will hopefully be fixed in v8.2 (see ticket).
For CuPy v9.x (the master branch): It should just work as long as rocPRIM and hipCUB are correctly installed. It's likely that the OP's local environment is not correctly set up, leading to cupy.cuda.cub module not built and thus ImportError.

Keras Import Error Tensorflow backend

---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in <module>()
4 try:
----> 5 from tensorflow.python.ops import ctc_ops as ctc
6 except ImportError:
ImportError: cannot import name 'ctc_ops'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-10-c74e2bd4ca71> in <module>()
----> 1 import keras
/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/__init__.py in <module>()
1 from __future__ import absolute_import
----> 2 from . import backend
3 from . import datasets
4 from . import engine
5 from . import layers
/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/backend/__init__.py in <module>()
67 elif _BACKEND == 'tensorflow':
68 sys.stderr.write('Using TensorFlow backend.\n')
---> 69 from .tensorflow_backend import *
70 else:
71 raise Exception('Unknown backend: ' + str(_BACKEND))
/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in <module>()
5 from tensorflow.python.ops import ctc_ops as ctc
6 except ImportError:
----> 7 import tensorflow.contrib.ctc as ctc
8
9 import numpy as np
ImportError: No module named 'tensorflow.contrib.ctc'
Seems like is an problem with Keras and not Tensorflow according to this post enter link description here
I was wondering if this has been fixed yet?
This is a problem between Keras and tensorflow. You should change this fix to use something like
if hasattr(tf.contrib, 'ctc'):
ctc = tf.contrib.ctc # old version
else:
ctc = tf.nn # New official version.
The current "official" way to access the ctc operations are in tf.nn, for instance, tf.nn.ctc_loss.
If keras is giving an import problem and you are facing "no module named keras" even if you have installed it.
Just upgrade your pip by:
python -m pip install –upgrade pip
Re-install upgraded keras and tensorflow by:
pip install keras
pip install tensorflow
Hope it will solve the problem. If not, try upgrading your conda (Anaconda) and then do steps 1 to 3 above again.

Tensorflow importing error in Jupyter notebook

So I managed all other packages (such as cv2, pandas, matplotlib..) work well in the default kernel or Python 3 kernel, except Tensorflow.
Tensorflow does not import with Kernel: "Python 3" or "Python default".
import tensorflow as tf
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-41389fad42b5> in <module>()
----> 1 import tensorflow as tf
ImportError: No module named tensorflow
When I choose "env: tensorflow" kernel, my other packages such as pandas, cv2 all collapse. Thus, I try to use "default" kernel or "Python 3" kernel.
Thanks a lot.
You haven't loaded the tensorflow kernel, please follow instructions here.