0

I worked this issue for 2 days: when I import psycopg2 into jupter notebook,it always return:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-7d2da0a5d979> in <module>
----> 1 import psycopg2

ModuleNotFoundError: No module named 'psycopg2'

I have used all the way no matter pip or conda to install both psycopg2 and psycopg2-binary but none of them works for me.

I'm using MAC and python version in anaconda is python 3.9

Any one can help ?

buhtz
  • 10,774
  • 18
  • 76
  • 149
William
  • 3,724
  • 9
  • 43
  • 76
  • 1
    Does this answer your question? [ModuleNotFoundError : No module named 'psycopg2.\_psycopg'](https://stackoverflow.com/questions/61006302/modulenotfounderror-no-module-named-psycopg2-psycopg) – NelsonGon Dec 07 '22 at 20:31

2 Answers2

1

first, u have to download the library. using this command in juypter notebook. --> conda install psycopg2 make sure you have an internet connection then u have to wait for 1-2 min it automatically downloads the library. then u can use that

1

I tried to reproduce your problem (albeit on Linux) but everything worked flawlessly.

Because your workflow for creating and using the Jupyter Notebook is not super-clear, it might be a good idea to run the code that worked for me and see whether it helps:

# Install packages from conda-forge (usually the best choice and very up-to-date packages)
conda create --name test python=3.9 jupyterlab psycopg2 -c conda-forge
# activate the new environment
conda activate test
# Start Jupyterlab
jupyter-lab

After testing you can remove the environment like so

conda deactivate
conda env remove --name test

Let me know whether it helped :-)

ffrosch
  • 899
  • 6
  • 15