使用 pip 安装 TensorFlow(参考:https://tensorflow.google.cn/install/pip)
pip install --upgrade tensorflow
下载支持依赖(VC_redist.x86.exe)
https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads
测试安装是否成功
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
缺少的dll 下载后放到 C:\Windows\System32\
https://cn.dll-files.com/download/
Demo:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
message=tf.constant('welcome to zac first tf')
with tf.compat.v1.Session() as sess:
print(sess.run(message).decode())
-----------虚拟环境运行
创建一个新的虚拟环境,方法是选择 Python 解释器并创建一个 .\venv 目录来存放它:
python -m venv --system-site-packages .\venv
激活虚拟环境:
.\venv\Scripts\activate
在不影响主机系统设置的情况下,在虚拟环境中安装软件包。首先升级 pip:
pip install --upgrade pip
pip list # show packages installed within the virtual environment
之后退出虚拟环境:
deactivate # don't exit until you're done using TensorFlow
------v1的一些函数
tf.compat.v1.disable_eager_execution()
tf.compat.v1.placeholder
tf.compat.v1.Session()