ImportERROR: из. import postgresql, mysql, sqlite, ms sql, oracle # pragma: no cover ImportError: невозможно импортировать имя 'mysql' - PullRequest
0 голосов
/ 05 мая 2020

Я пытаюсь использовать приложение flask в своем Интернете.

Я установил Flask, Flask -Session, psycopg2-binary и SQLAlchemy

После этого я пробую простой код из flask

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

Ожидаемый результат - это ссылка для открытия моего flask приложения, но после выполнения 'flask run' на моем терминале я получаю эту ошибку

Traceback (most recent call last):
  File "/home/xenoveals/.local/bin/flask", line 11, in <module>
    sys.exit(main())
  File "/home/xenoveals/.local/lib/python3.6/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 781, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 700, in make_context
    self.parse_args(ctx, args)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 1209, in parse_args
    echo(ctx.get_help(), color=ctx.color)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 570, in get_help
    return self.command.get_help(self)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 975, in get_help
    self.format_help(ctx, formatter)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 1003, in format_help
    self.format_options(ctx, formatter)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 1137, in format_options
    self.format_commands(ctx, formatter)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/click/core.py", line 1184, in format_commands
    for subcommand in self.list_commands(ctx):
  File "/home/xenoveals/.local/lib/python3.6/site-packages/flask/cli.py", line 549, in list_commands
    self._load_plugin_commands()
  File "/home/xenoveals/.local/lib/python3.6/site-packages/flask/cli.py", line 523, in _load_plugin_commands
    self.add_command(ep.load(), ep.name)
  File "/home/xenoveals/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2446, in load
    return self.resolve()
  File "/home/xenoveals/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2452, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/flask_migrate/__init__.py", line 8, in <module>
    from alembic import __version__ as __alembic_version__
  File "/usr/lib/python3/dist-packages/alembic/__init__.py", line 9, in <module>
    from . import context  # noqa
  File "/usr/lib/python3/dist-packages/alembic/context.py", line 1, in <module>
    from .runtime.environment import EnvironmentContext
  File "/usr/lib/python3/dist-packages/alembic/runtime/environment.py", line 2, in <module>
    from .migration import MigrationContext
  File "/usr/lib/python3/dist-packages/alembic/runtime/migration.py", line 12, in <module>
    from .. import ddl, util
  File "/usr/lib/python3/dist-packages/alembic/ddl/__init__.py", line 1, in <module>
    from . import postgresql, mysql, sqlite, mssql, oracle  # pragma: no cover
ImportError: cannot import name 'mysql'

1 Ответ

0 голосов
/ 05 мая 2020

В конце звоните app.run(). Или лучше

if __name__ = '__main__':
    app.run()

Вы можете изменить port, если хотите, это app.run(port=5000)

...