I have installed tensorflow with anaconda in Windows, but I can't import tensorflow in spyder IDE?
The reason Spyder is unable to import Tensorflow is that Anaconda does not store the tensorflow package in the same environment.
One solution is to create a new separate environment in Anaconda dedicated to TensorFlow and containing Python with its own Spyder and then install tensorflow into that environment
Related
I am trying to build a ANN model using Tensorflow library on Spyder. Afte ı set my training and test data, ı imported the keras library as seen below
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
But the prcocess did not finished normally.I tookthe same error-> cannnot import name 'LayerNormalization' from 'tensorflow.python.keras.layers.normalization'
I am using the following versions Spyder 4.2.5 tensorflow 2.7
Please create a new virtual environment in ananconda to install TensorFlow:
conda create -n tf tensorflow #"tf" is the name for your TensorFlow environment
conda activate tf # to activate the virtual environment
pip install tensorflow # install tensorlfow in that environment
Select the same "tf" environment in anaconda navigator and install Spyder to launch and type below code to check if TensorFlow installed properly:
import tensorflow as tf
Now please try again executing your code in this Spyder IDE.
I'm trying to use the HeUniform() method from the keras.initializers class, bu when I go to run my code, I get the following output:
AttributeError: module 'tensorflow_core.keras.initializers' has no attribute 'HeUniform'
The code that I ran is the following:
init = tf.keras.initializers.HeUniform()
My imports are:
import gym
import tensorflow as tf
import numpy as np
from tensorflow import keras
from collections import deque
import time
import random
I'm using tensorflow version 2.0.0 installed from conda. I tried to upgrade the version, but I was getting further errors saying that version 2.2.0 and 2.4.1 does not exist for conda. Please advise.
Take a look at the tensorflow api documentation for version 2.0. There is no class tf.keras.initializers.HeUniform. Instead, there is a function tf.keras.initializers.he_uniform. You can find the source code for the function on GitHub.
TensorFlow recommends installing with pip. In the past, I have created a new conda environment specifically for tensorflow. It is bad practice to mix conda and pip packages, so that's why I create a new environment just for the specific version of tensorflow.
conda create -n tf2 python=3.8
conda activate tf2
python -m pip install --no-cache-dir tensorflow==2.4.1
Just keep in mind that the GPU versions depend on specific versions of CUDA and cuDNN. See https://www.tensorflow.org/install/source#gpu for more information about the requirements.
I installed tensorflow-gpu in anaconda3.
The steps I followed are:
conda create -n tensorflow pip python=3.6
source activate tensorflow
pip install tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl
After these steps, I find that if I use the python and ipython in anaconda3/bin, I can't import tensorflow (no module named tensorflow)
But If I activate the environment of tensorflow or I use the python and ipython in anaconda3/env/tensorflow/bin, I can import tensorflow.
And there is also no directory for tensorflow inanaconda3/lib/python3.6/site-package
Anyone knows why?
You created a conda environment and installed Tensorflow to that environment. Therefore you can only use Tensorflow inside that environment.
If you wish to use Tensorflow outside of an environment then don't activate the environment you created and just pip install Tensorflow.
I have a python script whose initial lines read
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
When I run the script it gives this error
'no module such as tensorflow.tutorials.examples.mnist'.
I have already pip installed Tensorflow, what do i do now?
From your comment I can see that you are using Anaconda. Have you tried to install it with conda install tensorflow? Also, you could try to create an environment first, and install tensorflow afterwards with conda create -n tensorflow pip python=2.7 (or 3.x depending on your system) within it.
I have installed tensorflow with anaconda successfully. There is a virtual environment named tensorflow, and I activate it.
But in Jupyter Notebook, I tried to import tensorflow, only to get an error: No module named 'tensorflow'.
NOTE: should be activate tensorflow and NOT activate tensorfow