zoukankan      html  css  js  c++  java
  • macOS Big Sur安装TensorFlow踩坑记

    一,还是设置代理:

    export http_proxy=http://192.168.31.168:1190
    export https_proxy=http://192.168.31.168:1190

    二、通过下面的命令安装 pip 和 Virtualenv:

    $ sudo easy_install pip
    $ pip install --upgrade virtualenv

    装完提示:

    WARNING: The script virtualenv is installed in '/Users/meetrice/Library/Python/2.7/bin' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
     
    根据提示加入环境变量吧
    export PATH="$PATH:/Users/meetrice/Library/Python/2.7/bin"
     
    三、执行下面的命令来创建 Virtualenv 环境
     
    创建 Python 2.7的环境:
    virtualenv --system-site-packages targetDirectory 
    执行结果:
    created virtual environment CPython2.7.16.final.0-64 in 2136ms
    creator CPython2macOsFramework(dest=/Users/meetrice/targetDirectory, clear=False, no_vcs_ignore=False, global=True)
    seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=/Users/meetrice/Library/
    Application Support/virtualenv)
    added seed packages: pip==20.3.1, setuptools==44.1.1, wheel==0.36.1
    activators PythonActivator,CShellActivator,FishActivator,PowerShellActivator,BashActivator
    这表示创建成功!
     
    创建 Python 3.n 的环境:
    virtualenv --system-site-packages -p python3
    执行结果出现异常 :
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3'
     
    于是单独执行python3命令:
    python3
    出现提示
    You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
     Hit the Return key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
    根据提示 输入 回车,此时会显示授权协议 
    不断的按 空格键 直到结尾,出现
    By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else t
    o cancel, [agree, print, cancel]
     
    输入 "agree"回车
    这此python3就已经可以正常使用
     
    再一次安装python 3的虚拟环境
    virtualenv --system-site-packages -p python3 targetDirectory
    执行后:
    created virtual environment CPython3.8.2.final.0-64 in 2232ms
    creator CPython3macOsFramework(dest=/Users/meetrice/targetDirectory, clear=False, no_vcs_ignore=False, global=True)
    seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=/Users/meetrice/Library/
    Application Support/virtualenv)
    added seed packages: pip==20.3.1, setuptools==51.0.0, wheel==0.36.1
    activators PythonActivator,FishActivator,XonshActivator,CShellActivator,PowerShellActivator,BashActivator
    成功!
     
    四、激活 Virtualenv 环境
    cd targetDirectory
    source ./bin/activate
    (targetDirectory)$ easy_install -U pip
     

    (targetDirectory)$ pip install --upgrade tensorflow # 对应 Python 2.7
    (targetDirectory)$ pip3 install --upgrade tensorflow # 对应 Python 3.n

    五,验证tensorFlow,运行HelloWorld

    在虚拟环境中的当前目录,创建helloworld.py

    (targetDirectory) meetrice@mbp targetDirectory % nano helloworld.py
    在编辑界面输入以下内容:
    import tensorflow as tf
    msg = tf.constant('Hello, TensorFlow!')
    tf.print(msg)
    然后ctrl+x Y,回车保存
    然后执行
    python helloworld.py
    出现结果:
     
    2020-12-27 14:34:26.911207: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices n
    ot set
    2020-12-27 14:34:26.918930: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI
    Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
    To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
    Hello, TensorFlow!
     
    HelloWorld 成功!
     
    退出虚拟环境: deactivate
    创建虚拟环境: virtualenv --no-site-packages --python=3.6 env #注释: --no-site-packages 不包括系统包 --python=3.6版本 env 虚拟环境名称
    激活虚拟环境:source test_env01/bin/activate(activate路径)
  • 相关阅读:
    PC端网站微信扫码登录
    H5微信授权登录
    Taro -- Swiper的图片由小变大3d轮播效果
    vue,一路走来(17)--vue使用scss,并且全局引入公共scss样式
    vscode 黑屏及类名报错解决方案
    js的cookie写入存储与读取
    常用正则表达式
    JS获取当前时间戳的方法
    URL的截取问题
    cookie的基本用法案例
  • 原文地址:https://www.cnblogs.com/meetrice/p/14197245.html
Copyright © 2011-2022 走看看