To learn about Deep Learning and Neural Networks, I am trying to install Tensorflow on my laptop (Dell Inspiron 5559, 4GB RAM, Windows 10), using conda 4.9.1
(which initially contains Python 3.8.3
). For this, I used the following command:
conda create -n tf tensorflow
This ran successfully and it installed Python 3.7.9
, tensorflow 2.1.0
and a lot of other modules. Now I want to test whether it works or not, so in Python terminal, imported some modules. Import was successful for math
and numpy
. But when I import tensorflow, the process fails with the following:
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 101, in
<module> from tensorflow_core import *
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow_core\__init__.py", line 40, in
<module> from tensorflow.python.tools import module_util as _module_util
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 959, in _find_and_load_unlocked
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 50, in
__getattr__ module = self._load()
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "D:\Program Files\Anaconda3\envs\tf\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "D:\Program Files\Anaconda3\envs\tf\lib\site-packages\tensorflow_core\python\__init__.py", line
49, in <module> from tensorflow.python import pywrap_tensorflow
File "D:\Program Files\Anaconda3\envs\tf\lib\site-
packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\Program Files\Anaconda3\envs\tf\lib\site-
packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\Program Files\Anaconda3\envs\tf\lib\site-
packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 15, in swig_import_helper
import imp
ValueError: source code string cannot contain null bytes
This error occurs even if I run a program importing Tensorflow.
I checked most other tutorials and it seemed that nobody faced this error. I also tried using using lower versions of Python and Tensorflow but the same error occurs.
Can anyone find what is happening, and what should I do?
I believe your issue is that you installed tensorflow
with conda, the conda build has some issues, try running the pip call in your conda env
conda remove tensorflow
then run
pip install --upgrade pip
pip install tensorflow
I tried with pip and pip3 and still the same problem occurred.
recreate your env and DONT use pip3, just pip to install
Tried earlier with pip, no difference.
Though my problem hasn't been still solved, but I marking it as answer due to more comments and because of bounty.