5

I've been working on learning artificial intelligence and how to code with Python.I was working on a project and I decided to update some packages of Python which were not new to work on then something happened and I can't compile my codes.I deleted Anaconda3 and set it up again but not worked. I've been seeing this problem which I wrote as a topic.If someone helps me,I would be appriciated to get some help.

>>> import tensorflow as tf
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\python\__init__.py", line 63, in <module>
    from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\python\framework\framework_lib.py", line 104, in <module>
    from tensorflow.python.framework.importer import import_graph_def
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\python\framework\importer.py", line 32, in <module>
    from tensorflow.python.framework import function
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\python\framework\function.py", line 36, in <module>
    from tensorflow.python.ops import resource_variable_ops
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 35, in <module>
    from tensorflow.python.ops import variables
  File "C:\Users\AliGalip\Anaconda3Yeni\lib\site-packages\tensorflow\python\ops\variables.py", line 40, in <module>
    class Variable(checkpointable.CheckpointableBase):
AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'
fuglede
  • 17,388
  • 2
  • 54
  • 99
Ali Galip
  • 63
  • 1
  • 1
  • 6

3 Answers3

3

The same question has been posted as a GitHub issue. In particular, the solution suggested by @allanlavoie is likely relevant here as well:

Sounds like a half-updated version of TensorFlow. Could you try removing TensorFlow entirely (e.g. pip uninstall tf-nightly or whichever package is installed), making sure import tensorflow fails, then reinstalling?

Since it is apparent from your question that you're using Anaconda to manage your Python environments, if the above fails to solve your problem, you can try to install TensorFlow in a clean conda environment as follows:

  1. Create a new environment through conda create --name tftest. (You can replace tftest with e.g. the name of your current project.)
  2. Activate that new environment through activate tftest (or source activate tftest if you happen to be using MSYS2's bash, or something similar to that).
  3. Install TF into this environment through conda install tensorflow.
  4. Ensure that you're in the right environment through where python (which should produce a path containing "tftest").
  5. Run Python through python.
  6. import tensorflow as tf in a shell in that environment.

Since you are using PyCharm (cf. the comments for this answer), you will then want to set up PyCharm for using this new environment instead. Indeed, using a new environment for every project, while disk space-intensive, is a good way of avoiding dependency issues for these rather dependency-heavy numerical packages.

fuglede
  • 17,388
  • 2
  • 54
  • 99
  • Not worked,neither unfortunately. By the way,I didn't make it to run "pip uninstall tf-nightly" .I used instuctions from tensorflow.org but it didn't work again. Still getting the same problem after all. I'm still looking for an answer,guys. – Ali Galip Jul 18 '18 at 20:07
  • 1
    @AliGalip: What happens if you 1) create a new environment through `conda create --name tftest`, 2) activate that through `activate tftest`, 3) install TF through `conda install tensorflow`, 4) ensure that you're in the right environment through `where python`, 5) run Python through `python`, and 6) `import tensorflor as tf` in a shell in that environment? – fuglede Jul 19 '18 at 12:25
  • 1
    IT WORKS!! I need to add something for people who might get the same error as I had. All the instructions which @fuglede wrote orderly.After I finished that,I opened Pycharm Community Edition but again I got error.All the things you need to do after doing what he says above,open Settings on Pycharm and re-configure your interpreter (Add Local:Anaconda/envs/tftest/python.exe) .Then,when I tried to compile my code I got two more errors. You need to get "nose" and "matplotlib" packages from Settings/Project Interpreter on Pycharm and it works! Thanks again @fuglede! – Ali Galip Jul 19 '18 at 22:15
  • @AliGalip: Great, good to hear; let me add my own, as well as your remarks, to the answer itself for ease of reference. The packages related to numerical computation are huge and with complicated inter-dependencies, so you may find useful a workflow that revolves around creating a new environment every time you start a new project. This has the added benefit of speeding up the infamous "indexing packages" process that PyCharm runs. – fuglede Jul 20 '18 at 07:47
0

This is error may be dues to the version of the tensorflow, your code is not compatible with the latest version of the tensor flow. Try installing older version of Tensorflow such as 1.14.0 or 1.7.0 it worked for me.

0
pip3 uninstall tensorflow

And then:

pip3 install --upgrade "tensorflow==1.15"
Rexcirus
  • 2,459
  • 3
  • 22
  • 42