NameError: name 'core' is not defined - tensorflow

I'm following the turtorial https://www.tensorflow.org/install/install_windows, But when I try to import tensorflow, it comes with an error:
Traceback (most recent call last):
File "", line 1, in
import tensorflow as tf
File "D:\Python 3.5.3\lib\site-packages\tensorflow__init__.py", line 51, in
del core
NameError: name 'core' is not defined
The tensorflow installation command is
pip3 install --upgrade tensorflow
The full code is here
>
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
The python version is 3.5.3 by the way
Is there any way to solve this problem? Thanks in advance.

I have solved this problem by unticking the option 'Precompile standard library' while installing Python.

pip uninstall tensorflow
pip install tensorflow
solved the issue for me

Related

Tensorflow protobuf incompatibility

I could not get the tensorflow Variables to work because of protobuf incompatibility. Appreciate if someone can suggest how to fix it.
The following is the error:
$ python a.py
Traceback (most recent call last):
File "a.py", line 20, in <module>
a = tf.Variable(tf.zeros(2))
File "/opt/miniconda3/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/opt/miniconda3/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 177, in _variable_handle_from_shape_and_dtype
handle_data.shape_and_type.append(
AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute 'append'
(base) kanduru#SJC-L-00060215:/mnt/c/Users/kanduru/Documents/Courses/MIT/skunk/Auto-Surprise$
and the code is
import tensorflow as tf
a = tf.Variable(tf.zeros(2))
$ pip list | grep tensorflow
tensorflow 2.7.0
tensorflow-estimator 2.7.0
$ pip list | grep protobuf
protobuf 4.21.1
There could be an issue with the TensorFlow installation or TensorFlow version compatibility with existing libraries. protobuf gets installed itself with its specific version compatible to Tensorflow version while installing TensorFlow.
Could you please try again by upgrading the TensorFlow version to the latest version using the code below:
pip install --upgrade pip
pip install --upgrade tensorflow #or
pip install tensorflow==2.10
Please have a look at this Tensorflow install guide for more details.
Let us know if the issue still persists. Thank you.

ModuleNotFoundError: No module named 'absl'

I followed instructions (https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html) to install the Tensorflow Object Detection API. I use Anaconda on ubuntu18.4 and all of the steps in the instructions seemed to complete OK.
When I train to train my model with the following command:
python model_main_tf2.py --model_dir=models/my_ssd_resnet50_v1_fpn --pipeline_config_path=models/my_ssd_resnet50_v1_fpn/pipeline.config
I get the following error:
Traceback (most recent call last):
File "model_main_tf2.py", line 31, in <module>
from absl import flags
ModuleNotFoundError: No module named 'absl'
I get the error mentioned in the headline. I would be very thankful if someone could help me with a code example to solve the problem.
You need the absl package; to install it, use either one of the following:
pip install absl-py
or if you are in a Conda environment:
conda install -c anaconda absl-py

No module named 'tensorflow.contrib' while importing tflearn

While I was importing tflearn I'm getting this error:-
import tflearn
Traceback (most recent call last):
File "", line 1, in
File "/Users/rohansethi/anaconda3/lib/python3.7/site-packages/tflearn/init.py", line 4, in
from . import config
File "/Users/rohansethi/anaconda3/lib/python3.7/site-packages/tflearn/config.py", line 5, in
from .variables import variable
File "/Users/rohansethi/anaconda3/lib/python3.7/site-packages/tflearn/variables.py", line 7, in
from tensorflow.contrib.framework.python.ops import add_arg_scope as contrib_add_arg_scope
ModuleNotFoundError: No module named 'tensorflow.contrib'
You need to use an older version of TensorFlow.
tensorflow.contrib
Was removed from tensorflow with versions >=1.14.
This is what you can do:
pip uninstall tensorflow
pip install tensorflow==1.14
To check if everything is working fine:
Start python in the console by typing python Then:
import tensorflow
tensorflow.__version__
It should show you 1.14.
Now you can run your program.

Tensorflow Image Retraining Tutorial Bazel Error

I am following the Tensorflow image retraining tutorial located here.
When I try to run this command using bazel:
bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir ~/flower_photos
I get the following error:
Traceback (most recent call last):
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 108, in <module>
import tensorflow as tf
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 63, in <module>
from tensorflow.python.framework.framework_lib import *
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/framework_lib.py", line 76, in <module>
from tensorflow.python.framework.ops import Graph
File "/home/j/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/ops.py", line 28, in <module>
from autograd import core as ag_core
ModuleNotFoundError: No module named 'autograd'
However, when I run it using the python command
python tensorflow/examples/image_retraining/retrain.py --image_dir ~/flower_photos
It runs correctly and does not generate this error.
I am running both of the above commands from the ~/tensorflow directory (the top of the git repo)
Environment:
Ubuntu 17.04
Python 3.6.1
Anaconda 4.4.0
Bazel 0.5.4
Tensorflow 1.3 (no GPU) (v1.3.0-rc2-20-g0787eee 1.3.0)
I solved this issue. The autograd dependency was not installed. This can be solved by running pip install autograd
You have to configure TensorFlow before compiling, so it set up all the dependencies: ./configure

Tensorflow error in Jupyter notebook

After having installed tensorflow on Ubuntu 16.0 on AWS,
by using :
conda install -c conda-forge tensorflow=1.2.1
When typing on terminal SSH :
ipython
import tensorflow as tf
tf.__version__
It returns 1.2.1 and everything is fine.
But, when this code is run on Jupyter Ipython notebook
launched from same python install (anaconda),
I got this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-b6f7b46cc0dd> in <module>()
1 import tensorflow as tf
----> 2 tf.__version__
AttributeError: module 'tensorflow' has no attribute '__version__'
Don't understand how this error can come over since the python distribution
is the same.
Is there a way to check the install of Tensorflow ?
EDIT:
This post https://github.com/tensorflow/tensorflow/issues/3369
shows it might be related to sudo access to some folders.... when installed.
TBD