CentOS7+ anaconda3 + Python-3.6 + tensorflow-cpu-1.5安装和配置

本文详细介绍了在CentOS7系统中使用Anaconda3搭建Python3.6环境,并成功安装配置TensorFlow1.5的过程,解决了非法指令错误问题,适合初学者及遇到相似问题的开发者参考。

CentOS7+ anaconda3 + Python-3.6 + tensorflow-cpu-1.5安装和配置
=============================================================================
本博客,博文:CentOS7服务器上部署深度/机器学习环境推荐首选anaconda3 链接https://www.cnblogs.com/jeshy/p/10522379.html
可能会出错:
>>> import tensorflow as tf
Illegal instruction
本文主要解决此问题(降低版本)
=============================================================================
(base) [jiangshan@localhost ~]$ conda info -e
# conda environments:
#
base * /home/jiangshan/anaconda3
tensorflow /home/jiangshan/anaconda3/envs/tensorflow

==========先卸载和删除掉先前创建 的tensorflow虚拟环境=======================

(base) [jiangshan@localhost ~]$ conda remove --name tensorflow --all

==========先卸载和删除掉先前创建 的tensorflow虚拟环境=======================

(base) [jiangshan@localhost ~]$ conda info -e
# conda environments:
#
base * /home/jiangshan/anaconda3

(base) [jiangshan@localhost ~]$ conda create --name tensorflow python=3.6
(base) [jiangshan@localhost ~]$ conda activate tensorflow

添加设置镜像
# 添加tensorflow的Linux/cpu清华镜像
(tensorflow) [jiangshan@localhost ~]$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/
# 设置搜索时显示通道地址
(tensorflow) [jiangshan@localhost ~]$ conda config --set show_channel_urls yes
**************************************************************************
安装 tensorflow1.8.0
(tensorflow) [jiangshan@localhost ~]$ conda install tensorflow==1.8
以上会出错,改为以下用pip从源码安装
(tensorflow) [jiangshan@localhost ~]$ pip install tensorflow==1.8
测试==报错==
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Illegal instruction
补救 卸载 tensorflow1.8 改安装较低版本的tensorflow(我来来回回降到了1.5版)
(tensorflow) [jiangshan@localhost ~]$ pip uninstall tensorflow
**************************************************************************
安装 tensorflow1.5
(tensorflow) [jiangshan@localhost ~]$ pip install tensorflow==1.5
测试
(tensorflow) [jiangshan@localhost ~]$ python
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('你好!姜山~')
>>> sess = tf.Session()
2019-03-13 03:39:49.959697: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2
>>> print (sess.run(hello))
b'\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x81\xe5\xa7\x9c\xe5\xb1\xb1~'【我靠 不识别中文?????,赶紧换英文试试】

>>> hello = tf.constant('hhhh')
>>> sess = tf.Session()
>>> print (sess.run(hello))
b'hhhh'

>>> quit()
(tensorflow) [jiangshan@localhost ~]$ conda deactivate
(base) [jiangshan@localhost ~]$

成功

 

转载于:https://www.cnblogs.com/jeshy/p/10523646.html

<think>嗯,用户现在要在CentOS 7上用Anaconda安装TensorFlow。首先,我得确认他们是否已经安装Anaconda。如果没有,可能需要先指导安装步骤。然后,TensorFlowCPUGPU版本,用户可能需要根据他们的硬件选择。不过CentOS服务器可能更多用CPU版本,但如果有NVIDIA显卡的话,GPU版本性能更好。 用户可能对conda环境不熟悉,所以需要详细说明如何创建管理环境。常见的错误可能包括环境没有正确激活,或者安装TensorFlow版本与Python版本不兼容。需要提醒他们检查Python版本,比如TensorFlow 2.x通常需要Python 3.73.10。 另外,安装时可能会遇到依赖问题,尤其是GPU版本需要CUDAcuDNN的支持。这时候可能需要指导他们如何通过conda自动安装这些依赖,或者手动安装。不过conda通常能处理这些依赖,所以建议使用conda安装。 测试步骤也很重要,用户安装后可能不知道如何验证是否成功,所以需要给出简单的测试代码。还有,常见问题比如导入错误,可能是环境没激活,或者版本冲突,需要提醒他们检查这些点。 最后,如果用户遇到问题,应该引导他们查看错误信息,或者提供更多的帮助资源。可能需要提到升级conda、清理缓存等维护技巧,确保他们能顺利安装。</think>在 CentOS 7 系统上通过 Anaconda 安装 TensorFlow 可分为以下步骤(包含避坑指南): --- ### 一、前置准备 1. **确认系统版本** ```bash cat /etc/centos-release # 输出应包含 "CentOS Linux release 7.x" ``` 2. **安装 Anaconda** ```bash wget https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh bash Anaconda3-2023.03-Linux-x86_64.sh # 安装时选择"yes"添加到PATH source ~/.bashrc # 激活环境变量 ``` --- ### 二、安装 TensorFlowCPU/GPU版) #### 方案 1CPU版本(通用) ```bash conda create -n tf_cpu python=3.9 # 创建独立环境(推荐Python 3.7-3.10) conda activate tf_cpu conda install -c conda-forge tensorflow # 通过conda自动解决依赖 ``` #### 方案 2:GPU版本(需NVIDIA显卡) ```bash conda create -n tf_gpu python=3.9 conda activate tf_gpu conda install -c conda-forge tensorflow-gpu # 自动安装CUDA/cuDNN依赖 ``` --- ### 三、验证安装 ```python # 测试脚本 test_tf.py import tensorflow as tf print(f"TensorFlow版本: {tf.__version__}") print("GPU是否可用:", tf.config.list_physical_devices(&#39;GPU&#39;)) ``` 运行验证: ```bash python test_tf.py ``` *期望输出示例:* ``` TensorFlow版本: 2.12.0 GPU是否可用: [PhysicalDevice(name=&#39;/physical_device:GPU:0&#39;, device_type=&#39;GPU&#39;)] ``` --- ### 四、常见问题解决 #### 1. **导入错误 `libcuda.so.1`** - **现象**:`ImportError: libcuda.so.1: cannot open shared object file` - **解决方案**: ```bash sudo yum install -y cuda-drivers # 安装NVIDIA驱动 nvidia-smi # 确认驱动版本 ≥450.80.02 ``` #### 2. **GLIBC版本过低** - **现象**:`/lib64/libm.so.6: version GLIBC_2.27 not found` - **解决方案**: ```bash conda install -c conda-forge gcc=12.1.0 # 在conda环境中安装新编译器 ``` --- ### 五、环境管理技巧 | 操作 | 命令 | |-------|------| | 查看所有环境 | `conda env list` | | 删除环境 | `conda remove -n 环境名 --all` | | 导出环境配置 | `conda env export > environment.yml` | | 克隆环境 | `conda create -n 新环境名 --clone 原环境名` | --- ### 六、版本对应关系(关键) | TensorFlow | Python | CUDA | cuDNN | |------------|--------|------|-------| | 2.12+ | 3.8-3.10| 11.8 | 8.6 | | 2.11 | 3.7-3.10| 11.2 | 8.1 | | 2.4-2.10 | 3.6-3.9 | 11.0 | 8.0 | --- 通过以上步骤,您可以在 CentOS 7 上稳定运行 TensorFlow。建议优先使用 conda 管理依赖,避免手动安装 CUDA 带来的兼容性问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值