0

I'm running python 3.9 and my goal is to install and import pyscopg2:

python --version 
Python 3.9.12

conda env list
# conda environments:
#
base                  *  /home/doug/anaconda3

Looks like I'm in anaconda base env.

conda install psycopg2
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

Now, when I try to import:

Enter python terminal:

python
Python 3.9.12 (main, Apr  5 2022, 06:56:58) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

Then try to import:

import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/doug/Documents/Projects/Zen/Projects/data-scripts/ga4ExtractLoad/psycopg2/__init__.py", line 50, in <module>
    from psycopg2._psycopg import (                     # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'
Doug Fir
  • 19,971
  • 47
  • 169
  • 299
  • https://stackoverflow.com/q/36103034/494134 – John Gordon Sep 29 '22 at 19:39
  • Does this answer your question? [ImportError: No module named 'psycopg2.\_psycopg'](https://stackoverflow.com/questions/36103034/importerror-no-module-named-psycopg2-psycopg) – Chris Sep 29 '22 at 19:46
  • @JohnGordon that post and accepted answer seems to be more about windows. I'm on Linux. I tried other suggestions on there like uninstalling and then reinstalling but my problem persists – Doug Fir Sep 29 '22 at 19:59
  • 1
    In case the installed directory is not in the library path, you can use find -iname in the installed target directory find the specific location. – pengchy Apr 07 '23 at 01:52

1 Answers1

1

It looks like /home/doug/Documents/Projects/Zen/Projects/data-scripts/ga4ExtractLoad/psycopg2 is masking what is installed into your base environment.

Try running this import from a different directory and/or delete /home/doug/Documents/Projects/Zen/Projects/data-scripts/ga4ExtractLoad/psycopg2.

See ModuleNotFoundError: No module named 'psycopg2._psycopg

Ken Odegard
  • 246
  • 1
  • 4