简体   繁体   English

无法使用 pip 或 anaconda 安装 tensorflow

[英]Can't install tensorflow with pip or anaconda

Does anyone know how to properly install tensorflow on Windows?有谁知道如何在 Windows 上正确安装 tensorflow?

I'm currently using Python 3.7 (also tried with 3.6) and every time I get the same "Could not find a version that satisfies the requirement tensorflow-gpu (from versions: ) No matching distribution found for tensorflow-gpu" error我目前正在使用 Python 3.7(也尝试过 3.6)并且每次我得到相同的“找不到满足 tensorflow-gpu 要求的版本(来自版本:)没有找到与 tensorflow-gpu 匹配的分布”错误

I tried installing using pip and anaconda, both don't work for me.我尝试使用 pip 和 anaconda 进行安装,两者都不适合我。


Found a solution, seems like Tensorflow doesn't support versions of python after 3.6.4.找到了解决方案,貌似Tensorflow 不支持3.6.4 之后的python 版本。 This is the version I'm currently using and it works.这是我目前使用的版本,它可以工作。

Tensorflow or Tensorflow-gpu is supported only for 3.5.X versions of Python. TensorflowTensorflow-gpu仅支持 3.5.X 版本的 Python。 Try installing with any Python 3.5.X version.尝试使用任何 Python 3.5.X 版本进行安装。 This should fix your problem.这应该可以解决您的问题。

  • Check whether you have a CPU or GPU, if your system doesn't have GPU, then it will generate error.检查你是否有 CPU 或 GPU,如果你的系统没有 GPU,那么它会产生错误。

  • If you are going to install tensorflow using Windows command prompt (assuming python is already installed), then just run the following command.如果您打算使用 Windows 命令提示符安装 tensorflow(假设已经安装了 python),那么只需运行以下命令。 Go to the root directory, preferably 'C:' drive then run转到根目录,最好是“C:”驱动器,然后运行

    • For GPU- pip3 install --upgrade tensorflow-gpu对于 GPU pip3 install --upgrade tensorflow-gpu

    • For CPU- pip3 install --upgrade tensorflow对于 CPU- pip3 install --upgrade tensorflow

  • If you are using Anaconda, then open Anaconda Navigator->Environments->Select 'All' from the drop down menu and then search TensorFlow.如果您使用的是 Anaconda,则打开 Anaconda Navigator->Environments->从下拉菜单中选择“All”,然后搜索 TensorFlow。 If you are using CPU, then select 'tensorflow', else for GPU select 'tensorflow-gpu'.如果您使用 CPU,则选择“tensorflow”,否则为 GPU 选择“tensorflow-gpu”。 Then click Apply.然后单击应用。

Screenshot of Anaconda Navigator-In case you are not familiar where to look. Anaconda Navigator 的屏幕截图 - 如果您不熟悉在哪里查看。

Unfortunately, tensorflow can't installed correctly on python 3.7 and last version of anaconda: so, the best and effective way to do this is to downgrade your python to python 3.6.7 use the next steps: 1- download the latest version of Anaconda use Anaconda prompt with administrator privilege 2- conda install python=3.6.7 (need a long time) 3-conda install tensorflow 4- conda install keras 5- conda install numpy不幸的是,tensorflow 无法在 python 3.7 和最新版本的 anaconda 上正确安装:因此,最好且有效的方法是将您的 python 降级到 python 3.6.7 使用以下步骤: 1- 下载最新版本的 Anaconda使用具有管理员权限的 Anaconda 提示符2- conda install python=3.6.7 (需要很长时间) 3-conda install tensorflow 4- conda install keras 5- conda install numpy

在此处输入图片说明

Here is what i did to get tensorflow working with windows.这是我为使 tensorflow 与 Windows 一起工作所做的工作。

Download python 3.7.0 (64 bit from Python Releases for Windows) Install it and check python version by running below command in cmd:下载 python 3.7.0(来自 Windows 的 Python 版本的 64 位)安装它并通过在 cmd 中运行以下命令来检查 python 版本:

python --version

Python 3.7.0蟒蛇 3.7.0

Then run below command to upgrade pip to latest然后运行以下命令将pip升级到最新

python -m pip install --upgrade pip

Now install tensorflow using pip现在使用 pip 安装 tensorflow

pip install tensorflow

That's it you have installed tensorflow on windows.就是这样,您已经在 Windows 上安装了 tensorflow。 Below image shows what happens when you type above commands下图显示了当您键入上述命令时会发生什么

link for tensorflow for python 3x python 3x tensorflow的链接

https://pypi.org/project/tensorflow/#files https://pypi.org/project/tensorflow/#files

