python 环境。在Mac 系统上实行 pip install tensorflow
可能会出现下面的错误提示
1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
是尝试卸载numpy
时出现的错误,可用下面一行强行(忽略旧版本升级)安装新的numpy
1
sudo pip install --ignore-installed numpy
或者配合Homebrew 安装,这是官方文档提的方法:
安装python
1
2
3
4
$ brew install python
$ brew linkapps python
$ which python
/usr/local/bin/python
用 easy_install 安装或升级pip:
1
2
$ easy_install pip
$ pip install --upgrade pip
安装 TensorFlow:
1
2
$ pip install tensorflow
$ pip install tensorflow-gpu # Optional
测试:
1
2
$ python
>>> import tensorflow as tf
如果上面的方法安装不成功,可尝试下面一行解决,填写最新版本:
1
pip install tensorflow==1.12.0 --user
关于python版本的问题
1
2
3
4
5
6
7
8
9
#当需要输入python时直接指向python3.5,可以这样处理:
ln -s /usr/local/python3/bin/python3 /usr/bin/python #前面换成你的安装路径
#ps:如果提示 ln: creating symbolic link `/usr/bin/python': File exists
#需要把原来的/usr/bin/python 通过以下命令备份一下
mv /usr/bin/python /usr/bin/python.bak
#需要恢复原来的python指向的话:
cp /usr/bin/python.bak /usr/bin/python
python3
如果是python3 环境就更方便,但目前tensorflow 只支持 Python 3.4, 3.5, 3.6
,如果用brew install python
或 brew install python3
则会安装最新的python3.7,用下面的方法才能安装python3.6 :
1
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
此时默认已安装pip3
,更新
1
pip3 install --upgrade pip
安装tensorflow
1
sudo pip3 install tensorflow
成功安装的包:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ pip3 list
Package Version
------------------- -------
absl-py 0.6.1
astor 0.7.1
gast 0.2.0
grpcio 1.17.1
h5py 2.8.0
Keras-Applications 1.0.6
Keras-Preprocessing 1.0.5
Markdown 3.0.1
numpy 1.15.4
pip 18.1
protobuf 3.6.1
setuptools 39.2.0
six 1.12.0
tensorboard 1.12.1
tensorflow 1.12.0
termcolor 1.1.0
Werkzeug 0.14.1
wheel 0.31.1
看看tensorflow 的信息:
1
2
3
4
5
6
7
8
9
10
11
12
$ pip show tensorflow
Name: tensorflow
Version: 1.12.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.6/site-packages
Requires: six, termcolor, tensorboard, numpy, keras-preprocessing, keras-applications, grpcio, wheel, protobuf, absl-py, astor, gast
Required-by:
测试:
1
python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
输出:
1
tf.Tensor(-193.46434, shape=(), dtype=float32)
本文网址: https://pylist.com/topic/166.html 转摘请注明来源