from exceptions import PendingDeprecationWarning ModuleNotFoundError: No module named 'exceptions'
时间: 2023-12-21 19:32:13 浏览: 405
根据你提供的引用内容,报错信息显示没有找到名为'exceptions'的模块。这是因为在Python 3中,'exceptions'模块已被取消,取而代之的是直接使用内置的异常类。所以,你不需要导入'exceptions'模块。
如果你想使用'PendingDeprecationWarning'异常类,你可以直接使用它,而无需导入任何模块。以下是一个示例代码:
```python
import warnings
warnings.warn("This is a pending deprecation warning.", PendingDeprecationWarning)
```
这段代码会发出一个'PendingDeprecationWarning'警告。请注意,警告只是提醒你某些功能将来可能会被弃用,但并不会导致程序终止。
相关问题
from exceptions import PendingDeprecationWarning ModuleNotFoundError: No module named 'exceptions'
根据你提供的引用内容,`from exceptions import PendingDeprecationWarning` 这行代码引发了一个 `ModuleNotFoundError: No module named 'exceptions'` 错误。这是因为在 Python 3 中已经取消了 `exceptions` 模块。然而, `PendingDeprecationWarning` 是一个内置的警告类型,可以直接使用,无需导入任何模块。因此,你可以直接使用 `PendingDeprecationWarning`,而不需要导入 `exceptions` 模块。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [Python3 读取Word文件方式](https://download.csdn.net/download/weixin_38729336/14851368)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [No module named 'exceptions'](https://blog.csdn.net/vah101/article/details/79914968)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
30 from exceptions import PendingDeprecationWarning 31 from warnings import warn 32 ModuleNotFoundError: No module named 'exceptions'
这个错误是因为你在导入模块时使用了错误的模块名称。在 Python 2 中,有一个名为 `exceptions` 的内置模块,但在 Python 3 中已经被移除了。相反,在 Python 3 中,异常被定义为内置的异常类,而不是在 `exceptions` 模块中定义的。因此,如果你想在 Python 3 中使用 `PendingDeprecationWarning` 异常,你应该从 `warnings` 模块导入它,而不是从 `exceptions` 模块导入。所以你应该这样导入:
```python
from warnings import warn, PendingDeprecationWarning
```
这样就可以避免这个错误了。
阅读全文
相关推荐











