I am trying to install Tensorflow on a Windows 7 laptop in order to use jupyter notebook to play around with the object detection notebook in Github. I am facing this error:
ImportError Traceback (most recent call
last) in ()
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ImportError: No module named tensorflow
I am getting the above error when I start the Jupyter Notebook from inside the Conda environment in Windows 7. I have installed Python 3.5.4 & within conda environment, tensorflow as well.
I am also getting ... not recognized as an internal/external... for $ command while giving $ python and sometimes also for pip3 I have included several file paths in Environment Variables. Can you please suggest me what to do. I am using the Conda env as I feel I have a problem in having Windows Service Pack 1.
Make sure your Tensorflow folder is somewhere that the environment will look, such as [Python install directory]/Lib/Site-packages
If you are using Anaconda to manage your installation, be aware that it is community supported and not officially supported by Google. Google has a detailed guide on how to install Tensorflow on Windows as well as how to validate the installation. Follow their steps carefully and be aware you may need to start the process over if you miss a step.
1) Make sure you start with a clean Conda Environment for Tensorflow. You will need to specifiy Python version 3.5. You can do this by running the command,
C:> conda create -n tensorflow python=3.5
2) Once the new Conda environmnet is created, activate it. This step is commonly overlooked.
C:> activate tensorflow
(tensorflow)C:> # The Conda environment may appear before the drive letter
3) With the Tensorflow environment active, issue the pip command to install the appropriate Tensorflow version. To keep things simple, I assume you will be installing the CPU version. If you need the GPU version, refer to the Google guide since there are other things you will need to do in order to set up the NVIDIA drivers.
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Note the flags included on the pip install command.
To make sure that Tensorflow is installed properly, validate the installation. Do this by double checking that the Tensorflow Conda environment is active and starting a python console. Once the console is running type the following sample program, suggested by Google's guide.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
If you are new to Tensorflow, this code may not make sense. What it does is import the Tensorflow library, assign a variable called "hello" to a Tensorflow constant tensor. Tensorflow is a library designed to operate on Tensor data objects. The next line initiates a Tensorflow session which loads all the data objects. The final line prints the output of Session.run() on the hello constant object. If everything is set up correctly you should see
Hello, TensorFlow!
output on the console. If you don't, check to common installation issues included in Google's Tensorflow install guide.
Related
I am reading "Hands-On Machine Learning with Scikit-Learn, Keras and Tensorflow" and installed Tensorflow 2 as follows:
$ python3 -m pip install --upgrade tensorflow
In the jupyter notebook I tried to import Tensorflow as follows:
import tensorflow as tf
But then I get the following error message:
The kernel appears to have died. It will restart automatically
I know there is a bunch of StackOverflow threads about this topic. I have read them all. Some of them are old, some are new. Most of them suggest to downgrade the Tensorflow version to 1.5. But when I do that I can not use some of the methods of the Keras API (e.g. load_data() could not be found).
Is there anyone who have found a solution for that?
The second version of the textbook is all about TensorFlow version 2 so you have to use TensorFlow version 2 to use code. if there is a problem get the first version of the textbook which uses TensorFlow 1.
But I suggest learning TensorFlow 2 as it is the latest version.
if you are using anaconda Try installing TensorFlow 2 in a new environment.
To create a new environment open anaconda prompt.
conda create -n envname python=3.6
and then activate the environment
activate envname
Now try installing TensorFlow 2 and other necessary modules
and check.
If it does not work the best solution is to use google colab(colab.research.google.com/).where you can do everything online, you can even have free GPU.
I have an issue using keras backend. I set up tensorflow as the backend. I check the ./keras/keras.json, the activate.d and activate.sh to have tensorflow as backend. I also tried to force the envs variable to tensorflow.
The first time a run keras on the jupyter, it works fine. I can also import tensorflow without any bugs.
However when I use jupyter notebook now, the backend is theano.
I try to import keras on ipython and the backend is tensorflow.
I install keras, tensorflow and theano with conda.
python version : 3.6
keras : 2.0.6
tensorflow : 1.3.0
theano : 0.9
OS : win10
I try different ways to change the backend to tensorflow for jupyter notebook but it does not seem to work.
Usually, with conda, we create specific environments that are (theoretically) independent from the others.
I suggest you create a tensorflow environment using conda. Using the command prompt:
conda create -n myTensorflowEnv python=3.5
And then you activate this environment:
activate myTensorflowEnv
The name of your environment should then appear in between parentheses at the beginning of the command prompt. (In case this doesn't work, you may need to setup some vars: How to activate an Anaconda environment)
Inside this environment, you install everything you need: Tensorflow, keras and other dependencies. This process will depend on what you want, though, cpu, gpu, compilations, etc.
You should probably install jupyter in this environment as well. (And perhaps -- only if you have the terrible bug I mentioned in my comment -- uninstall the other jupyters first).
If everything goes well, you will be able to use tensorflow in this environment if you run jupyter from this environment.
I'm totally new using Python and I have to learn quickly because of my job. I have downloaded Python2.7.13 (and also the pip package. My next step was:
C:\Python27\pip install keras
And it finished saying that theano and anaconda2 were installed to and also was fine.
The problem came when I tried the following line:
C:\Python27\python
>>>from keras.models import Sequential
And I get the following message (after others that don't give error):
ImportError: No module named numpy
The fact is that I got out of python and try pip install numpy and it says that I have already have numpy installed and show me in which folder I have it. So I go to that folder and try:
C:\users\maca\anaconda2\lib\site-packages\numpy\python setup.py install
And that returns:
This is the wrong setup.py file to run
I'm totally new so I'm very lost about what my next step should be and how to fix it, 'cause I'm not familiarized with Python. I would thank any understandable help.
Thanks in advance.
It sounds like you have vanilla python installed in C:\Python27\ and Anaconda installed in C:\Users\Maca\Anaconda2. These are different. Anaconda is not an add-on to python, it is a distribution of python. Anaconda will have the math prerequisites, vanilla will not. You can install Keras on vanilla (it's hard), but it sounds like you want to use Anaconda. Then use only anaconda. Run:
activate root
You should then be using Anaconda and you can run:
pip install keras
Also, keras works on top of a backend so make sure you either have theano (pip install theano) or tensorflow.
Then, in the same console window, using Anaconda, run python and type from keras.models import Sequential. It should work.
From then on, you can access anaconda (as long as it was set up with this command enabled) with activate root. This will set python and related arguments to refer to Anaconda rather than the default C:\Python27.
EDIT: If in the future you are planning to use only anaconda, you can delete C:\Python27 from your path or even add Anaconda to it. To add anaconda to you path, look up environment variables in the start menu, go to the system environment variables, and find PATH. If you haven't uninstalled Python27 yet you'll need to remove C:\Python27\ from that path, and then you can add C:\Users\Maca\Anaconda2 anywhere (probably towards the end depending on how often you use python and how cluttered your path is).
You are already using Anaconda Python distribution so you should use conda package manager for installing keras: run conda install keras in your terminal. This will install keras and all the dependencies.
I am trying to install Tensorflow on Windows.
I have Anaconda 4.2.0. I tried running
conda create -n tensorflow python=3.5
in my command prompt. This seemed to do something, but I'm not sure what this accomplished. It created a folder within the Anaconda3 program in my username folder.
This folder is filled with the following content:
Over the summer, I used mainly Jupyter Notebooks to do my python coding. Within this environment, there is a tab marked Condas
So it looks like I should be able to switch to the Tensorflow environment. But this doesn't work when I try to switch, there is no option to change my kernel to a Tensorflow one.
I tried running
conda search tensorflow
But nothing appears.
I'm not sure what to do. I asked a few grad students in my economics research group, but they weren't sure what to do either.
My Question
How do I properly install Tensorflow on Windows?
The syntax of the command is conda create -n <name_of_new_env> <packages>. As a result, you created a clean environment named tensorflow with only Python 3.5 installed. Since conda search tensorflow returned nothing, you will have to use pip or some other method of installing the package. Since there is spotty official support for Windows, the conda-forge package (CPU only) at https://github.com/conda-forge/tensorflow-feedstock is probably the best way.
People have also reported success installing Tensorflow with docker, if you have docker set up already.
I was able to run it under the Windows 10 linux subsystem (https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
Which is basically a linux environment within windows.
The latest tensorflow version (0.12) added windows support
https://www.tensorflow.org/get_started/os_setup#pip_installation_on_windows
just run:
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
(the url is for the specific version - you will need to change it for future versions or other setups)
An Anaconda environment isolates itself completely with the outer world, so all the packages you installed outside the virtualenv is nothing in the virtualenv, if you want to use Tensorflow in the environment(seems like the only way with Anaconda), use activate tensorflow command and install the packages you want seperately.
pip provides an easy method to install tensorflow on windows machine.
use the following pip command
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
Tensorflow only support python3.5 x64 bit on windows machines and it requires that you install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow
I understand this may be an old question, but still I cannot find solution from off-the-shelf Q$A. Here is the problem:
I am following Udacity "Machine Learning" and its assignments, and need use iPythonNotebook & tensorflow. Details : https://github.com/Omarito2412/udacity-deeplearning
Assignment2 requires tensorflow. BTW, I already installed Anaconda,
already made tensorflow working on Pycharm on the same computer which is Macbook, but do not know how to make it work on iPythonNotebook environment.
The codes are quite simple, as follows:
import numpy as np
import tensorflow as tf
from six.moves import cPickle as pickle
from six.moves import range
and the error message is as follows:
ImportError Traceback (most recent call last)
<ipython-input-1-0970743dd90d> in <module>()
2 # before proceeding further.
3 import numpy as np
----> 4 import tensorflow as tf
5 from six.moves import cPickle as pickle
6 from six.moves import range
ImportError: No module named tensorflow
Thanks. Any suggestions ?
PS: I have this problem on two MacBooks, and both MacBooks run Pycharm+tensorflow well.
You should deactivate and re-activate the environment
source deactivate tensorflow
source activate tensorflow
After I tried Anaconda-installation (I was using the other installation methods, which are all shown in the link below)
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
It worked ...
Further, on terminal activate tensorflow
>>> source activate tensorflow
before open iPython Notebook
>>> ipython notebook
At last, I have to restart my macbook to make it work....
i have missed tensorflow install (3) number below the list..
now i have solved
for anaconda install
for enviroment install
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
for tensorflow install
https://github.com/conda-forge/tensorflow-feedstock
This is likely due to an anemic environment variable, one of the library path class. I don't know how iPythonNotebook denotes the libraries it will search for files (say, $LD_LIBRARY_PATH), but I believe that you have to find it (a list of paths to libraries) and add the root directory of TensorFlow.
More than likely either Tensorflow is not installed in the right Python environment of Conda or not installed at all. Follow the below steps:
$ conda create -n tensorflow python=3.5
Once that is done, need to activate that as below:
$ source activate tensorflow
Then when you open IPython Notebook or Spyder, it will recognize the Tensorflow.
Run python -m ipykernel install --user --name <Environment_Name>. This should add your environment to the jupyter kernel list.
Change the kernel using Kernel->Change Kernel option or New-><Environment_Name>.