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

No module named 'psycopg2' when running 04 - Ingest notebooks #199

Closed
alanzablocki opened this issue Apr 2, 2021 · 8 comments
Closed

No module named 'psycopg2' when running 04 - Ingest notebooks #199

alanzablocki opened this issue Apr 2, 2021 · 8 comments

Comments

@alanzablocki
Copy link

Trying to run Ingest module from workshop, folder #4, notebooks 7,8 and 9, and this statement results in an error:

engine = create_engine('postgresql://{}:{}@{}:{}/{}'.format(master_user_name, master_user_pw, redshift_endpoint_address, redshift_port, database_name_redshift))


ModuleNotFoundError Traceback (most recent call last)
in
----> 1 engine = create_engine('postgresql://{}:{}@{}:{}/{}'.format(master_user_name, master_user_pw, redshift_endpoint_address, redshift_port, database_name_redshift))

/opt/conda/lib/python3.7/site-packages/sqlalchemy/engine/init.py in create_engine(*args, **kwargs)
518 strategy = kwargs.pop("strategy", default_strategy)
519 strategy = strategies.strategies[strategy]
--> 520 return strategy.create(*args, **kwargs)
521
522

/opt/conda/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py in create(self, name_or_url, **kwargs)
85 if k in kwargs:
86 dbapi_args[k] = pop_kwarg(k)
---> 87 dbapi = dialect_cls.dbapi(**dbapi_args)
88
89 dialect_args["dbapi"] = dbapi

/opt/conda/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py in dbapi(cls)
776 @classmethod
777 def dbapi(cls):
--> 778 import psycopg2
779
780 return psycopg2

ModuleNotFoundError: No module named 'psycopg2'

Is there a recommended install?

I tried pip install and it did not work.

pip freeze returns
psycopg2==2.7.7

bash-4.2$ python -V
Python 3.7.10

bash-4.2$ pip -V
pip 21.0.1 from /opt/conda/lib/python3.7/site-packages/pip (python 3.7)
bash-4.2$

@alanzablocki
Copy link
Author

I did run bash-4.2$ pip install psycopg2-binary

and this works

bash-4.2$ python
Python 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import psycopg2

I did restart kernel many times.

@alanzablocki
Copy link
Author

This was using SQLAlchemy 1.3.13, if I rerun setup and get 1.3.22 I briefly got the error

TypeError: public_factory() takes 2 positional arguments but 3 were given, but then it goes back to psycopg2 import error when restarting kernel.

Any ideas on what extra setup we might need to run here?

@cfregly
Copy link
Contributor

cfregly commented Apr 2, 2021

@alanzablocki did you run the 01_setup/ set of notebooks to get everything installed?

!pip install --disable-pip-version-check -q SQLAlchemy==1.3.22

@alanzablocki
Copy link
Author

Hi Chris I did, and I did not hit this issue in your workshop, just on a fresh sagemaker instance.

I did run the command you gave above and still the same issue, what is interesting, is that I can do import psycopg2 in the cmd ( base env and default python), but I cannot import psycopg2 in the jupyter notebook on its own, and so when I run create_engine() that is what trips the notebook up as well.

(base) bash-4.2$ python
Python 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import psycopg2

(base) bash-4.2$ conda deactivate
bash-4.2$ python
Python 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import psycopg2

@cfregly
Copy link
Contributor

cfregly commented Apr 2, 2021

interesting, yeah i remember having a similar issue at one point with the psycopg2 import, but can't remember the details.

by "sagemaker instance", do you mean SM Studio? we've only been testing in SM Studio recently.

either way, which Kernel are you using? can you list all the installed python libraries?

@alanzablocki
Copy link
Author

alanzablocki commented Apr 2, 2021

Yes I am using Sagemaker Studio just like in the workshop.

Using Python3 (data science) kernel

Here is the pip freeze output:

