import torch error in google Colaboratory - pytorch

I get the following error on google colaboratory.
ImportErrorTraceback (most recent call last)
in ()
----> 1 import torch
/usr/local/lib/python3.6/site-packages/torch/init.py in ()
54 except ImportError:
55 pass
---> 56 from torch._C import *
57
58 all += [name for name in dir(_C)
ImportError: No module named _C
I tried importing from a different directory. But, still get the same error. Any help?

Try restarting runtime. Colab sometimes gives errors like this :P

Generally that suggests you are in a dir called torch. See this.

Related

while attempting to import module of sklearn in Jupiter notebook as well as in PYCHARM, i continuously get following error

i have installed scikit-learn using pip command, however while trying to import module of sklearn in Jupiter notebook as well as in PYCHARM, i continuously get following error. I am working in python3.9. I am new to the interface, so it is requested to suggest solution for this issue.
ImportError Traceback (most recent call last)
in
----> 1 import sklearn.linear_model as lm
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/init.py in
79 # it and importing it first would fail if the OpenMP dll cannot be found.
80 from . import _distributor_init # noqa: F401
---> 81 from . import __check_build # noqa: F401
82 from .base import clone
83 from .utils._show_versions import show_versions
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/init.py in
44 from ._check_build import check_build # noqa
45 except ImportError as e:
---> 46 raise_build_error(e)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/init.py in raise_build_error(e)
29 else:
30 dir_content.append(filename + '\n')
---> 31 raise ImportError("""%s
32 ___________________________________________________________________________
33 Contents of %s:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/_check_build.cpython-39-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/../.dylibs/libomp.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build/../.dylibs/libomp.dylib
Contents of /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sklearn/__check_build:
init.py pycache _check_build.cpython-39-darwin.so
setup.py
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform
thanks
As you can see in this bug report, the new sklearn version 0.24 crashes on MacOS<10.15 systems.
Until this bug is fixed, the developers suggest installing the previous version using pip install -U scikit-learn==0.23.

TensorFlow ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found

System specifications:
Python==3.8.5
tensorflow==2.3.1
I am trying to import tensorflow... but I am getting import error. Please help me rectify the problem. I tried following...
pip uninstall tensorflow
and
pip install tensorflow
When I execute pip freeze I see the installed tensorflow package with specified version.
Error Message:
ImportError Traceback (most recent call last)
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
63 try:
---> 64 from tensorflow.python._pywrap_tensorflow_internal import *
65 # This try catch logic is because there is no bazel equivalent for py_extension.
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-d6579f534729> in <module>
----> 1 import tensorflow
~\anaconda3\lib\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
~\anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
39
---> 40 from tensorflow.python.eager import context
41
42 # pylint: enable=wildcard-import
~\anaconda3\lib\site-packages\tensorflow\python\eager\context.py in <module>
33 from tensorflow.core.protobuf import config_pb2
34 from tensorflow.core.protobuf import rewriter_config_pb2
---> 35 from tensorflow.python import pywrap_tfe
36 from tensorflow.python import tf2
37 from tensorflow.python.client import pywrap_tf_session
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py in <module>
26
27 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
---> 28 from tensorflow.python import pywrap_tensorflow
29 from tensorflow.python._pywrap_tfe import *
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
81 for some common reasons and solutions. Include the entire stack trace
82 above this error message when asking for help.""" % traceback.format_exc()
---> 83 raise ImportError(msg)
84
85 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
ImportError: Traceback (most recent call last):
File "C:\Users\user\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.```
Use Anaconda to install Tensorflow,
Create separate environment for Tensorflow with Python 3.8
conda create --name tf python=3.8 tensorflow
conda activate tf
I accidentally deleted this file. Uninstalling TensorFlow like pip uninstall tensorflow==2.3.0 and installing it again pip install tensorflow==2.3.0 resolved the issue. Dont forget to restart the kernal
Adding my workaround/hack (TF 2.5.0), in case it helps someone:
In my case I already had a dozen of Visual C++ Redistributables installed ('05, '08, ... all the way to 2017) - but TF was still failing with the infamous ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found error. I didn't want to download and install another redistributable, just to get TF working. (Besides, I had already run into several posts, enough to raise doubt whether installing it would actually resolve the problem.)
According to this SO post, the offending failing _pywrap_tensorflow_internal.pyd is just another DLL; so I
downloaded (just 468 KB) and ran Dependency Walker to detect which DLLs were requested by above PYD.
in addition to the commonly mentioned vcruntime140.dll, the PYD was also depending on a vcruntime140_1.dll.
vcruntime140.dll was available in C:/Windows/System32/ (checked using where vcruntime140.dll), but not vcruntime140_1.dll; so I ran a search on my system partition C: and found several copies of vcruntime140_1.dll at other places, mainly in my home dir's AppData/Local/ (user-installed apps).
Almost all these apps were "trusted" ones (WhatsApp, MS Teams, ...) so I just copied vcruntime140_1.dll from one of them into C:/Windows/System32/ - and the error went away.
So if you get this error even when all documented requirements are fulfilled, do a bit of debugging to find the cause of the error. It will probably save you a good deal of frustration and wasted bandwidth.

Why do I get "No module named Object detection" in Google colab?

I am trying to do object detection using tensor flow in google colab but everytime I run the following code
%run model_builder_test.py
I get this error
ModuleNotFoundError Traceback (most recent call last)
/content/drive2/My Drive/object_detection/builders/model_builder_test.py in <module>()
21
22 from google.protobuf import text_format
---> 23 from object_detection.builders import model_builder
24 from object_detection.meta_architectures import faster_rcnn_meta_arch
25 from object_detection.meta_architectures import rfcn_meta_arch
ModuleNotFoundError: No module named 'object_detection'
I have setup the python path as they said but still keep getting this error.I will give you link to my program below
https://colab.research.google.com/drive/1iko-bEUfxLimtbGqCmrypRyEzaWzE3vu?usp=sharing
Please help
%set_env PYTHONPATH=$PYTHONPATH:/content/models/research:/content/models/research/slim:/content/models
import os
os.environ['PYTHONPATH'] += ':/kaggle/working/models/research/:/kaggle/working/models/research/slim/'

ImportError: No module named 'sklearn.__check_build._check_build'

ModuleNotFoundError Traceback (most recent call last)
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build\__init__.py in <module>()
43 try:
---> 44 from ._check_build import check_build # noqa
45 except ImportError as e:
ModuleNotFoundError: No module named
'sklearn.__check_build._check_build'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-f14d678f34eb> in <module>()
1 from keras.models import Sequential
2 from keras.layers import Dense, Dropout
----> 3 from sklearn.model_selection import train_test_split
4 import numpy
5 import pandas as pd
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__init__.py in <module>()
61 # process, as it may not be compiled yet
62 else:
---> 63 from . import __check_build
64 from .base import clone
65 from .utils._show_versions import show_versions
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build\__init__.py in <module>()
44 from ._check_build import check_build # noqa
45 except ImportError as e:
---> 46 raise_build_error(e)
~\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build\__init__.py in raise_build_error(e)
39 to build the package before using it: run `python setup.py install` or
40 `make` in the source directory.
---> 41 %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
42
43 try:
ImportError: No module named 'sklearn.__check_build._check_build'
Contents of C:\Users\owaisaaa\AppData\Roaming\Python\Python36\site-packages\sklearn\__check_build:
setup.py _check_build.cp36-win32.pyd__init__.py
__pycache__
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
I recently used the pycharm on the same machine and downloaded the packages in it. From that moment onward I am getting the above mentioned error in my jupyter notebook.
Try installing scipy and restarting python shell
Upgrading scikit-learn worked for me:
$ pip install --upgrade scikit-learn

How to fix 'cannot initialize type TensorProto DataType' error while importing torch?

I installed pytorch using pip3 command for my windows pc without GPU support.
But when I tried to import torch it is giving an error.
At first, there was a different error saying numpy version not matching and I updated the numpy to the latest version.
import torch
RuntimeError Traceback (most recent call last)
<ipython-input-10-c031d3dd82fc> in <module>()
----> 1 import torch
C:\Users\iamuraptha\Anaconda3\lib\site-packages\torch\__init__.py in <module>()
82 pass
83
---> 84 from torch._C import *
85
86 __all__ += [name for name in dir(_C)
RuntimeError: generic_type: cannot initialize type "TensorProtoDataType": an object with that name is already defined
I reinstalled anaconda and then created a virtual environment for pytorch.Now everything works fine
If you are running this in colab, remember to restart your runtime after installing your modules with pip.

Resources