Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'asyncmy' despite being installed #46

Closed
fagirton opened this issue Oct 22, 2022 · 4 comments
Closed

Comments

@fagirton
Copy link

When trying to make revision with Alembic it gives error like this:

Traceback (most recent call last):                                                                                           
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\alembic.exe\__main__.py", line 7, in <module>
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\config.py", line 590, in main
    CommandLine(prog=prog).main(argv=argv)
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\config.py", line 584, in main
    self.run_cmd(cfg, options)
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\config.py", line 561, in run_cmd
    fn(
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\command.py", line 229, in revision
    script_directory.run_env()
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\script\base.py", line 569, in run_env
    util.load_python_file(self.dir, "env.py")
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\util\pyfiles.py", line 94, in load_python_file
    module = load_module_py(module_id, path)
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alembic\util\pyfiles.py", line 110, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "sql_app/migrations\env.py", line 11, in <module>
    from sql_app.database import Base
  File "H:\GitHub\Smart_yard_Backend_server\.\sql_app\database.py", line 9, in <module>
    engine = create_engine(
  File "<string>", line 2, in create_engine
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\create.py", line 548, in create_engine
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "C:\Users\fagir\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\mysql\asyncmy.py", line 291, in dbapi
    return AsyncAdapt_asyncmy_dbapi(__import__("asyncmy"))
ModuleNotFoundError: No module named 'asyncmy'

After that I found this repository and reinstalled it with steps needed on Windows, but nothing changed.
Using asyncmy with SQLAlchemy ORM mode

@calebporto2
Copy link

calebporto2 commented Dec 19, 2022

I am also having the same problem. I reinstalled the library, but it didn't work.

Updating:
My problem happened while I was using virtualenv. I disabled the virtualenv, installed the library on the pc itself, reactivated the virtualenv and ran the code, and everything worked normally.
The problem is in the sqlalchemy.dialects.mysql.asyncmy module, which does not correctly specify the path to the asyncmy module while using virtual environment. Hope they fix it.

@ifduyue
Copy link

ifduyue commented Feb 6, 2023

Similar issue here, but a little different

...clip...
  File "/srv/app/app/db/session.py", line 47, in <module>
    async_engine = create_async_engine(
                   ^^^^^^^^^^^^^^^^^^^^
  File "/srv/app/.venv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/engine.py", line 43, in create_async_engine
    sync_engine = _create_engine(*arg, **kw)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in create_engine
  File "/srv/app/.venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/srv/app/.venv/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 548, in create_engine
    dbapi = dialect_cls.dbapi(**dbapi_args)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/app/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/asyncmy.py", line 291, in dbapi
    return AsyncAdapt_asyncmy_dbapi(__import__("asyncmy"))
                                    ^^^^^^^^^^^^^^^^^^^^^
  File "/srv/app/.venv/lib/python3.11/site-packages/asyncmy/__init__.py", line 1, in <module>
    from .connection import Connection, connect  # noqa:F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'asyncmy.connection'
$ ls /srv/app/.venv/lib/python3.11/site-packages/asyncmy/
__init__.py  auth.py      charset.pyx     constants    converters.pyx  errors.pyx     pool.pyx      replication  version.py
__pycache__  charset.pxd  connection.pyx  contexts.py  cursors.pyx     optionfile.py  protocol.pyx  structs.py

After pip install asyncmy==0.2.5, *.pyx weren't compiled. I'm using Python 3.11 and venv.

@matan1008
Copy link

matan1008 commented Feb 6, 2023

Same as @ifduyue, but without venv and on the latest release

@long2ice
Copy link
Owner

long2ice commented Feb 6, 2023

dup of #50

@long2ice long2ice closed this as completed Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants