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
相关推荐
再吃一根胡萝卜4 分钟前
使用 squashmigrations 命令优化 Django 迁移文件
python·django
强盛小灵通专卖员6 分钟前
DL00291-联邦学习以去中心化锂离子电池健康预测模型完整实现
人工智能·机器学习·深度强化学习·核心期刊·导师·小论文·大论文
逆向菜鸟8 分钟前
【摧毁比特币】椭圆曲线象限细分求k-陈墨仙
python·算法
Hello123网站15 分钟前
多墨智能-AI一键生成工作文档/流程图/思维导图
人工智能·流程图·ai工具
有Li1 小时前
CLIK-Diffusion:用于牙齿矫正的临床知识感知扩散模型|文献速递-深度学习人工智能医疗图像
人工智能·深度学习·文献·医学生
有梦想的攻城狮1 小时前
Java 11中的Collections类详解
java·windows·python·java11·collections
哈哈很哈哈1 小时前
Spark 运行流程核心组件(三)任务执行
大数据·分布式·spark
前端小趴菜051 小时前
python - input()函数
python
大唐荣华1 小时前
视觉语言模型(VLA)分类方法体系
人工智能·分类·机器人·具身智能
即兴小索奇1 小时前
AI应用商业化加速落地 2025智能体爆发与端侧创新成增长引擎
人工智能·搜索引擎·ai·商业·ai商业洞察·即兴小索奇