创建文件夹
mkdir tf-course
安装virtualenv
➜ tf-course sudo pip install virtualenv
Password:
DEPRECATION: Python 2.7 will rhttps://files.pythonhosted.org/packages/ca/ee/8375c01412abe6ff462ec80970e6bb1c4308724d4366d7519627c98691ab/virtualenv-16.6.0-py2.py3-none-any.whl (2.0MB)
100% |████████████████████████████████| 2.0MB 2.0MB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.6.0
- 查看版本
➜ tf-course virtualenv --version
16.6.0
- 使用virtualenv创建一个python虚拟环境
➜ tf-course virtualenv --version
16.6.0
➜ tf-course virtualenv --system-site-packages -p python2.7 ./venv
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in /Users/lujie/Desktop/workspace/tf-course/venv/bin/python2.7
Also creating executable in /Users/lujie/Desktop/workspace/tf-course/venv/bin/python
Installing setuptools, pip, wheel...
done.
➜ tf-course ll
total 0
drwxr-xr-x 6 lujie staff 192B 6 16 18:18 venv
- 激活虚拟环境
➜ tf-course source venv/bin/activate
(venv) ➜ tf-course
linux环境:
创建环境 virtualenv --no-site-packages venv
进入环境 source venv/bin/activate
- 安装tensorflow (可能比较慢)
(venv) ➜ tf-course pip install tensorflow
- 可以查看一下下载的依赖包
(venv) ➜ tf-course pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package Version
---------------------- ---------
absl-py 0.7.1
astor 0.8.0
backports.weakref 1.0.post1
enum34 1.1.6
funcsigs 1.0.2
futures 3.2.0
gast 0.2.2
grpcio 1.21.1
h5py 2.9.0
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.0
List 1.3.0
Markdown 3.1.1
mock 3.0.5
mysql-connector-python 8.0.16
numpy 1.16.4
pip 19.1.1
protobuf 3.8.0rc1
setuptools 41.0.1
six 1.12.0
tensorboard 1.13.1
tensorflow 1.13.1
tensorflow-estimator 1.13.0
termcolor 1.1.0
virtualenv 16.6.0
Werkzeug 0.15.4
wheel 0.33.4
- 进入python查看
(venv) ➜ tf-course python
Python 2.7.16 (default, Apr 12 2019, 15:32:40)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> exit()
- 离开环境
(venv) ➜ tf-course deactivate
➜ tf-course
- 打印
Hello Tensor Flow
(venv) ➜ tf-course python
Python 2.7.16 (default, Apr 12 2019, 15:32:40)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant("Hello TensorFlow")
>>> sess = tf.Session()
2019-06-16 19:12:25.502889: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
>>> sess.run(hello)
'Hello TensorFlow'
>>> print(sess.run(hello))
Hello TensorFlow
>>>