首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模组烧瓶不会启动

模组烧瓶不会启动
EN

Stack Overflow用户
提问于 2019-05-28 06:10:54
回答 1查看 235关注 0票数 1

项目解释器和本地env映像我在使用模块烧瓶时遇到了一个真正的问题,我已经在论坛上尝试了很多解决方案,但是都没有奏效。

我可以看到烧瓶是已安装的pip列表??在设置中显示烧瓶,当我键入代码时,模块烧瓶被安装在项目解释器中,我可以看到模块出现。

然而,当我启动代码时,我会得到一个错误

没有名为“烧瓶”的模块

我试着重新安装py魅力,我试着卸载并再次安装烧瓶,仍然是同样的问题。有什么建议吗?

文件名vsearch.py

以下是代码:

代码语言:javascript
复制
from flask import Flask, render_template, request, escape

app = Flask(__name__)

def search4words(phrase: str, letters: str) -> set:
    return set(letters).intersection(set(phrase))

def log_request(req: 'flask_request', res: str) -> None:
    with open('vsearch.log', 'a') as log:
        print(req.form, req.remote_addr, req.user_agent, res, file=log, 
        sep='|')

@app.route('/search4', methods=['POST'])
def do_search() -> 'html':
    phrase = request.form['phrase']
    letters = request.form['letters']
    title = 'Here are your results:'
    results = str(search4words(phrase, letters))
    log_request(request, results)
    return render_template('results.html', the_phrase=phrase, 
                           the_letters=letters, the_title=title, 
                           the_results=results,)

@app.route('/')
@app.route('/entry')
def entry_page() -> 'html':
    return render_template('entry.html', the_title='Welcome back 
    AGAIN!!!!!')

@app.route('/viewlog')
def view_the_log() -> 'html':
    contents = []
    with open('vsearch.log') as log:
        for line in log:
            contents.append([])
            for item in line.split('|'):
                 contents[-1].append(escape(item))
    titles = ('Form Data', 'Remote_addr', 'User_agent', 'Results')
    return render_template('viewlog.html',
                           the_title = 'View log',
                           the_row_titles = titles,
                           the_data = contents,)

if __name__ == '__main__' :
    app.run(debug=True)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-28 06:25:12

您的问题是试图通过终端运行vsearch.py,而不是通过PyCharm的解释器(正确安装)。为了利用虚拟环境,您应该将其配置为在运行代码时正确使用它。

激活虚拟环境有多种方法,因此请找到适用于您的项目的方法。这方面的一个很好的来源是https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56335986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档