tensorflow-1.14.0-cp37-cp37m-win_amd64.whl (68.3 MB) tensorflow-1.14.0-cp37-cp37m-win_amd64.whl (68.3 MB)

  1. Download the latest version of anaconda from here I'm using Anaconda 2019.03 for Windows Installer, Python 3.7, 64-bit这里下载最新版本的 anaconda 我正在使用 Anaconda 2019.03 for Windows Installer, Python 3.7, 64-bit
  2. Upgrade pip as:将 pip 升级为:

    python -m pip install --upgrade pip python -m pip install --upgrade pip

  3. (a). (一种)。 Install tensorflow using pip3 as:使用 pip3 安装 tensorflow 为:

    pip3 install --user --upgrade tensorflow pip3 install --user --upgrade tensorflow

    (b). (b)。 If you installed anaconda with all users mode.如果您在所有用户模式下安装了 anaconda。 The above command will become:上面的命令会变成:

    pip3 install --upgrade tensorflow pip3 install --upgrade tensorflow

  4. Check installation success as:检查安装成功为:

    python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))" python -c“将tensorflow导入为tf;打印(tf.reduce_sum(tf.random.normal([1000,1000])))”

As of Feb 2020, Tensorflow is not supported for Python 3.8+截至 2020 年 2 月,Python 3.8+ 不支持 Tensorflow

To make it work install a virtualenv w/ Python 3.7 from here: https://www.python.org/downloads/windows/为了使它工作,从这里安装一个带有 Python 3.7 的 virtualenv: https : //www.python.org/downloads/windows/

Tensorflow pip installation for python version 3.5-3.8 requires pip 19.0 or later, as mentioned in the official tensorflow documentation . python版本3.5-3.8的Tensorflow pip安装需要pip 19.0或更高版本,如官方tensorflow文档中所述

Here is a part of this documentation:这是文档的一部分

System requirements系统要求

  • Python 3.5–3.8 Python 3.5–3.8

    Python 3.8 support requires TensorFlow 2.2 or later. Python 3.8 支持需要 TensorFlow 2.2 或更高版本。

  • pip 19.0 or later (requires manylinux2010 support) pip 19.0 或更高版本(需要 manylinux2010 支持)

Try running pip install --upgrade pip inside your python3 virtualenv.尝试在 python3 virtualenv 中运行pip install --upgrade pip

You mentioned Anaconda.你提到了蟒蛇。 Do you run your python through there?你在那里运行你的蟒蛇吗?

If so check in Anaconda Navigator --> Environments, if your current environment have got tensorflow installed.如果是这样,请检查 Anaconda Navigator --> Environments,如果您当前的环境已经安装了 tensorflow。 If not, install tensorflow and run from that environment.如果没有,请安装 tensorflow 并从该环境运行。 Should work.应该管用。

I had the same problem that yours, happened that I had python at version 3.7.我遇到了和你一样的问题,碰巧我有 3.7 版的 python。 So for installing the Tensorflow with the GPU support I used:因此,为了安装具有 GPU 支持的 Tensorflow,我使用了:

py -3.6 -m pip install tensorflow-gpu py -3.6 -m pip install tensorflow-gpu

at a Virtualenv ambient.在 Virtualenv 环境中。 You can see the documentation behind on this website:你可以在这个网站上看到后面的文档:

https://docs.python.org/3/installing/index.html https://docs.python.org/3/installing/index.html

I think that this solution is better than downgrade the Python version.我认为这个解决方案比降级Python版本更好。

Actually the easiest way to install tensorflow is: install python 3.5 (not 3.6 or 3.7) you can check wich version you have by typing "python" in the cmd.实际上,安装 tensorflow 的最简单方法是:安装 python 3.5(不是 3.6 或 3.7),您可以通过在 cmd 中键入“python”来检查您拥有的版本。

When you install it check in the options that you install pip with it and you add it to variables environnement.当您安装它时,请检查您安装 pip 的选项并将其添加到变量环境中。 When its done just go into the cmd and tipe "pip install tensorflow"完成后,只需进入 cmd 并提示“pip install tensorflow”

It will download tensorflow automatically.它将自动下载 tensorflow。

If you want to check that it's been installed type "python" in the cmd then some that ">>>" will appear, then you write "import tensorflow" and if there's no error, you've done it!如果您想检查它是否已安装,请在 cmd 中键入“python”,然后会出现一些“>>>”,然后您编写“import tensorflow”,如果没有错误,您就完成了!

As of November 2018, Tensorflow is not supported for Python 3.6.4+截至 2018 年 11 月,Python 3.6.4+支持 Tensorflow

What to do:该怎么办:

Downgrade Anaconda's Python from 3.7 or 3.6.5+ to 3.6.4将 Anaconda 的 Python 从 3.7 或 3.6.5+ 降级到 3.6.4

a.一种。 Open Command Prompt, find your Anaconda environment, and change your directory打开命令提示符,找到您的 Anaconda 环境,并更改您的目录

  • where anaconda or where python where anaconda where python where anacondawhere python
    • Example path and cd:示例路径和 cd:
    • cd C:\\ProgramData\\Anaconda3\\bin

