python-3.x – 没有名为’urlparse’的模块,但我没有使用urlpars
发布时间:2020-12-20 11:04:22 所属栏目:Python 来源:网络整理
导读:我试图弄清楚为什么我看到错误ModuleNotFoundError:没有名为’urlparse’的模块,但我从未在我的代码中调用urlparse.当我尝试用pip安装urlparse时,我发现这个模块不存在.当我尝试使用pip安装urllib.parse时,我看到了与urllib.parse相同的消息.找不到urllib.p
我试图弄清楚为什么我看到错误ModuleNotFoundError:没有名为’urlparse’的模块,但我从未在我的代码中调用urlparse.当我尝试用pip安装urlparse时,我发现这个模块不存在.当我尝试使用pip安装urllib.parse时,我看到了与urllib.parse相同的消息.找不到urllib.parse的匹配分布.
我在这里错过了什么? from flask import Flask,request,redirect,url_for,session,g,flash, render_template from flask_oauth import OAuth from sqlalchemy import create_engine,Column,Integer,String from sqlalchemy.orm import scoped_session,sessionmaker from sqlalchemy.ext.declarative import declarative_base # configuration SECRET_KEY = 'development key' DEBUG = True # setup flask app = Flask(__name__) app.debug = DEBUG app.secret_key = SECRET_KEY oauth = OAuth() # Use Twitter as example remote app twitter = oauth.remote_app('twitter',base_url='https://api.twitter.com/1/',request_token_url='https://api.twitter.com/oauth/request_token',access_token_url='https://api.twitter.com/oauth/access_token',authorize_url='https://api.twitter.com/oauth/authenticate',consumer_key='',consumer_secret='' ) @twitter.tokengetter def get_twitter_token(token=None): return session.get('twitter_token') @app.route('/') def index(): access_token = session.get('access_token') if access_token is None: return redirect(url_for('login')) access_token = access_token[0] return render_template('templates/index.html') if __name__ == '__main__': app.run() 解决方法
flask_oauth库不支持Python3 – 您将从traceback中看到:
Traceback (most recent call last): File "app.py",line 3,in <module> from flask_oauth import OAuth File "/Users/matthealy/virtualenvs/test/lib/python3.6/site-packages/flask_oauth.py",line 13,in <module> from urlparse import urljoin ModuleNotFoundError: No module named 'urlparse' 在Python 3中更改了urlparse模块的行为: https://docs.python.org/2/library/urlparse.html
这是在Github上使用软件包维护者提出的.Github上的源代码看起来是固定的,但修复版本还没有被推送到pypi. 在Github上建议的解决方案是直接从源代码而不是pypi安装: pip install git+https://github.com/mitsuhiko/flask-oauth (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |