• tensorflow环境搭建


    官网:https://www.tensorflow.org/

    https://www.tensorflow.org/install/install_windows

    You must choose one of the following types of TensorFlow to install:

    • TensorFlow with CPU support only. If your system does not have a NVIDIA® GPU, you must install this version. Note that this version of TensorFlow is typically much easier to install (typically, in 5 or 10 minutes), so even if you have an NVIDIA GPU, we recommend installing this version first. Prebuilt binaries will use AVX instructions.
    • TensorFlow with GPU support. TensorFlow programs typically run significantly faster on a GPU than on a CPU. Therefore, if your system has a NVIDIA® GPU meeting the prerequisites shown below and you need to run performance-critical applications, you should ultimately install this version.

    Requirements to run TensorFlow with GPU support

    If you are installing TensorFlow with GPU support using one of the mechanisms described in this guide, then the following NVIDIA software must be installed on your system:

    • CUDA® Toolkit 9.0. For details, see NVIDIA's documentation Ensure that you append the relevant Cuda pathnames to the %PATH% environment variable as described in the NVIDIA documentation.
    • The NVIDIA drivers associated with CUDA Toolkit 9.0.
    • cuDNN v7.0. For details, see NVIDIA's documentation. Note that cuDNN is typically installed in a different location from the other CUDA DLLs. Ensure that you add the directory where you installed the cuDNN DLL to your %PATH%environment variable.
    • GPU card with CUDA Compute Capability 3.0 or higher for building from source and 3.5 or higher for our binaries. See NVIDIA documentation for a list of supported GPU cards.

    If you have a different version of one of the preceding packages, please change to the specified versions. In particular, the cuDNN version must match exactly: TensorFlow will not load if it cannot find cuDNN64_7.dll. To use a different version of cuDNN, you must build from source.

    tensorflow有两个版本,一个是CPU的,一个是GPU的,其中GPU对显卡有要求,必须是NVIDIA

    CUDA(Compute Unified Device Architecture),是显卡厂商NVIDIA推出的运算平台。 CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。

    Determine how to install TensorFlow

    You must pick the mechanism by which you install TensorFlow. The supported choices are as follows:

    • "native" pip
    • Anaconda

    Native pip installs TensorFlow directly on your system without going through a virtual environment. Since a native pip installation is not walled-off in a separate container, the pip installation might interfere with other Python-based installations on your system. However, if you understand pip and your Python environment, a native pip installation often entails only a single command! Furthermore, if you install with native pip, users can run TensorFlow programs from any directory on the system.

    In Anaconda, you may use conda to create a virtual environment. However, within Anaconda, we recommend installing TensorFlow with the pip install command, not with the conda install command.

    NOTE: The conda package is community supported, not officially supported. That is, the TensorFlow team neither tests nor maintains this conda package. Use that package at your own risk.

    anaconda2和anaconda3的区别也要注意。

    使用anaconda:

    接下来需要设置 Anaconda 仓库镜像,因为默认连接的是国外镜像地址,下载速度比较慢,我们把镜像地址改为清华大学开源软件镜像站,打开 Anaconda Prompt, 输入:

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --set show_channel_urls yes

    The Anaconda installation is community supported, not officially supported.

    Take the following steps to install TensorFlow in an Anaconda environment:

    1. Follow the instructions on the Anaconda download site to download and install Anaconda.

    2. Create a conda environment named tensorflow by invoking the following command:

       
      C:> conda create -n tensorflow pip python=3.5 
    3. Activate the conda environment by issuing the following command:

       
      C:> activate tensorflow
       (tensorflow)C:>  # Your prompt should change 
    4. Issue the appropriate command to install TensorFlow inside your conda environment. To install the CPU-only version of TensorFlow, enter the following command:

       
      (tensorflow)C:> pip install --ignore-installed --upgrade tensorflow 

      To install the GPU version of TensorFlow, enter the following command (on a single line):

       
      (tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu 

    输入activate tensorflow可以看到 命令行行前面有个tensorflow,这个就是当前运行环境。

    遇到的一个问题:

    powshell中无法active TensorFlow,我输入命令:

    PS C:WINDOWSsystem32> activate tensorflow
    PS C:WINDOWSsystem32> python -V
    Python 2.7.14 :: Anaconda, Inc.

    如上图还是没有进入tensorflow环境。

    看到一个回答在:另外在powershell中无法使用activate指令激活环境,需要进入到cmd中(https://www.zhihu.com/question/58573630 ,原因在于:

    https://blog.csdn.net/yannanxiu/article/details/78703888

     )

    我输入cmd,然后:

    PS C:WINDOWSsystem32> cmd
    Microsoft Windows [版本 10.0.16299.371]
    (c) 2017 Microsoft Corporation。保留所有权利。

    C:WINDOWSsystem32>activate tensorflow

    (tensorflow) C:WINDOWSsystem32>

    可以看到进入tensorflow环境了。

    运行 开始菜单 ->Anaconda3—>Anaconda Navigator,点击左侧的Environments,可以看到tensorflow的环境已经创建好了。

    在Anaconda Prompt中启动tensorflow环境:

    activate tensorflow

    注:当不使用tensorflow时,关闭tensorflow环境,命令为:deactivate(返回默认的python 3.6环境)

     

    运行pip install --ignore-installed --upgrade tensorflow

    报错:

    大量报:

    FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\mingsoo\AppData\Local\Temp\pip-build-5gbn3vww\gast\setup.py'

    ----------------------------------------
    Failed building wheel for gast
    Running setup.py clean for gast

    这种类似错误

    运行命令:pip install --upgrade --ignore-installed setuptools  

    然后接着安装tensorflow就安装成功了。

    Validate your installation

    Start a terminal.

    If you installed through Anaconda, activate your Anaconda environment.

    Invoke python from your shell as follows:

     
    $ python

    Enter the following short program inside the python interactive shell:

     
    >>> import tensorflow as tf
    >>> hello = tf.constant('Hello, TensorFlow!')
    >>> sess = tf.Session()
    >>> print(sess.run(hello))

    If the system outputs the following, then you are ready to begin writing TensorFlow programs:

     
    Hello, TensorFlow!

    If the system outputs an error message instead of a greeting, see Common installation problems.

    If you are new to machine learning, we recommend the following:

    If you are experienced with machine learning but new to TensorFlow, see Getting Started with TensorFlow.

    no moduled named tensorflow无此模块报错问题解决

     在spyder里面和Ipython里面输入测试代码,会报错没有tensorflow这个模块。但是在spyder和ipython里测试代码,会提示没有tensorflow模块,

    Import Error: No module named tensorflow.


    解决方法就是在tensorflow里面也给其安装属于python3.5的spyder。

    在开始菜单中搜索anaconda navigator,点击运行;

    点击左侧的home,选择application on tensorflow(有一个下拉框)

    会发现spyder属于右侧绿色install,这个时候点击install就可以在tensorflow里Python3.5环境里安装spyder,安装好之后,就如图所示,显示launch(已安装),

     
    点击launch,即可启动在tensorflow里面的spyder,,可以看到右下框,那个Python console变成了3.5版本,
     
     
     

     若要在pycharm中使用,则需选择 
     建工程后在  File-Setting–Project Interpreter  选择  tensorflow  下的Python解释器
     
     

    参考:

    windows7 下Anaconda2与Anaconda3并存

    https://blog.csdn.net/y1535766478/article/details/75097984

    https://blog.csdn.net/sb19931201/article/details/53648615

     https://www.cnblogs.com/W-Yentl/p/7783933.html

    https://www.cnblogs.com/nosqlcoco/p/6923861.html

  • 相关阅读:
    nunit2.5.7 单元测试时提示:“当前不会命中断点 还没有为该文档加载任何符号”
    文件下载报错:引发类型为“System.OutOfMemoryException”的异常-.Net 内存溢出
    asp.net 访问页面访问统计实现 for iis7
    easyui tree 更改图标
    asp.net 访问页面访问统计实现
    记一次空格引起的查询问题
    SVN如何忽略dll文件和bin目录
    vmware 中安装Ghost XP 版本心得
    冒泡排序
    JS数组去重
  • 原文地址:https://www.cnblogs.com/youxin/p/9022590.html
Copyright © 2020-2023  润新知