gpt4 book ai didi

python - 属性错误 : 'module' object has no attribute 'getargspec' while running a main python file of the flask project

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:38 24 4
gpt4 key购买 nike

当我尝试运行我的 flask 项目的 python 文件时。我得到 AttributeError:

'module' object has no attribute 'getargspec'

**Scenario 1:** When tried running the python file of my flask project
-bash-4.2$ python ./main_service.py
Traceback (most recent call last):
File "./main_service.py", line 1, in <module>
from flask import Flask, request, json, Blueprint
File "/usr/lib64/python2.7/site-packages/flask/__init__.py", line 17, in
<module>
from werkzeug.exceptions import abort
File "/usr/lib/python2.7/site-packages/werkzeug/__init__.py", line 20, in
<module>
from werkzeug._compat import iteritems
File "/usr/lib/python2.7/site-packages/werkzeug/_compat.py", line 10, in <module>
import builtins
File "/usr/lib/python2.7/site-packages/builtins/__init__.py", line 8, in <module>
from future.builtins import *
File "/usr/lib/python2.7/site-packages/future/builtins/__init__.py", line 10, in <module>
from future.builtins.iterators import (filter, map, zip)
File "/usr/lib/python2.7/site-packages/future/builtins/iterators.py", line 38, in <module>
from future import utils
File "/usr/lib/python2.7/site-packages/future/utils/__init__.py", line 55, in <module>
import inspect
File "/usr/lib64/python2.7/inspect.py", line 39, in <module>
import tokenize
File "/usr/lib64/python2.7/tokenize.py", line 30, in <module>
from token import *
File "/opt/cDVR/services/token.py", line 2, in <module>
import requests, json
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 47, in <module>
from cryptography import x509
File "/usr/lib64/python2.7/site-packages/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/usr/lib64/python2.7/site-packages/cryptography/x509/base.py", line 14, in <module>
from cryptography import utils
File "/usr/lib64/python2.7/site-packages/cryptography/utils.py", line 70, in <module>
signature = inspect.getargspec
AttributeError: 'module' object has no attribute 'getargspec'
-bash-4.2$



Scenario2: Output of import flask statement in python console
-bash-4.2$ flask --version
Flask 1.0.2
Python 2.7.5 (default, May 31 2018, 09:41:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
-bash-4.2$

-bash-4.2$ python
Python 2.7.5 (default, May 31 2018, 09:41:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/usr/lib/python2.7/site-packages/werkzeug/__init__.py", line 20, in <module>
from werkzeug._compat import iteritems
File "/usr/lib/python2.7/site-packages/werkzeug/_compat.py", line 10, in <module>
import builtins
File "/usr/lib/python2.7/site-packages/builtins/__init__.py", line 8, in <module>
from future.builtins import *
File "/usr/lib/python2.7/site-packages/future/builtins/__init__.py", line 10, in <module>
from future.builtins.iterators import (filter, map, zip)
File "/usr/lib/python2.7/site-packages/future/builtins/iterators.py", line 38, in <module>
from future import utils
File "/usr/lib/python2.7/site-packages/future/utils/__init__.py", line 55, in <module>
import inspect
File "/usr/lib64/python2.7/inspect.py", line 39, in <module>
import tokenize
File "/usr/lib64/python2.7/tokenize.py", line 30, in <module>
from token import *
File "token.py", line 2, in <module>
import requests, json
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 47, in <module>
from cryptography import x509
File "/usr/lib64/python2.7/site-packages/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/usr/lib64/python2.7/site-packages/cryptography/x509/base.py", line 14, in <module>
from cryptography import utils
File "/usr/lib64/python2.7/site-packages/cryptography/utils.py", line 70, in <module>
signature = inspect.getargspec
AttributeError: 'module' object has no attribute 'getargspec'

这个错误与 flask 有什么关系吗?虚拟环境?尝试卸载并重新安装 python。但是,无济于事。感谢对解决问题的评论。提前致谢!!!!!!

最佳答案

正如@CristiFati 所说,您有一个与 Flask 正在使用的东西同名的文件。您需要查看堆栈跟踪以查找代码库中的任何内容,在您的情况下提到了 token.py

如果我这样做(在 shell 中),我会得到类似的错误:

mkdir test
cd test
echo "print('in token.py')" > token.py
python -c 'import flask'

如果我删除这个文件,错误就会消失。

关于python - 属性错误 : 'module' object has no attribute 'getargspec' while running a main python file of the flask project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55936643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com