b.While in anaconda3/bin in your Command Prompt, source activate your base Anaconda environment在命令提示符中的 anaconda3/bin 中,源激活您的基本 Anaconda 环境

  • source activate

c. C。 In your Command Prompt, downgrade your base Anaconda environment在您的命令提示符中,降级您的基本 Anaconda 环境

  • conda install python=3.6.4

d. d. Install Tensorflow安装 TensorFlow

  • pip install tensorflow

Further reading: http://docs.anaconda.com/anaconda/user-guide/faq/#how-do-i-get-the-latest-anaconda-with-python-3-5进一步阅读: http : //docs.anaconda.com/anaconda/user-guide/faq/#how-do-i-get-the-latest-anaconda-with-python-3-5

As of July 2019, I have installed it on python 3.7.3 using py -3 -m pip install tensorflow-gpu py -3 in my installation selects the version 3.7.3.截至 2019 年 7 月,我已使用py -3 -m pip install tensorflow-gpu py -3 在 python 3.7.3 上安装它,在我的安装中选择版本 3.7.3。 The installation can also fail if the python installation is not 64 bit.如果 python 安装不是 64 位,安装也可能失败。 Install a 64 bit version first.首先安装 64 位版本。

This is Manas working as a intern in COE-AI lab(CET,BBSR) under tech machindra.这是 Manas 在 tech machindra 的 COE-AI 实验室(CET,BBSR)实习。

We faced same error.我们面临同样的错误。 After a little research, we found that there is a glitch in anaconda python 3.7 .经过一番研究,我们发现 anaconda python 3.7中存在一个小故障。 It does not install tensorflow through pip or conda install command, even if it does..produces same error..它不会通过 pip 或 conda install 命令安装 tensorflow,即使它确实..产生相同的错误..

Here is the solution, install conda environment for python=3.6 :这是解决方案,为python=3.6安装 conda 环境:

  1. go to the directory where conda is installed转到安装 conda 的目录
  2. cd anaconda3 cd anaconda3
  3. conda create -n tensorflow python=3.6 conda create -n tensorflow python=3.6
  4. conda activate tensorflow conda 激活 tensorflow
  5. conda install tensorflow python=3.6畅达安装张量流 python=3.6
  6. python Python
  7. Import tensorflow.导入张量流。

steps脚步

Do it twice:做两次:
enter image description here在此处输入图片说明
enter image description here在此处输入图片说明

-> Not able to install tensorflow , Here I have a solution that worked for me -> 无法安装 tensorflow ,这里我有一个对我有用的解决方案

Step 1 : - Check version of python(3.7.3) - Python must be 64 bit Otherwise tensorflow never ever going to be installed it defiitely gives Error.第 1 步: - 检查 python(3.7.3) 的版本 - Python 必须是 64 位,否则永远不会安装 tensorflow,它肯定会出现错误。

Step 2 :第2步 :

pip install tensorflow==2.0.0

Step 3 :第 3 步:

pip install sklearn==0.0
pip install Pillow==8.0.1
pip install h5py==2.10.0

Step 4 :第四步 :

pip install keras==2.3.1

Now its ready to use.现在它可以使用了。

In Windows 10 with Python 3.8.5, first i tried directly then it was giving following error:在使用 Python 3.8.5 的 Windows 10 中,首先我直接尝试,然后出现以下错误:

ERROR: Could not find a version that satisfies the requirement tensorflow==1.15 (from versions: none)错误:找不到满足 tensorflow==1.15 要求的版本(来自版本:无)

Then i installed successfully in virtual environment shown below:然后我在如下所示的虚拟环境中成功安装:

PS E:\udemy\full_stack_web_ai\deeplearning> .\myenv\Scripts\activate
(myenv) PS E:\udemy\full_stack_web_ai\deeplearning> pip install tensorflow
Collecting tensorflow ###
Downloading tensorflow-2.4.1-cp38-cp38-win_amd64.whl (370.7 MB) 

Use virtual environment using:使用虚拟环境使用:

python -m venv myenv
.\myenv\Scripts\activate

Not Enabling the Long Paths can be the potential problem.To solve that,不启用长路径可能是潜在的问题。要解决这个问题,

Steps include:步骤包括:

  1. Go to Registry Editor on the Windows Laptop转到 Windows 笔记本电脑上的注册表编辑器

  2. Find the key "HKEY_LOCAL_MACHINE"->"SYSTEM"->"CurrentControlSet"-> "File System"->"LongPathsEnabled" then double click on that option and change the value from 0 to 1.找到键 "HKEY_LOCAL_MACHINE"->"SYSTEM"->"CurrentControlSet"->"File System"->"LongPathsEnabled" 然后双击该选项并将值从 0 更改为 1。

3.Now try to install the tensorflow it will work. 3.现在尝试安装它会工作的tensorflow。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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