I tried to import sqlalchemy to my pytest file but when I tried to run it shows this error, even though I have already installed sqlalchemy.
new.py:1: in <module>
import sqlalchemy
E ImportError: No module named sqlalchemy
my code :
import pytest
import sqlalchemy
the code was just when I was importing the sqlalchemy.
How do I fix it? Thanks in advance
I had the same, and fixed by running tests with:
python -m pytest .
Related
im unable to import sqlalchemy and psycopg2 libraries into my python code while using VSCode tool. it throws the following errors:
(module) sqlalchemy
Import "sqlalchemy" could not be resolved from sourcePylancereportMissingModuleSource
No quick fixes available
Import "psycopg2" could not be resolved from sourcePylancereportMissingModuleSourc
heres the code:
I try to import class ClickHouseHook from airflow.hooks.clickhouse_hook
from airflow.hooks.clickhouse_hook import ClickHouseHook
This is no problem. No import errors here.
But when I try:
import airflow.hooks.clickhouse_hook
I have an error:
ModuleNotFoundError: No module named 'airflow.hooks.clickhouse_hook'
And I can't understand how it works? I have no module named clickhouse_hook in directory airflow.hooks, but how can I import class ClickHouseHook without error in this way?
There is no ClickHouse provider in Airflow.
I assume you are using clickhouse plugin
thus the clickhouse_hook file is not in airflow/hooks folder because it is not part of Airflow.
I'm using in my lambda SQLAlchemy
I'm using python 3.8 (It supposed to work also in 3.7 to I don't care to change)
I downloaded the module separately and uploaded it as a zip with my code.
It looks like this:
But I'm still getting this error:
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'sqlalchemy'
Any idea why? How can I solve it? Unfortunately, I must use sqlalchemy so I can't change the module
Edit:
This is how I import:
from sqlalchemy import and_
from sqlalchemy.sql.functions import count
But I also tried with package.sqlalchemy and got the same results
I am getting that error when trying to import SQLAlchemy from flask_sqlalchemy:
from flask_sqlalchemy import SQLAlchemy
The complete error message is:
File "C:\Users\..\lib\site-packages\sqlalchemy\pool\base.py", line 63, in Pool
#util.deprecated_params(
AttributeError: module 'sqlalchemy.util' has no attribute 'deprecated_params'
The version of my libraries are sqlalchemy = 1.1.13 and flask_sqlalchemy = 2.4.0
Any suggestions on how to solve this?
Thanks
Had the same error with my python env which is managed via pipenv.
I ran pipenv update sqlalchemy which strangely enough rolled back sqlalchemy's version to 1.2.19 from what I had before, which was 1.3.5.
pip freeze | grep chemy
Flask-SQLAlchemy==2.4.0
SQLAlchemy==1.2.19
This now works for me without error:
python -c "from flask_sqlalchemy import SQLAlchemy"
I guess that without pipenv, one can manually use pip to re-install sqlalchemy for this specific version.
I don't know why my code doesn't work, I Import the library in the first line
from flask_sqlalchemy import SQLAlchemy
Knowing that I've already install flask_sqlalchemy
If it is a flask app you should run the app in virtualenv, otherwise simply running by python appName.py will give that error.
The other way is "set FLASK_APP=appName.py" then run flask run.
The first thing I'd check would be can you import the whole flask_sqlalchemy module:
import flask_sqlalchemy
If that works, it could be a case or spelling issue as that command works in my local environment.
It seems like you installed the wrong package. If you are using python3 you have to use python3 -m pip install <module>