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
相关推荐
TMO Group 探谋网络科技5 小时前
AI电商的应用:Magento 使用 Adobe 生成式 AI改造7大业务场景
大数据·人工智能·adobe·ai
二川bro5 小时前
字符串特性解析:Python不可变性引发的错误
android·开发语言·python
UI设计兰亭妙微5 小时前
理性数据,温柔体验:北京兰亭妙微解码 Hydra Corps. 企业管理界面的 “松弛感设计”
大数据·人工智能·用户体验设计
慎独4135 小时前
家家有:从单向支出到价值循环,绿色积分如何 重构商业逻辑?
大数据·人工智能
梦里不知身是客115 小时前
flink使用 DefaultResourceCalculator(默认资源计算器) 策略
大数据·flink
呆萌小新@渊洁5 小时前
声纹模型全流程实践-开发(训练 - 微调 - 部署 - 调用)
linux·服务器·python·语音识别
深度之眼5 小时前
入选TPAMI顶刊!多模态图像融合新突破!
深度学习·机器学习·多模态
Mxsoft6195 小时前
DBSCAN孤立点检测救场!某次异常数据污染,精准过滤保模型精度!
人工智能
华东设计之美5 小时前
muti-Agent+RAG+KnowledgeGraph构建智能问诊系统的可行性分析
人工智能·软件开发·rag·大模型应用·增强检索生成
光羽隹衡5 小时前
sklearn实现一元线性回归——分析广告投入和销售额的关系
人工智能·线性回归·sklearn