aioboto3==6.5.0
aiobotocore==0.11.1
aiofiles==0.5.0
aiohttp==3.6.2
aioify==0.3.2
aioitertools==0.6.0
aiologger==0.6.0
asn1crypto @ file:///home/conda/feedstock_root/build_artifacts/asn1crypto_1595949944546/work
async-generator==1.10
async-timeout==3.0.1
asynctest==0.13.0
attrs==19.3.0
aws-embedded-metrics==1.0.7
aws-jupyter-proxy==0.1.0
awscli==1.18.212
backcall==0.1.0
bleach==3.1.4
boto3==1.16.49
botocore==1.19.49
brotlipy==0.7.0
certifi==2020.4.5.1
cffi @ file:///home/conda/feedstock_root/build_artifacts/cffi_1613413867554/work
chardet==3.0.4
click==7.1.2
colorama==0.4.3
conda==4.6.14
conda-package-handling @ file:///home/conda/feedstock_root/build_artifacts/conda-package-handling_1602876795648/work
cryptography @ file:///home/conda/feedstock_root/build_artifacts/cryptography_1615406009918/work
decorator==4.4.2
defusedxml==0.6.0
docutils==0.15.2
entrypoints @ file:///home/conda/feedstock_root/build_artifacts/entrypoints_1605121927639/work/dist/entrypoints-0.3-py2.py3-none-any.whl
fastapi==0.61.1
gitdb==4.0.4
GitPython==3.1.1
google-pasta==0.2.0
greenlet==1.0.0
h11==0.9.0
httptools==0.1.1
idna==2.9
importlib-metadata==1.6.0
ipykernel==5.2.0
ipython==7.13.0
ipython-genutils==0.2.0
jedi==0.16.0
jeepney==0.6.0
Jinja2==2.11.1
jmespath==0.9.5
json5==0.9.4
jsonschema @ file:///home/conda/feedstock_root/build_artifacts/jsonschema_1614815863336/work
jumpstartserver==1.3.8
jupyter-client==6.1.5
jupyter-core @ file:///home/conda/feedstock_root/build_artifacts/jupyter_core_1605127874166/work
jupyter-server-proxy==1.3.2
jupyter-telemetry==0.1.0
jupyterlab==1.2.20
jupyterlab-git==0.11.0
jupyterlab-server==1.0.7
keyring==22.0.1
MarkupSafe @ file:///home/conda/feedstock_root/build_artifacts/markupsafe_1610127564475/work
mistune @ file:///home/conda/feedstock_root/build_artifacts/mistune_1610112870915/work
module-wrapper==0.2.4
multidict==4.7.5
nbconvert==5.6.1
nbdime==1.1.0
nbformat==5.0.5
notebook @ file:///home/conda/feedstock_root/build_artifacts/notebook_1594078842924/work
numpy==1.20.1
packaging==20.9
pandocfilters==1.4.2
parso==0.6.2
pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1602535608087/work
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work
pkginfo==1.7.0
poetry-version==0.1.5
prometheus-client==0.7.1
prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1592500439797/work
protobuf==3.15.6
protobuf3-to-dict==0.1.5
psycopg2-binary==2.8.6
ptyprocess==0.6.0
pyasn1==0.4.8
pycosat @ file:///home/conda/feedstock_root/build_artifacts/pycosat_1610094791171/work
pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1593275161868/work
pydantic==1.8.1
Pygments==2.6.1
pyOpenSSL @ file:///home/conda/feedstock_root/build_artifacts/pyopenssl_1608055815057/work
pyparsing==2.4.7
pyrsistent==0.16.0
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1610291444829/work
python-dateutil==2.8.0
python-json-logger==0.1.11
PyYAML==5.3.1
pyzmq==19.0.0
readme-renderer==29.0
regex==2020.10.23
requests==2.23.0
requests-toolbelt==0.9.1
rfc3986==1.4.0
rsa==3.4.2
ruamel-yaml-conda @ file:///home/conda/feedstock_root/build_artifacts/ruamel_yaml_1611943443937/work
ruamel.yaml==0.16.10
ruamel.yaml.clib==0.2.0
s3transfer==0.3.6
sagemaker==2.21.0
sagemaker-jupyter-server-tools @ file:///home/sagemaker-user/tmp/build-deps/dist/sagemaker-jupyter-server-tools-1.0.tar.gz
sagemaker-nb2kg @ file:///home/sagemaker-user/tmp/build-deps/dist/sagemaker_nb2kg-0.1.tar.gz
sagemaker-sharing @ file:///home/sagemaker-user/tmp/build-deps/dist/sagemaker_sharing-0.1.tar.gz
sagemaker-ui-proxy==3.3.0
sagemakermodelhub==0.7.3
SecretStorage==3.3.1
Send2Trash==1.5.0
simpervisor==0.3
six==1.14.0
smdebug-rulesconfig==1.0.0
smmap==3.0.2
SQLAlchemy==1.4.5
starlette==0.13.6
supervisor==4.1.0
terminado==0.8.3
testpath==0.4.4
tomlkit==0.5.11
tornado==6.1
tqdm==4.57.0
traitlets==4.3.3
twine==3.3.0
typing-extensions==3.7.4.3
urllib3==1.25.8
uvicorn==0.11.8
uvloop==0.15.2
wcwidth==0.1.9
webencodings==0.5.1
websockets==8.1
wrapt==1.12.1
yarl==1.4.2
zipp==3.1.0
bash-4.2$

