安装anaconda
windows下直接安装,最好勾上python加入系统路径。
查看及安装tensorflow依赖
查看cuda版本(机器支持gpu的不考虑)
cat /usr/local/cuda/version.txt
cuda版本及其对应tf版本:
[经过测试的构建配置]
查看python版本
python -V
安装python环境anaconda参考[python虚拟环境安装和配置]
安装对应的tf版本
检测已安装版本
$pip3 show tensorflow
$pip3 show tensorflow-gpu
Note:
1 安装的tensorflow版本要和python对应,否则出错:tensorflow_gpu-1.12.0-cp...m-linux_x86_64.whl is not a supported wheel on this platform。
2 安装的tensorflow版本也要和cuda版本相对应,否则出错:tenforflow ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found stackoverflow。
3 tensorflow_gpu版本太高,如1.12,会报错Failed to get convolution algorithm. cudnn failed to initialize…。目前版本的TensorFlow的ObjectDection中,使用tensorflow-gpu ==1.12 版本会报错,如上,将版本降到tensorflow-gpu ==1.9.0即可正常运行。pip3 install --upgrade --force-reinstall tensorflow-gpu==1.10.1
4 tensorflow-gpu版本太低,如1.9,也会报错:tensorflow-gpu 1.9.0 module 'tensorflow.contrib.estimator' has no attribute 'stop_if_no_increase_hook',这个模块在1.10以上版本才有,所以需要权衡一下再安装。
[一些不同平台不同版本地址how to install tensorflow version 1.12.0 with pip - Stack Overflow]
linux中pip直接安装
安装最新版本:
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
安装指定版本2.*
pip install tensorflow==2.* -i https://pypi.tuna.tsinghua.edu.cn/simple
安装带gpu的指定版本1.*
pip3 install --upgrade --force-reinstall tensorflow-gpu==1.10.1
pip3 install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-linux_x86_64.whl 低版本下载地址在这里[tensorflow-gpu · PyPI]
[安装 TensorFlow]
mac下安装
安装2.*最新版本
pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
m1芯片直接安装tf2.0可能会出错:Process finished with exit code 132( signal 4 (SIGILL)。可能是因为“tensoflow版本问题,1.5.0以上的tensorflow需要AVX支持,所以,退回到1.5.0可以解决此问题。”
安装1.*版本
mac intel cpu安装
pip3 install --upgrade https://download.tensorflow.google.cn/mac/cpu/tensorflow-1.13.1-py3-none-any.whl pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl
tf1.12这种低版本的需要python3版本低,比如py3.6,否则import tensorflow时会提示出错:todo...
mac m1芯片安装
m1芯片安装就有点麻烦了,而且目前lz只找到tf2.0的版本,tf1.0貌似无法安装,有方法求留言!
m1芯片直接安装tf1.0会提示错误:“zsh: illegal hardware instruction python” ;
需要使用特定版本的tf:
下载anaconda arm 打开anaconda arm 链接macOS ARM builds on conda-forge — the conda-forge blog,点开here就可以下载了。
安装anaconda:/bin/bash ./Miniforge3-MacOSX-arm64.sh
conda create -n tfenv python=3.8 conda activate tfenv
下载tensorflowReleases · apple/tensorflow_macos · GitHub 进入这个网站,有Assets,点击下载文件tensorflow_macos-0.1alpha3.tar.gz就可以了。
在当前tfenv环境中执行下面的语句 libs="/Users/pipi/download/tensorflow_macos/arm64"
env="/Users/pipi/miniforge3/envs/tfenv"
pip install --upgrade pip wheel setuptools cached-property six
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl"
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl"
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl"
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl"
pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl"
验证:python>import tensorflow
[Mac m1芯片anaconda上安装tensorflow][Macbook m1芯片版本怎么安装tensorflow2.0]。
之后可能还要安装其它包,如pandas,import时出错:ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
解决:重装numpy: pip uninstall numpy pip install numpy
window下安装
anaconda powershell prompt中安装最新版本
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
安装老版本
pip3 install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl
安装tf相关拓展包
pip3 install git+https://github.com/guillaumegenthial/tf_metrics.git
python import tensorflow as tf
tf.__version__ #查看tensorflow版本
tf.__path__ #查询tensorflow安装路径
from: -柚子皮-
ref: