##一、 安装指令
pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple
执行安装后,成功安装相关依赖库和TensorFlow,最后2行安装程序输出信息如下:
Installing collected packages: tensorflow-io-gcs-filesystem, tensorflow
Successfully installed tensorflow-2.11.0 tensorflow-io-gcs-filesystem-0.29.0
二、测试
1、运行Python3
(aiStudy) administrator@jwp:~/Desktop/aiStudy$ python3
Python 3.7.3 (default, Oct 13 2023, 10:47:37)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
2、执行import
>>> import tensorflow as tf
/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/python/ops/__init__.py:98: UserWarning: unable to load libtensorflow_io_plugins.so: unable to open file: libtensorflow_io_plugins.so, from paths: ['/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/python/ops/libtensorflow_io_plugins.so']
caused by: ["[Errno 2] The file to load file system plugin from does not exist.: '/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/python/ops/libtensorflow_io_plugins.so'"]
warnings.warn(f"unable to load libtensorflow_io_plugins.so: {e}")
/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/python/ops/__init__.py:104: UserWarning: file system plugins are not loaded: unable to open file: libtensorflow_io.so, from paths: ['/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/python/ops/libtensorflow_io.so']
caused by: ['/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/python/ops/libtensorflow_io.so: cannot open shared object file: No such file or directory']
warnings.warn(f"file system plugins are not loaded: {e}")
可以看到有警告信息,是加载tensorflow_io失败,TensorFlow I/O 是一个扩展库,为 TensorFlow 提供了对各种文件系统和数据格式的支持。它不是 TensorFlow 的核心组件,但是提供了一些额外的功能,比如:
- 支持多种文件系统:包括本地文件系统、HDFS、GCS(Google Cloud Storage)、S3(Amazon Simple Storage Service)等
- 支持多种数据格式:如 Apache Parquet、Apache Avro 等
- 数据管道功能:提供高级的数据输入管道操作,以简化数据加载和预处理的代码。
而这个库安装TensorFlow时并没有手动安装,也没有作为依赖项自动安装,因此怀疑是自动安装依赖库tensorflow-io-gcs-filesystem导致的。
3、检查TensorFlow依赖关系
检查依赖关系需要使用pipdeptree,pipdeptree 是一个命令行工具,用于显示 Python 环境中安装的包及其依赖关系的树状图。可以展示不同包之间的依赖关系,以及哪些包可能间接依赖于其他包。
安装pipdeptree及用之检查TensorFlow的依赖关系的指令及执行情况如下:
(aiStudy) administrator@jwp:~/Desktop/aiStudy$ pip3 install pipdeptree
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pipdeptree
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/41/2c/63ad89d8e01d471b91c0ad4d69ed45f5221f70f3ece6c097beecb7c67f7a/pipdeptree-2.9.6-py3-none-any.whl (19 kB)
Installing collected packages: pipdeptree
Successfully installed pipdeptree-2.9.6
(aiStudy) administrator@jwp:~/Desktop/aiStudy$ pipdeptree | grep tensorflow
tensorflow==2.11.0
- tensorflow-cpu-aws [required: ==2.11.0, installed: 2.11.0]
- tensorflow-estimator [required: >=2.11.0,<2.12, installed: 2.11.0]
- tensorflow-io-gcs-filesystem [required: >=0.23.1, installed: 0.29.0]
可以看到tensorflow依赖tensorflow-cpu-aws,而tensorflow-cpu-aws依赖tensorflow-estimator和tensorflow-io-gcs-filesystem。
卸载tensorflow-io-gcs-filesystem试试:
(aiStudy) administrator@jwp:~/Desktop/aiStudy$ pip3 uninstall tensorflow-io-gcs-filesystem
Found existing installation: tensorflow-io-gcs-filesystem 0.29.0
Uninstalling tensorflow-io-gcs-filesystem-0.29.0:
Would remove:
/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io/*
/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io_gcs_filesystem-0.29.0.dist-info/*
/home/administrator/Desktop/aiStudy/lib/python3.7/site-packages/tensorflow_io_gcs_filesystem/*
Proceed (Y/n)? y
Successfully uninstalled tensorflow-io-gcs-filesystem-0.29.0
卸载成功后重新检测依赖关系:
(aiStudy) administrator@jwp:~/Desktop/aiStudy$ pipdeptree | grep tensorflowWarning!!! Possibly conflicting dependencies found:
* tensorflow-cpu-aws==2.11.0
- tensorflow-io-gcs-filesystem [required: >=0.23.1, installed: ?]
------------------------------------------------------------------------
tensorflow==2.11.0
- tensorflow-cpu-aws [required: ==2.11.0, installed: 2.11.0]
- tensorflow-estimator [required: >=2.11.0,<2.12, installed: 2.11.0]
- tensorflow-io-gcs-filesystem [required: >=0.23.1, installed: ?]
可以看到tensorflow-io-gcs-filesystem 的安装状态为问号,没有安装,但依赖tensorflow-io-gcs-filesystem 的上层库并没受影响,是否影响程序运行暂时未知。
我们重新执行import tensorflow:
(aiStudy) administrator@jiangwenping:~/Desktop/aiStudy$ python3
Python 3.7.3 (default, Oct 13 2023, 10:47:37)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
可以看到正常执行,无警告信息。
四、小结
由于笔者统信UOS机器没有使用tensorflow-io-gcs-filesystem运行环境,但安装TensorFlow却自动安装了tensorflow-io-gcs-filesystem,导致import tensorflow时加载tensorflow_io失败报错,解决办法就是执行pip3 uninstall tensorflow-io-gcs-filesystem卸载tensorflow-io-gcs-filesystem即可。
更多人工智能知识学习请关注专栏《零基础机器学习入门》后续的文章。
更多人工智能知识学习过程中可能遇到的疑难问题及解决办法请关注专栏《机器学习疑难问题集》后续的文章。
写博不易,敬请支持:
如果阅读本文于您有所获,敬请点赞、评论、收藏,谢谢大家的支持!
关于老猿的付费专栏
- 付费专栏《https://blog.csdn.net/laoyuanpython/category_9607725.html 使用PyQt开发图形界面Python应用》专门介绍基于Python的PyQt图形界面开发基础教程,对应文章目录为《 https://blog.csdn.net/LaoYuanPython/article/details/107580932 使用PyQt开发图形界面Python应用专栏目录》;
- 付费专栏《https://blog.csdn.net/laoyuanpython/category_10232926.html moviepy音视频开发专栏 )详细介绍moviepy音视频剪辑合成处理的类相关方法及使用相关方法进行相关剪辑合成场景的处理,对应文章目录为《https://blog.csdn.net/LaoYuanPython/article/details/107574583 moviepy音视频开发专栏文章目录》;
- 付费专栏《https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV-Python初学者疑难问题集》为《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python图形图像处理 》的伴生专栏,是笔者对OpenCV-Python图形图像处理学习中遇到的一些问题个人感悟的整合,相关资料基本上都是老猿反复研究的成果,有助于OpenCV-Python初学者比较深入地理解OpenCV,对应文章目录为《https://blog.csdn.net/LaoYuanPython/article/details/109713407 OpenCV-Python初学者疑难问题集专栏目录 》
- 付费专栏《https://blog.csdn.net/laoyuanpython/category_10762553.html Python爬虫入门 》站在一个互联网前端开发小白的角度介绍爬虫开发应知应会内容,包括爬虫入门的基础知识,以及爬取CSDN文章信息、博主信息、给文章点赞、评论等实战内容。
前两个专栏都适合有一定Python基础但无相关知识的小白读者学习,第三个专栏请大家结合《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python图形图像处理 》的学习使用。
对于缺乏Python基础的同仁,可以通过老猿的免费专栏《https://blog.csdn.net/laoyuanpython/category_9831699.html 专栏:Python基础教程目录)从零开始学习Python。
如果有兴趣也愿意支持老猿的读者,欢迎购买付费专栏。