英文:
Python: ModuleNotFoundError: No module named Rich
问题
I am trying to use rich module to draw table in python3.9 in Linux.
However, I am getting:
Traceback (most recent call last):
File "/opt/audit.py", line 12, in
from rich.table import Table
ModuleNotFoundError: No module named 'rich'
I have both python 2.7 and 3.9 installed.
Command I run: python3.9 /opt/audit.py
I have verified I have rich installed.
python3.9 -m pip list
Package Version
ansitable 0.9.7
colored 2.2.2
markdown-it-py 3.0.0
mdurl 0.1.2
pip 22.0.4
Pygments 2.15.1
rich 13.4.2
setuptools 58.1.0
python3.9 -m pip install rich --upgrade
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: rich in /disk2/users/python3.9/site-packages (13.4.2)
Requirement already satisfied: markdown-it-py>=2.2.0 in /disk2/users/python3.9/site-packages (from rich) (3.0.0)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /disk2/users/python3.9/site-packages (from rich) (2.15.1)
Requirement already satisfied: mdurl~=0.1 in /disk2/users/python3.9/site-packages (from markdown-it-py>=2.2.0->rich) (0.1.2)
This is the start of the file and it fails on line 12:
import cx_Oracle
import configparser
import json
import os
import requests
import smtplib
from rich.table import Table
from email.message import EmailMessage
from pathlib import Path
英文:
I am trying to use rich module to draw table in python3.9 in Linux.
However, I am getting:
Traceback (most recent call last):
File "/opt/audit.py", line 12, in <module>
fom rich.table import Table
ModuleNotFoundError: No module named 'rich'
I have both python 2.7 and 3.9 installed.
Command I run: python3.9 /opt/audit.py
I have verified I have rich installed.
python3.9 -m pip list
Package Version
-------------- -------
ansitable 0.9.7
colored 2.2.2
markdown-it-py 3.0.0
mdurl 0.1.2
pip 22.0.4
Pygments 2.15.1
rich 13.4.2
setuptools 58.1.0
python3.9 -m pip install rich --upgrade
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: rich in /disk2/users/python3.9/site-packages (13.4.2)
Requirement already satisfied: markdown-it-py>=2.2.0 in /disk2/users/python3.9/site-packages (from rich) (3.0.0)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /disk2/users/python3.9/site-packages (from rich) (2.15.1)
Requirement already satisfied: mdurl~=0.1 in /disk2/users/python3.9/site-packages (from markdown-it-py>=2.2.0->rich) (0.1.2)
This is the start of the file and it fails on line 12:
import cx_Oracle
import configparser
import json
import os
import requests
import smtplib
from rich.table import Table
from email.message import EmailMessage
from pathlib import Path
答案1
得分: 1
如果该软件包已正确安装,有可能是由于某些配置错误,python3 未加载安装在该路径上的软件包。
您可以通过检查模块由pip安装到何处来开始故障排除:
$ python3 -m pip show rich
Name: rich
Version: 13.4.2
Summary: 渲染富文本、表格、进度条、语法高亮、Markdown等到终端
Home-page: https://github.com/Textualize/rich
Author: Will McGugan
Author-email: willmcgugan@gmail.com
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages
Requires: markdown-it-py, pygments
Required-by:
如果Location
路径也出现在下面的sys.path
列表中,这意味着该路径是全局site-packages目录的一部分,Python应该能够在解释器运行时找到该模块:
$ python3 -m site
sys.path = [
'/Users/Admin/workspace',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python311.zip',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages',
]
USER_BASE: '/Users/Admin/Library/Python/3.11' (不存在)
USER_SITE: '/Users/Admin/Library/Python/3.11/lib/python/site-packages' (不存在)
ENABLE_USER_SITE: True
如您在此示例中所见,Location
路径是sys.path
的最后一个条目。但是,如果它不在其中,有可能会在用户site-packages目录中列出:
$ python3 -m site --user-site
如果Location
路径在这些site-packages中都不存在,那么您可以尝试将该路径添加到其中一个。但此时我会认真质疑您的Python安装的完整性。
英文:
If that package has been installed correctly, it is possible that python3 is not loading packages installed on that path due to some misconfiguration.
You can start troubleshooting by checking where the module was installed by pip:
$ python3 -m pip show rich
Name: rich
Version: 13.4.2
Summary: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal
Home-page: https://github.com/Textualize/rich
Author: Will McGugan
Author-email: willmcgugan@gmail.com
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages
Requires: markdown-it-py, pygments
Required-by:
If the Location
path is also present in the sys.path
list below, it means that this path is part of the global site-packages directories and python should be able to find the module when the interpreter runs:
$ python3 -m site
sys.path = [
'/Users/Admin/workspace',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python311.zip',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages',
]
USER_BASE: '/Users/Admin/Library/Python/3.11' (doesn't exist)
USER_SITE: '/Users/Admin/Library/Python/3.11/lib/python/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
As you can see in this example, the Location
path is the last entry on sys.path
. However, if it's not in there, there's a chance it might be listed by the user site-package directories:
$ python3 -m site --user-site
If the Location
path is not present in either of these site-packages, then you can try to add that path to one of them. But at this point I would seriously question the integrity of your python installation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论