tensorflow-cpu

python3.8~3.12安装tensorflow-cpu

准备

创建并进入目录

bash 复制代码
mkdir tf-cpu
cd tf-cpu

编写测试代码

test_tensorflow.py

python 复制代码
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

创建虚拟环境

bash 复制代码
python312 -m venv tf219-312

windows

bash 复制代码
cd tf219-312/Scripts
activate
cd ../../

linux

bash 复制代码
source tf219-312/bin/activate

升级pip版本

bash 复制代码
python -m pip install --upgrade pip

搜索可用版本

bash 复制代码
pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

复制代码
pip install tensorflow-cpu==2.19.0

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

bash 复制代码
pip install tensorflow-intel==2.18.0

测试

bash 复制代码
python test_tensorflow.py

取消激活环境

windows

bash 复制代码
cd tf219-312/Scripts
deactivate
cd ../../

linux

bash 复制代码
source tf219-312/bin/deactivate

python3.11 tensorflow

创建虚拟环境

bash 复制代码
python311 -m venv tf219-311

windows

bash 复制代码
cd tf219-311/Scripts
activate
cd ../../

linux

bash 复制代码
source tf219-311/bin/activate

升级pip版本

bash 复制代码
python -m pip install --upgrade pip

搜索可用版本

bash 复制代码
pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

bash 复制代码
pip install tensorflow-cpu==2.19.0

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

bash 复制代码
pip install tensorflow-intel==2.18.0

测试

bash 复制代码
python test_tensorflow.py

取消激活环境

windows

bash 复制代码
cd tf219-311/Scripts
deactivate
cd ../../

linux

bash 复制代码
source tf219-311/bin/deactivate

python3.10 tensorflow

创建虚拟环境

bash 复制代码
python310 -m venv tf219-310

windows

bash 复制代码
cd tf219-310/Scripts
activate
cd ../../

linux

bash 复制代码
source tf219-310/bin/activate

升级pip版本

bash 复制代码
python -m pip install --upgrade pip

搜索可用版本

bash 复制代码
pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

bash 复制代码
pip install tensorflow-cpu==2.19.0

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

bash 复制代码
pip install tensorflow-intel==2.18.0

测试

bash 复制代码
python test_tensorflow.py

取消激活环境

windows

bash 复制代码
cd tf219-310/Scripts
deactivate
cd ../../

linux

bash 复制代码
source tf219-310/bin/deactivate

python3.9 tensorflow

创建虚拟环境

bash 复制代码
python39 -m venv tf219-39

windows

bash 复制代码
cd tf219-39/Scripts
activate
cd ../../

linux

bash 复制代码
source tf219-39/bin/activate

升级pip版本

bash 复制代码
python -m pip install --upgrade pip

搜索可用版本

bash 复制代码
pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

bash 复制代码
pip install tensorflow-cpu==2.19.0

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

bash 复制代码
pip install tensorflow-intel==2.18.0

测试

bash 复制代码
python test_tensorflow.py

取消激活环境

windows

bash 复制代码
cd tf219-39/Scripts
deactivate
cd ../../

linux

bash 复制代码
source tf219-39/bin/deactivate

python3.8 tensorflow2.13

创建虚拟环境

bash 复制代码
D:\dev\python\Python38\python.exe -m venv tf213-38

windows

bash 复制代码
cd tf213-38/Scripts
activate
cd ../../

linux

bash 复制代码
source tf213-38/bin/activate

升级pip版本

bash 复制代码
python -m pip install --upgrade pip

搜索可用版本

bash 复制代码
pip index versions tensorflow-cpu
pip index versions tensorflow-intel

安装指定版本

复制代码
pip install tensorflow-cpu==2.13.0

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

bash 复制代码
pip install tensorflow-intel==2.13.0

测试

bash 复制代码
python test_tensorflow.py

取消激活环境

windows

bash 复制代码
cd tf213-38/Scripts
deactivate
cd ../../

linux

bash 复制代码
source tf213-38/bin/deactivate
相关推荐
JJJJ_iii5 小时前
【机器学习08】模型评估与选择、偏差与方差、学习曲线
人工智能·笔记·python·深度学习·学习·机器学习
phoenix@Capricornus6 小时前
样本与样本值
人工智能·机器学习·概率论
东方佑6 小时前
构建智能对话系统:Python实现聊天话题管理与摘要生成
jvm·python·oracle
讲师-汪春波6 小时前
【无标题】
人工智能
RockHopper20256 小时前
利用数字孪生技术打造智能工厂的“情境认知”能力
人工智能·智能制造·数字孪生·智能工厂
兮兮能吃能睡6 小时前
数据分析核心术语略解
数据挖掘·数据分析
喵叔哟6 小时前
8. 从0到上线:.NET 8 + ML.NET LTR 智能类目匹配实战--规则回退与可解释性:四层策略如何兜底
人工智能·深度学习·.net
微软技术栈6 小时前
Microsoft AI Genius | 用智能 Microsoft Copilot 副驾驶® 构建高韧性 DevOps 流程
人工智能·microsoft·copilot
前端世界6 小时前
用Python手写一个能识花的感知器模型——Iris分类实战详解
开发语言·python·分类
茶杯6756 小时前
GraphRAG产品赋能企业智能升级:创邻科技知寰Hybrid RAG的四大核心应用场景深度解析
人工智能·科技·graphrag产品