from csv import QUOTE_NONNUMERIC ImportError: cannot import name 'QUOTE_NONNUMERIC' from 'csv' (C:\Users\Administrator\Desktop\test\csv.py)
时间: 2023-07-22 21:09:39 浏览: 206
这个错误通常是由于你的代码文件名与Python标准库模块名重名导致的。在你的代码中,你尝试从 csv 模块导入 QUOTE_NONNUMERIC,但是导入失败了,并且错误信息显示它从 'csv' (C:\Users\Administrator\Desktop\test\csv.py) 导入了。
为了解决这个问题,你可以采取以下几种方法:
1. 避免使用与Python标准库模块相同的文件名。将你的代码文件命名为其他名称,避免与Python标准库模块名重复。
2. 检查你的代码中是否有其他文件与 csv.py 文件同名。如果有,将其重命名为其他名称。
3. 如果你确实需要使用名为 csv.py 的文件,可以尝试使用绝对导入来导入 Python 标准库的 csv 模块。例如,改为使用 `import csv` 来导入 csv 模块。
请注意,当你的代码文件与Python标准库模块重名时,Python会优先导入同名的文件而不是标准库模块。因此,将代码文件命名为与标准库模块不同的名称是一个良好的实践。
相关问题
from urllib import quote_plus ImportError: cannot import name 'quote_plus' from 'urllib'
`quote_plus` is a function that is present in the `urllib.parse` module in Python 3.x. It seems like you are using Python 2.x, where this function is present in the `urllib` module. However, the correct way to import it in Python 2.x is:
```python
from urllib import quote_plus
```
If you are still facing issues, please check if you are using the correct version of Python and if the module is installed correctly.
from flask import current_app ImportError: cannot import name 'current_app'
This error message indicates that there is an issue with importing the `current_app` object from the `flask` module. This object is used to access the current Flask application instance, and is typically used in a context where the application instance is not available through other means.
There are a few possible reasons why you might encounter this error:
1. You may be importing `current_app` from the wrong module. Make sure that you are importing it from the `flask` module and not another module with a similar name.
2. You may be importing `current_app` before the Flask application has been created. `current_app` is only available when a Flask application context is active, so if you try to import it outside of a request or application context, you will get this error. Make sure that you are importing `current_app` from within a Flask view function, or from within a function that is called within a Flask view function.
3. There may be a circular import issue in your application. Flask applications can be prone to circular import issues if you're not careful about how you structure your code. If you're importing `current_app` from a module that also imports something from the module where your Flask application instance is created, you may run into this error. Try restructuring your code to avoid circular imports.
To resolve this error, you should check your code for the above issues and make sure that you are importing `current_app` correctly and in the right context. You may also want to review the Flask documentation on application context and request context to better understand how they work.
阅读全文