tensorflow-cpu

python3.8~3.12安装tensorflow-cpu

准备

创建并进入目录

mkdir tf-cpu
cd tf-cpu

编写测试代码

test_tensorflow.py

import tensorflow as tf
 
# 检查TensorFlow版本
print("\nTensorFlow version:", tf.__version__,end='\n\n')
 
# 创建一个简单的计算图并运行它
tensor = tf.constant([[1, 2], [3, 4]])
result = tf.multiply(tensor, 2)
 
# 启动默认的TensorFlow会话(自TensorFlow 2.x起,推荐使用tf.function和eager execution)
if hasattr(tf, 'Session'):  # TensorFlow 1.x风格
    with tf.Session() as sess:
        output = sess.run(result)
        print("Output of multiplication:", output)
else:  # TensorFlow 2.x风格,默认启用eager execution
    output = result.numpy()  # 将Tensor转换为NumPy数组以查看结果
    print("Output of multiplication:\n", output)

python3.12 tensorflow

创建虚拟环境

python312 -m venv tf219-312

windows

cd tf219-312/Scripts
activate
cd ../../

linux

source tf219-312/bin/activate

升级pip版本

python -m pip install --upgrade pip

搜索可用版本

pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

pip install tensorflow-cpu==2.19.0

intel优化版本可以执行以下命令

pip install tensorflow-intel==2.18.0

测试

python test_tensorflow.py

取消激活环境

windows

cd tf219-312/Scripts
deactivate
cd ../../

linux

source tf219-312/bin/deactivate

python3.11 tensorflow

创建虚拟环境

python311 -m venv tf219-311

windows

cd tf219-311/Scripts
activate
cd ../../

linux

source tf219-311/bin/activate

升级pip版本

python -m pip install --upgrade pip

搜索可用版本

pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

pip install tensorflow-cpu==2.19.0

intel优化版本可以执行以下命令

pip install tensorflow-intel==2.18.0

测试

python test_tensorflow.py

取消激活环境

windows

cd tf219-311/Scripts
deactivate
cd ../../

linux

source tf219-311/bin/deactivate

python3.10 tensorflow

创建虚拟环境

python310 -m venv tf219-310

windows

cd tf219-310/Scripts
activate
cd ../../

linux

source tf219-310/bin/activate

升级pip版本

python -m pip install --upgrade pip

搜索可用版本

pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

pip install tensorflow-cpu==2.19.0

intel优化版本可以执行以下命令

pip install tensorflow-intel==2.18.0

测试

python test_tensorflow.py

取消激活环境

windows

cd tf219-310/Scripts
deactivate
cd ../../

linux

source tf219-310/bin/deactivate

python3.9 tensorflow

创建虚拟环境

python39 -m venv tf219-39

windows

cd tf219-39/Scripts
activate
cd ../../

linux

source tf219-39/bin/activate

升级pip版本

python -m pip install --upgrade pip

搜索可用版本

pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

pip install tensorflow-cpu==2.19.0

intel优化版本可以执行以下命令

pip install tensorflow-intel==2.18.0

测试

python test_tensorflow.py

取消激活环境

windows

cd tf219-39/Scripts
deactivate
cd ../../

linux

source tf219-39/bin/deactivate

python3.8 tensorflow2.13

创建虚拟环境

D:\dev\python\Python38\python.exe -m venv tf213-38

windows

cd tf213-38/Scripts
activate
cd ../../

linux

source tf213-38/bin/activate

升级pip版本

python -m pip install --upgrade pip

搜索可用版本

pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

pip install tensorflow-cpu==2.13.0

intel优化版本可以执行以下命令

pip install tensorflow-intel==2.13.0

测试

python test_tensorflow.py

取消激活环境

windows

cd tf213-38/Scripts
deactivate
cd ../../

linux

source tf213-38/bin/deactivate
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李昊哲小课

桃李不言下自成蹊

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值