我安装烧瓶pipenv,但不能导入该包。
蟒3.6.8,2018年11月26日pipenv
$ pipenv install flask
Installing flask…
Adding flask to Pipfile's [packages]…
Installing dependencies from Pipfile.lock (a18377)…
✔ Installation Succeeded
▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 29/29 — 00:00:0603
(env) $ python -c 'import flask'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'flask'
,但看起来像烧瓶安装:
(env) $ flask --help
Traceback (most recent call last):
File ".../.virtualenvs/env-vop2XA0b/lib/python3.6/site-packages/flask/cli.py", line 529, in list_commands
rv.update(info.load_app().cli.list_commands(ctx))
File ".../virtualenvs/env-vop2XA0b/lib/python3.6/site-packages/flask/cli.py", line 384, in load_app
'Could not locate a Flask application. You did not provide '
flask.cli.NoAppException: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Usage: flask [OPTIONS] COMMAND [ARGS]...
A general utility script for Flask applications.
Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
will enable debug mode.
$ export FLASK_APP=hello.py
$ export FLASK_ENV=development
$ flask run
Options:
--version Show the flask version
--help Show this message and exit.
Commands:
routes Show the routes for the app.
run Runs a development server.
shell Runs a shell in the app context.
和
(env) $ which flask
path/to/.virtualenvs/env-vop2XA0b/bin/flask
我与virtualenv
的行为相同
这是怎么回事呢?
答案 0 :(得分:0)
它看起来像您使用pipenv安装包,但是,你必须加入pipenv创建的虚拟环境,实际使用安装的软件包。
首先,使用安装包pipenv install flask
现在,您有两个选择可以在安装了flask的虚拟环境中运行任何内容。
pipenv run flask
- 这将直接运行烧瓶命令,而不需要你到源虚拟环境
pipenv shell
和python -c 'import flask'
- 这将工作完全一样虚拟环境中,通过获取所述虚拟环境,然后使用它的运行蟒