1

Background

I'm trying to work on a GAN neural network (I'm a beginner for both Python and Machine-Learning), and I need Tensorflow.

Problem

I have tried to use TensorFlow but can't install. I have read questions and answers on SO about various errors, and have tested out those solutions, but I believe this case is different.

What I have tried (in chronological order)

1. Plain Reboot

a) Close all tabs for Jupyter Notebook
b) Close Anaconda Navigator
c) Restart Jupyter Notebook
d) Rerun code

Result: ImportError: no module

2. Reinstall tf

a) Repeat 1a and 1b
b) Open Anaconda Prompt
c) pip install tensorflow

Result: module installed

3. Check out Navigator

Tensorflow installed in all environments I have.

4. Reinstall tf (Take 2)

a) Repeat 1a and 1b
b) Open Anaconda Prompt
c) conda install -c conda-forge tensorflow

Result: EnvironmentNotWritableError:The current user does not have write permissions to the target environment. environment location: C:\ProgramData\<my username>

5. Run as admin (from this question)

a) Repeat 1a and 1b
b) Open Anaconda Prompt
c) conda install -c conda-forge tensorflow

Result:

Preparing transaction: done
Verifying transaction: done
Executing transaction: <after some text> done

6. Run in Jupyter

The code has nothing to do with TF at the moment, but still, it doesn't work.

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import os
import glob2

font_lib = glob2.glob('**/*.ttf', recursive=True)

count = 0
for f in font_lib:
    count = count + 1
    if count < 10:
        print (f)
    else:
        break
print ("done")

Result:

AttributeError                            Traceback (most recent call last)
<ipython-input-6-efbffb1990be> in <module>
----> 1 import tensorflow as tf
      2 import numpy as np
      3 import matplotlib.pyplot as plt
      4 import os
      5 import glob2

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 from tensorflow._api.v1 import app

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
     80 from tensorflow.python import data
     81 from tensorflow.python import distribute
---> 82 from tensorflow.python import keras
     83 from tensorflow.python.feature_column import feature_column_lib as feature_column
     84 from tensorflow.python.layers import layers

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\__init__.py in <module>
     23 
     24 from tensorflow.python.keras import activations
---> 25 from tensorflow.python.keras import applications
     26 from tensorflow.python.keras import backend
     27 from tensorflow.python.keras import callbacks

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\applications\__init__.py in <module>
     24 from tensorflow.python.keras import backend
     25 from tensorflow.python.keras import engine
---> 26 from tensorflow.python.keras import layers
     27 from tensorflow.python.keras import models
     28 from tensorflow.python.keras import utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\__init__.py in <module>
     27 
     28 # Advanced activations.
---> 29 from tensorflow.python.keras.layers.advanced_activations import LeakyReLU
     30 from tensorflow.python.keras.layers.advanced_activations import PReLU
     31 from tensorflow.python.keras.layers.advanced_activations import ELU

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\layers\advanced_activations.py in <module>
     25 from tensorflow.python.keras.engine.base_layer import Layer
     26 from tensorflow.python.keras.engine.input_spec import InputSpec
---> 27 from tensorflow.python.keras.utils import tf_utils
     28 from tensorflow.python.ops import math_ops
     29 from tensorflow.python.util.tf_export import tf_export

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\__init__.py in <module>
     36 from tensorflow.python.keras.utils.layer_utils import get_source_inputs
     37 from tensorflow.python.keras.utils.losses_utils import squeeze_or_expand_dimensions
---> 38 from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
     39 from tensorflow.python.keras.utils.np_utils import normalize
     40 from tensorflow.python.keras.utils.np_utils import to_categorical

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\utils\multi_gpu_utils.py in <module>
     20 from tensorflow.python.framework import ops
     21 from tensorflow.python.keras import backend as K
---> 22 from tensorflow.python.keras.engine.training import Model
     23 from tensorflow.python.ops import array_ops
     24 from tensorflow.python.util.tf_export import tf_export

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in <module>
     40 from tensorflow.python.keras.engine import training_generator
     41 from tensorflow.python.keras.engine import training_utils
---> 42 from tensorflow.python.keras.engine.network import Network
     43 from tensorflow.python.keras.optimizer_v2 import optimizer_v2
     44 from tensorflow.python.keras.utils import data_utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\network.py in <module>
     38 from tensorflow.python.keras.engine import base_layer
     39 from tensorflow.python.keras.engine import base_layer_utils
---> 40 from tensorflow.python.keras.engine import saving
     41 from tensorflow.python.keras.engine import training_utils
     42 from tensorflow.python.keras.utils import generic_utils

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\saving.py in <module>
     36 # pylint: disable=g-import-not-at-top
     37 try:
---> 38   import h5py
     39   HDF5_OBJECT_HEADER_LIMIT = 64512
     40 except ImportError:

C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py in <module>
     34 _errors.silence_errors()
     35 
---> 36 from ._conv import register_converters as _register_converters
     37 _register_converters()
     38 

h5py\h5r.pxd in init h5py._conv()

h5py\h5r.pyx in init h5py.h5r()

AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__'

7. Update h5py

a) Followed @Alireza Tajadod's instructions and tried. b) Run code in Jupyter

Result: Same as 6)...


I have tried every method I could, and any help would be highly appreciated. Thank you in advance!

Edit:

Reminded by the answer by @GarytheIceBreaker: Sorry that I forgot to mention, but I have everything installed and set up in Windows. Although this might be frustrating to some, please suggest solutions that can be done within Windows OS premises. Thanks!

  • 1
    per this thread : https://github.com/h5py/h5py/issues/1151 you should reinstall a different version of h5py. "PeterJPRoche commented on Jun 10, 2019 I had h5py-2.9.0 installed and got this issue. Followed @robisen1 suggestion and installed 2.8.0 conda install h5py=2.8.0 Fixed the problem for me" – Alireza Tajadod Jan 30 '20 at 14:20
  • tried, but to no avail... thanks for the help tho! @AlirezaTajadod – Omega Krypton Jan 30 '20 at 14:34

1 Answers1

0

I tried jumping through hoops on Windows, and did get Anaconda working, but not Tensorflow. I recommend running Ubuntu virtually, on WSL if you don't want to make any major changes to your machine. Ubuntu is pretty user friendly these days, even if you use it without any graphical shell enabled.
Enable WSL, install Ubuntu from the Microsoft store, and apt-get install tensorflow.

  • Sorry that I forgot to mention, but I have everything installed and set up in Windows. Although this might be frustrating to some, please suggest solutions that can be done within Windows OS premises. Thanks! – Omega Krypton Jan 30 '20 at 14:25
  • If Windows is a real requirement, I'll have to defer, but I got used to working mostly within applications running on Windows, and then invoking code with Linux running in parallel. I like my IDEs and whatnot, and I keep them open when I hop over to the terminal running WSL to actually run my code. Running and installing Python projects tends to be less of a headache in Linux. – GaryTheIcebreaker Jan 30 '20 at 14:36