简体   繁体   中英

tensorflow - cannot install tensorflow from Anaconda

I am trying to access tensorflow from two ways, both of which are failing:

  1. Installed Anaconda (Windows 32 bit Python 3.6). Then, created a conda environment with Python 3.6 (also tried with 3.5) and Tensorflow. Then, I opened Spyder desktop app. In this Spyder, the tensorflow is not working (eg 'import tensorflow as tf' is not working).

  2. From Anaconda Navigator, created an environment (using the GUI), with Python 3.6. Then, I filtered the "Not installed" packages, and searched for "tensorflow". I couldn't find any relevant tensorflor package. All I could find is "r-tensorflow" which is not relevant for me.

The attached image describes the 2nd problem.

Can someone help?

Screenshot of the step 2 above

Open an anaconda prompt, and create an environment with tensorflow like this:

conda create -n tf tensorflow
activate tf
# Verify that it works
python -c "import tensorflow"

Then, you probably have to specify that environment from within Spyder. Open Preferences -> Console -> Advanced Settings and set the python path to <anaconda_install>/envs/tf/bin/python .

tensorflow can be installed simply by running following commands

On mac/Windows use following command:

conda install -c conda-forge tensorflow 

This will install the latest Tensorflow on your system. if you wish to upgrade it to newer verion then you can use the following command

conda update -f -c conda-forge tensorflow

However if you have the virtual environment created from anaconda then before doing these steps you have to activate the environment first and then run the command. With this trensorflow will get installed on your specific command

Please refer the example below for more details:

Creating a environment for Tensorflow

  conda create -n “myEnv” python=3.6 anaconda

This will create virtual environment along with anaconda packages. Once this is done, Activate the Environment by :

  source activate myEnv #(for mac)
  conda activate myEnv #(for windows)

you will see the following.

激活环境

Once the Environment is active. you can now install the packages you need as follows: I am showing you the packages which i work upon on virtual environment and this will take care of most of your dependencies

conda update conda
conda upgrade conda
conda upgrade anaconda

conda install pip
conda install -c conda-forge opencv
conda install -c conda-forge tensorflow 
conda install -c conda-forge keras

Hope this will solve your problem.

Open Terminal, then enter:

conda update conda

After installing done, enter:

conda install tensorflow

It will take some time based on your internet speed.

After installing, open Anaconda -> Spyder/Jupyter

import tensorflow as ts

Let's break it down in a couple of steps:

  1. If you don't have, download and install Anaconda .

  2. Access Anaconda Command Prompt for the environment that you want to install TensorFlow . If you don't have an environment created, access the Anaconda Prompt.

  3. Assuming that you don't have an environment created, choose the name of your TensorFlow environment, such as " tensor " and install TensorFlow as following

    conda create -n tensor tensorflow
    conda activate tensor

If you want to install the GPU TensorFlow (Linux or Windows), in the environment " tensor-gpu ", use the following

conda create -n tensor-gpu tensorflow-gpu
conda activate tensor-gpu

TensorFlow is now installed. For more information access their documentation .

Try to install Spyder within the Anaconda environment in which you want to use tensorflow. This resolved the issue for me.

I had been stuck on the exact same problem for the past 4 days. I could see 'r - tensorflow' and a few other packages but not the 'tensorflow' package. Apparently, i was using the 32 - bit version of Anaconda. I searched it up and found out that Tensorflow is not supported on 32 - bit platforms. So i uninstalled the 32 - bit version and installed the 64 - bit version. I followed the same steps as before and i was able to find the 'tensorflow' package in the 'not installed' tab.

In my case I used pip instead of conda and it installed without any issue. In my opinion pip installation is much faster than conda installation.

Use

pip install tensorflow

and its done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM