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路徑)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM