Python 记录在Ubuntu上的一次模块缺失的摸排检查工作

简介: 记录在Ubuntu上的一次模块缺失的摸排检查工作

记录在Ubuntu上的一次模块缺失的摸排检查工作

#python

ftp123@ubuntutest-virtual-machine:~/Recv/123$ cd ~
ftp123@ubuntutest-virtual-machine:~$ ls
bin  Data  examples.desktop  FtpSend.py  Recv  Snd  src  XY_send_file.sh
ftp123@ubuntutest-virtual-machine:~$ cd bin/
ftp123@ubuntutest-virtual-machine:~/bin$ ls
clear_file.sh
ftp123@ubuntutest-virtual-machine:~/bin$ cd $xy_src
ftp123@ubuntutest-virtual-machine:~/src$ ls
fileRedis.py  FtpSend.py  GetRedis.py
ftp123@ubuntutest-virtual-machine:~/src$ ll
total 28
drwxrwxr-x  2 ftp123 ftp123 4096 12月 22 09:51 ./
drwxr-xr-x 10 ftp123 ftp123 4096 12月 24 09:07 ../
-rw-rw-r--  1 ftp123 ftp123 2130 12月 22 09:39 fileRedis.py
-rw-rw-r--  1 ftp123 ftp123 5404 12月 22 09:39 FtpSend.py
-rw-rw-r--  1 ftp123 ftp123 6277 12月 22 09:39 GetRedis.py
# ---------------------------------------------------------------------
# 这里开始作为使用python并且发现没有找到redis模块的问题的开始
ftp123@ubuntutest-virtual-machine:~/src$ python fileRedis.py 
  File "fileRedis.py", line 7
SyntaxError: Non-ASCII character '\xe7' in file fileRedis.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
ftp123@ubuntutest-virtual-machine:~/src$ ^C
ftp123@ubuntutest-virtual-machine:~/src$ python fileRedis.py 
Traceback (most recent call last):
  File "fileRedis.py", line 3, in <module>
    import GetRedis
  File "/home/ftp123/src/GetRedis.py", line 4, in <module>
    import redis
ImportError: No module named redis
# 问题现象描述结束
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# 第一次尝试使用pip安装redis
ftp123@ubuntutest-virtual-machine:~/src$ pip install redis
Command 'pip' not found, but can be installed with:
apt install python-pip
Please ask your administrator.
# 显示系统并没有安装pip命令,所以转而进行pip的安装
ftp123@ubuntutest-virtual-machine:~/src$ apt install python-pip
# 以下为系统安装 pip 过程
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
ftp123@ubuntutest-virtual-machine:~/src$ su - 
Password: 
root@ubuntutest-virtual-machine:~# apt install python-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...
# pip 安装完毕,开始使用pip安装redis         
root@ubuntutest-virtual-machine:~# pi
pi1toppm         pico             pinentry         pinentry-x11     ping6            pivot_root
pi3topbm         piconv           pinentry-curses  ping             pinky            
pic              pidof            pinentry-gnome3  ping4            pip3 
# 这里其实已经有隐形提示,在一般情况下pip命令是只有pip的。
# 当出现 pip3 的情况下,就说明了此时系统上装有Python2 和 Python3 两个版本。
# 使用pip3 安装redis
root@ubuntutest-virtual-machine:~# pip3 install redis
Collecting redis
  Downloading https://files.pythonhosted.org/packages/b1/9c/838dbabd16f7dad05d3b83abad11560a2c6cc72fe913a02fa487fc915b9d/redis-4.0.2-py3-none-any.whl (119kB)
    25% |████████▏                       | 30kB 1.5kB/s eta 0:01:01Exception:
...
error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
# 因为网络问题第一次安装失败。
# 这里开始确认系统上有没有redis环境
root@ubuntutest-virtual-machine:~# find / -name redis*
/var/log/redis
/var/log/redis/redis-server.log.4.gz
/var/log/redis/redis-server.log
...
^C
# 这里通过查找确认了本地有redis 库文件。所以退出再次重试
root@ubuntutest-virtual-machine:~# exit
logout
ftp123@ubuntutest-virtual-machine:~/src$ python fileRedis.py 
Traceback (most recent call last):
  File "fileRedis.py", line 3, in <module>
    import GetRedis
  File "/home/ftp123/src/GetRedis.py", line 4, in <module>
    import redis
ImportError: No module named redis
# 依旧显示库缺失,和可以使用的用户确认本地环境变量的差异性。无误
# 选择再次安装Python的 redis库。
ftp123@ubuntutest-virtual-machine:~/src$ vi ~/.profile 
ftp123@ubuntutest-virtual-machine:~/src$ su -
Password: 
# 使用root用户 第二次安装
root@ubuntutest-virtual-machine:~# pip3 install redis
Collecting redis
  Downloading
   ...