@alanzablocki
Copy link
Author

and here is the conda list output

bash-4.2$ conda list

packages in environment at /opt/conda:

Name Version Build Channel

_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 1_gnu conda-forge
aioboto3 6.5.0 pypi_0 pypi
aiobotocore 0.11.1 pypi_0 pypi
aiofiles 0.5.0 pypi_0 pypi
aiohttp 3.6.2 pypi_0 pypi
aioify 0.3.2 pypi_0 pypi
aioitertools 0.6.0 pypi_0 pypi
aiologger 0.6.0 pypi_0 pypi
argparse 1.4.0 pypi_0 pypi
asn1crypto 1.4.0 pyh9f0ad1d_0 conda-forge
async-generator 1.10 pypi_0 pypi
async-timeout 3.0.1 pypi_0 pypi
asynctest 0.13.0 pypi_0 pypi
attrs 19.3.0 py_0 conda-forge
aws-embedded-metrics 1.0.7 pypi_0 pypi
aws-jupyter-proxy 0.1.0 pypi_0 pypi
awscli 1.18.212 pypi_0 pypi
backcall 0.1.0 py_0 conda-forge
bleach 3.1.4 pyh9f0ad1d_0 conda-forge
boto3 1.16.49 pypi_0 pypi
botocore 1.19.49 pypi_0 pypi
brotlipy 0.7.0 py37h5e8e339_1001 conda-forge
ca-certificates 2020.12.5 ha878542_0 conda-forge
certifi 2020.4.5.1 py37hc8dfbb8_0 conda-forge
cffi 1.14.5 py37hc58025e_0 conda-forge
chardet 3.0.4 pypi_0 pypi
click 7.1.2 pypi_0 pypi
colorama 0.4.3 pypi_0 pypi
conda 4.6.14 py37_0 conda-forge
conda-package-handling 1.7.2 py37hb5d75c8_0 conda-forge
cryptography 3.4.6 py37h5d9358c_0 conda-forge
decorator 4.4.2 py_0 conda-forge
defusedxml 0.6.0 py_0 conda-forge
docutils 0.15.2 pypi_0 pypi
entrypoints 0.3 pyhd8ed1ab_1003 conda-forge
fastapi 0.61.1 pypi_0 pypi
gitdb 4.0.4 pypi_0 pypi
gitpython 3.1.1 pypi_0 pypi
google-pasta 0.2.0 pypi_0 pypi
greenlet 1.0.0 pypi_0 pypi
h11 0.9.0 pypi_0 pypi
httptools 0.1.1 pypi_0 pypi
icu 64.2 he1b5a44_1 conda-forge
idna 2.9 pypi_0 pypi
importlib-metadata 1.6.0 py37hc8dfbb8_0 conda-forge
importlib_metadata 1.6.0 0 conda-forge
ipykernel 5.2.0 py37h43977f1_1 conda-forge
ipython 7.13.0 py37hc8dfbb8_2 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
jedi 0.16.0 py37hc8dfbb8_1 conda-forge
jeepney 0.6.0 pypi_0 pypi
jinja2 2.11.1 pypi_0 pypi
jmespath 0.9.5 pypi_0 pypi
json5 0.9.4 pypi_0 pypi
jsonschema 3.2.0 pyhd8ed1ab_3 conda-forge
jumpstartserver 1.3.8 pypi_0 pypi
jupyter-client 6.1.5 pypi_0 pypi
jupyter-server-proxy 1.3.2 pypi_0 pypi
jupyter-telemetry 0.1.0 pypi_0 pypi
jupyter_core 4.6.3 py37h89c1867_2 conda-forge
jupyterlab 1.2.20 pypi_0 pypi
jupyterlab-git 0.11.0 pypi_0 pypi
jupyterlab-server 1.0.7 pypi_0 pypi
keyring 22.0.1 pypi_0 pypi
ld_impl_linux-64 2.35.1 hea4e1c9_2 conda-forge
libcxx 10.0.0 hc9558a2_2 conda-forge
libcxxabi 10.0.0 2 conda-forge
libedit 3.1.20181209 hc058e9b_0 defaults
libffi 3.3 h58526e2_2 conda-forge
libgcc-ng 9.3.0 h2828fa1_18 conda-forge
libgomp 9.3.0 h2828fa1_18 conda-forge
libsodium 1.0.17 h516909a_0 conda-forge
libstdcxx-ng 9.3.0 h6de172a_18 conda-forge
libuv 1.34.0 h516909a_0 conda-forge
markupsafe 1.1.1 py37h5e8e339_3 conda-forge
mistune 0.8.4 py37h5e8e339_1003 conda-forge
module-wrapper 0.2.4 pypi_0 pypi
multidict 4.7.5 pypi_0 pypi
nbconvert 5.6.1 py37hc8dfbb8_1 conda-forge
nbdime 1.1.0 pypi_0 pypi
nbformat 5.0.5 pypi_0 pypi
ncurses 6.2 h58526e2_4 conda-forge
nodejs 12.16.1 h67efad7_0 conda-forge
notebook 6.0.3 py37hc8dfbb8_1 conda-forge
numpy 1.20.1 pypi_0 pypi
openssl 1.1.1j h7f98852_0 conda-forge
packaging 20.9 pypi_0 pypi
pandoc 2.9.2.1 0 conda-forge
pandocfilters 1.4.2 py_1 conda-forge
parso 0.6.2 pypi_0 pypi
pexpect 4.8.0 pyh9f0ad1d_2 conda-forge
pickleshare 0.7.5 py_1003 conda-forge
pip 21.0.1 pyhd8ed1ab_0 conda-forge
pkginfo 1.7.0 pypi_0 pypi
poetry-version 0.1.5 pypi_0 pypi
prometheus_client 0.7.1 py_0 conda-forge
prompt-toolkit 3.0.5 py_1 conda-forge
protobuf 3.15.6 pypi_0 pypi
protobuf3-to-dict 0.1.5 pypi_0 pypi
psycopg2-binary 2.8.6 pypi_0 pypi
ptyprocess 0.6.0 py_1001 conda-forge
pyasn1 0.4.8 pypi_0 pypi
pycosat 0.6.3 py37h5e8e339_1006 conda-forge
pycparser 2.20 pyh9f0ad1d_2 conda-forge
pydantic 1.8.1 pypi_0 pypi
pygments 2.6.1 py_0 conda-forge
pyopenssl 20.0.1 pyhd8ed1ab_0 conda-forge
pyparsing 2.4.7 pypi_0 pypi
pyrsistent 0.16.0 py37h8f50634_0 conda-forge
pysocks 1.7.1 py37h89c1867_3 conda-forge
python 3.7.10 hffdb5ce_100_cpython conda-forge
python-dateutil 2.8.0 pypi_0 pypi
python-json-logger 0.1.11 pypi_0 pypi
python_abi 3.7 1_cp37m conda-forge
pyyaml 5.3.1 pypi_0 pypi
pyzmq 19.0.0 py37hac76be4_1 conda-forge
readline 8.0 he28a2e2_2 conda-forge
readme-renderer 29.0 pypi_0 pypi
regex 2020.10.23 pypi_0 pypi
requests 2.23.0 pypi_0 pypi
requests-toolbelt 0.9.1 pypi_0 pypi
rfc3986 1.4.0 pypi_0 pypi
rsa 3.4.2 pypi_0 pypi
ruamel-yaml 0.16.10 pypi_0 pypi
ruamel-yaml-clib 0.2.0 pypi_0 pypi
ruamel_yaml 0.15.80 py37h5e8e339_1004 conda-forge
s3transfer 0.3.6 pypi_0 pypi
sagemaker 2.21.0 pypi_0 pypi
sagemaker-jupyter-server-tools 1.0 pypi_0 pypi
sagemaker-nb2kg 0.1 pypi_0 pypi
sagemaker-sharing 0.1 pypi_0 pypi
sagemaker-ui-proxy 3.3.0 pypi_0 pypi
sagemakermodelhub 0.7.3 pypi_0 pypi
secretstorage 3.3.1 pypi_0 pypi
send2trash 1.5.0 py_0 conda-forge
setuptools 49.6.0 py37h89c1867_3 conda-forge
simpervisor 0.3 pypi_0 pypi
six 1.14.0 py_1 conda-forge
smdebug-rulesconfig 1.0.0 pypi_0 pypi
smmap 3.0.2 pypi_0 pypi
sqlalchemy 1.4.5 pypi_0 pypi
sqlite 3.34.0 h74cdb3f_0 conda-forge
starlette 0.13.6 pypi_0 pypi
supervisor 4.1.0 pypi_0 pypi
terminado 0.8.3 py37hc8dfbb8_1 conda-forge
testpath 0.4.4 py_0 conda-forge
tk 8.6.10 h21135ba_1 conda-forge
tomlkit 0.5.11 pypi_0 pypi
tornado 6.1 py37h5e8e339_1 conda-forge
tqdm 4.57.0 pypi_0 pypi
traitlets 4.3.3 py37hc8dfbb8_1 conda-forge
twine 3.3.0 pypi_0 pypi
typing-extensions 3.7.4.3 pypi_0 pypi
urllib3 1.25.8 pypi_0 pypi
uvicorn 0.11.8 pypi_0 pypi
uvloop 0.15.2 pypi_0 pypi
wcwidth 0.1.9 pyh9f0ad1d_0 conda-forge
webencodings 0.5.1 py_1 conda-forge
websockets 8.1 pypi_0 pypi
wheel 0.36.2 pyhd3deb0d_0 conda-forge
wrapt 1.12.1 pypi_0 pypi
xz 5.2.5 h516909a_1 conda-forge
yaml 0.2.5 h516909a_0 conda-forge
yarl 1.4.2 pypi_0 pypi
zeromq 4.3.2 he1b5a44_2 conda-forge
zipp 3.1.0 py_0 conda-forge
zlib 1.2.11 h516909a_1010 conda-forge

@oonisim
Copy link

oonisim commented Aug 6, 2021

!pip install psycopg2-binary

@cfregly cfregly closed this as completed Feb 11, 2022
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

3 participants