MacOS: Problem with run aiosqlite for any DB
See original GitHub issueProblem with run aiosqlite for any DB at MacOS
MacOS (macOS Big Sur, version 11.1 (20C69):
ModuleNotFoundError: No module named ‘aiosqlite’
Python 3.9 ===== FastAPI ===== SQLite ===== Databases ===== aiosqlite
Description
Test project on FastAPI - including from the example: https://fastapi.tiangolo.com/advanced/async-sql-databases/
Example My Code:
from typing import List
import databases
import sqlalchemy
from fastapi import FastAPI
from pydantic import BaseModel
DATABASE_URL = "sqlite:///./test.db"
database = databases.Database(DATABASE_URL)
metadata = sqlalchemy.MetaData()
notes = sqlalchemy.Table(
"notes",
metadata,
sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
sqlalchemy.Column("text", sqlalchemy.String),
sqlalchemy.Column("completed", sqlalchemy.Boolean),
)
# engine = sqlalchemy.create_engine(
# DATABASE_URL, connect_args={"check_same_thread": False}
# )
# metadata.create_all(engine)
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
Start:
Activate virtual environment:
$ pip3 -m venv venv
$ source ./venv/bin/activate
Set dependencies:
$ pip3 install aiosqlite, databases, fastapi
Look the installed dependencies:
$ pip3 list
Package Version
----------------- --------
aiosqlite 0.17.0
databases 0.4.3
fastapi 0.63.0
pip 21.1.1
pydantic 1.8.1
setuptools 56.0.0
SQLAlchemy 1.3.24
starlette 0.13.6
typing-extensions 3.10.0.0
Start server:
$ uvicorn main:app --reload
The server won’t start On Mac OS (any editor: vim, VS Code, “Pycharm”, etc.)
ERROR shell:
(env) ➜ testDB2 uvicorn main:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [2967] using statreload
Process SpawnProcess-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/subprocess.py", line 62, in subprocess_started
target(sockets=sockets)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/main.py", line 390, in run
loop.run_until_complete(self.serve(sockets=sockets))
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/main.py", line 397, in serve
config.load()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/config.py", line 278, in load
self.loaded_app = import_from_string(self.app)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/importer.py", line 23, in import_from_string
raise exc from None
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/uvicorn/importer.py", line 20, in import_from_string
module = importlib.import_module(module_str)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/alexneo/Documents/GIT/FastAPI/testDB2/./main.py", line 11, in <module>
database = databases.Database(DATABASE_URL)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/databases/core.py", line 66, in __init__
backend_cls = import_from_string(backend_str)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/databases/importer.py", line 21, in import_from_string
raise exc from None
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/databases/importer.py", line 18, in import_from_string
module = importlib.import_module(module_str)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/databases/backends/sqlite.py", line 5, in <module>
import aiosqlite
ModuleNotFoundError: No module named 'aiosqlite'
All of the dependencies are exist and I’ve can click them and moved to these dependencies file!!! And ‘aiosqlite’ too!
on Linux, everything works OK
but on a MacOS I can not run any of the databases (example SQLITE)
The error is as follows: does not see “aiosqlite”! All of the requirements have been seated correct (Python 3.9.5, venv, pip, aiosqlite, sqlalchemy, databases etc. - all of this have been updated)
This problem at StackOverflow:
https://stackoverflow.com/questions/67406165/macos-problem-with-run-aiosqlite-for-any-db
This solution hasn’t worked to my fail:
https://question-it.com/questions/467425/kak-ja-mogu-zapustit-server-fast-api-ispolzuja-pycharm
Screenshots:
- Error https://i.stack.imgur.com/r50bg.jpg
- Dependencies https://i.stack.imgur.com/OeBD9.jpg
- Pip List https://i.stack.imgur.com/KbFRB.jpg
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top GitHub Comments
Dear @NeoSPU:
databases
isn’t part of the standard library, yet you don’t install it, and yet you are able to import it and you can see in the tracebacks that its code is being run.) That means that it is somehow available as part of your system site-packages, as I mentioned before. (The same stands forsqlalchemy
- your code seems to use it, yet you don’t install it.)Please run
python3 -m pip list
outside any virtualenv and let us know the output. On a “venv-clean” system it should have little more thanpip
,wheel
,setuptools
.@akx Aarni Koskela
Yes!
You are right!
I’ve fixed my solution!
The solution is next:
**requirements.txt:
Thank you!