Successfully installed deprecated-1.2.13 redis-4.0.2 wrapt-1.13.3
# 这里安装完毕,不再急于启动程序,首先通过python 尝试调用库。
root@ubuntutest-virtual-machine:~# python 
Python 2.7.17 (default, Feb 27 2021, 15:10:58) 
# 其实这里就已经有答案了,我通过find查找到的redis库是通过pip3安装的,路径在Python3.6下
# 但是这里的版本是2.7 。存在多个版本的时候特别是2和3都有的情况下,一定要使用Python2或Python3来指定版本。
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named redis
>>> q
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'q' is not defined
>>> 
KeyboardInterrupt
>>> 
KeyboardInterrupt
>>> import redis
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named redis
>>> 
[1]+  Stopped                 python
# 想要看看在这个安装路径下调用可不可以,因为python的特性是先在当前目录下寻找。
root@ubuntutest-virtual-machine:~# cd anaconda3/lib/python3.7/site-packages/redis-3.5.3.dist-info/METADATA
-su: cd: anaconda3/lib/python3.7/site-packages/redis-3.5.3.dist-info/METADATA: No such file or directory
# 成功使用的正确方式
# 前提安装完成redis
ftp123@ubuntutest-virtual-machine:~/src$ python3 fileRedis.py 
{'type': 'message', 'pattern': None, 'channel': b'second_product', 'data': b'20210606000000'}
send 20210606000000.bz2 end


再附赠解决国内链接GitHub网络不稳的解决方式:


怎么解决Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection

遇到该问题的表象: 原因是连接超时,所以需要自己设定安装源,

9f0c56a0383bde9a9ffb77dbe23e31e6_8f31366eb3e24baaa38815ae92db22c6.png

root@ubuntutest-virtual-machine:~# pip install requests -i http://pypi.douban.com/simple --trusted-host pypi.douban.com(通过豆瓣)
root@ubuntutest-virtual-machine:~# pip install xxx -i https://pypi.tuna.tsinghua.edu.cn/simple(使用清华镜像)

成功表现:

049affaa9a558cc7e0113bc7646c567d_113d9fea7a414f0dbc39cefe621e8b25.png

目录
相关文章
|
7月前
|
SQL 关系型数据库 数据库
Python SQLAlchemy模块:从入门到实战的数据库操作指南
免费提供Python+PyCharm编程环境,结合SQLAlchemy ORM框架详解数据库开发。涵盖连接配置、模型定义、CRUD操作、事务控制及Alembic迁移工具,以电商订单系统为例,深入讲解高并发场景下的性能优化与最佳实践,助你高效构建数据驱动应用。
896 7
|
7月前
|
监控 安全 程序员
Python日志模块配置:从print到logging的优雅升级指南
从 `print` 到 `logging` 是 Python 开发的必经之路。`print` 调试简单却难维护,日志混乱、无法分级、缺乏上下文;而 `logging` 支持级别控制、多输出、结构化记录,助力项目可维护性升级。本文详解痛点、优势、迁移方案与最佳实践,助你构建专业日志系统,让程序“有记忆”。
634 0
|
7月前
|
JSON 算法 API
Python中的json模块:从基础到进阶的实用指南
本文深入解析Python内置json模块的使用,涵盖序列化与反序列化核心函数、参数配置、中文处理、自定义对象转换及异常处理,并介绍性能优化与第三方库扩展,助你高效实现JSON数据交互。(238字)
621 4
|
8月前
|
安全 大数据 程序员
Python operator模块的methodcaller:一行代码搞定对象方法调用的黑科技
`operator.methodcaller`是Python中处理对象方法调用的高效工具,替代冗长Lambda,提升代码可读性与性能。适用于数据过滤、排序、转换等场景,支持参数传递与链式调用,是函数式编程的隐藏利器。
252 4
|
7月前
|
Java 调度 数据库
Python threading模块:多线程编程的实战指南
本文深入讲解Python多线程编程,涵盖threading模块的核心用法:线程创建、生命周期、同步机制(锁、信号量、条件变量)、线程通信(队列)、守护线程与线程池应用。结合实战案例,如多线程下载器,帮助开发者提升程序并发性能,适用于I/O密集型任务处理。
713 0
|
7月前
|
XML JSON 数据处理
超越JSON:Python结构化数据处理模块全解析
本文深入解析Python中12个核心数据处理模块,涵盖csv、pandas、pickle、shelve、struct、configparser、xml、numpy、array、sqlite3和msgpack,覆盖表格处理、序列化、配置管理、科学计算等六大场景,结合真实案例与决策树,助你高效应对各类数据挑战。(238字)
1002 0
|
8月前
|
存储 数据库 开发者
Python SQLite模块:轻量级数据库的实战指南
本文深入讲解Python内置sqlite3模块的实战应用,涵盖数据库连接、CRUD操作、事务管理、性能优化及高级特性,结合完整案例,助你快速掌握SQLite在小型项目中的高效使用,是Python开发者必备的轻量级数据库指南。
717 0
|
9月前
|
存储 安全 数据处理
Python 内置模块 collections 详解
`collections` 是 Python 内置模块,提供多种高效数据类型,如 `namedtuple`、`deque`、`Counter` 等,帮助开发者优化数据处理流程,提升代码可读性与性能,适用于复杂数据结构管理与高效操作场景。
565 0
|
10月前
|
数据安全/隐私保护 Python
抖音私信脚本app,协议私信群发工具,抖音python私信模块
这个实现包含三个主要模块:抖音私信核心功能类、辅助工具类和主程序入口。核心功能包括登录
|
Python
Python教程:os 与 sys 模块详细用法
os 模块用于与操作系统交互,主要涉及夹操作、路径操作和其他操作。例如,`os.rename()` 重命名文件,`os.mkdir()` 创建文件夹,`os.path.abspath()` 获取文件绝对路径等。sys 模块则用于与 Python 解释器交互,常用功能如 `sys.path` 查看模块搜索路径,`sys.platform` 检测操作系统等。这些模块提供了丰富的工具,便于开发中处理系统和文件相关任务。
540 14