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
相关推荐
编码小哥1 天前
OpenCV Haar级联分类器:人脸检测入门
人工智能·计算机视觉·目标跟踪
程序员:钧念1 天前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
数据与后端架构提升之路1 天前
TeleTron 源码揭秘:如何用适配器模式“无缝魔改” Megatron-Core?
人工智能·python·适配器模式
Chef_Chen1 天前
数据科学每日总结--Day44--机器学习
人工智能·机器学习
这张生成的图像能检测吗1 天前
(论文速读)FR-IQA:面向广义图像质量评价:放松完美参考质量假设
人工智能·计算机视觉·图像增强·图像质量评估指标
hele_two1 天前
快速幂算法
c++·python·算法
KG_LLM图谱增强大模型1 天前
本体论与知识图谱:揭示语义技术的核心差异
人工智能·知识图谱·本体论
小鸡脚来咯1 天前
Git 新手入门指南
大数据·git·elasticsearch
l1t1 天前
利用DeepSeek将python DLX求解数独程序格式化并改成3.x版本
开发语言·python·算法·数独
JicasdC123asd1 天前
黄瓜植株目标检测:YOLOv8结合Fasternet与BiFPN的高效改进方案
人工智能·yolo·目标检测