Package requirement 'psycopg2==2.9.1' not satisfied pycharm macos
Asked Answered
H

2

8

after long hours of trying: i installed psycopg2==2.9.1 with pip installed with pip

I tried adding it to all the interpreter paths i could find but still keep getting this message: error message

I tried as well restarting pycharm, invalidate caches ..

When trying to just install it with pycharm i get this error messege:

    Collecting psycopg2==2.9.1
  Using cached psycopg2-2.9.1.tar.gz (379 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Building wheels for collected packages: psycopg2
  Building wheel for psycopg2 (setup.py): started
  Building wheel for psycopg2 (setup.py): finished with status 'error'
  Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
    Running setup.py install for psycopg2: started
    Running setup.py install for psycopg2: finished with status 'error'

  ERROR: Command errored out with exit status 1:
   command: '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"'; __file__='"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-wheel-lbvr1lzp
       cwd: /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/
  Complete output (53 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.13.0-x86_64-3.9
  creating build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/_json.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/extras.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/errorcodes.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/tz.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/_range.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/_ipaddress.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/__init__.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/extensions.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/errors.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/sql.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  copying lib/pool.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
  warning: build_py: byte-compiling is disabled, skipping.
  
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build/temp.macosx-10.13.0-x86_64-3.9
  creating build/temp.macosx-10.13.0-x86_64-3.9/psycopg
  /usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140001 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include -I/Applications/QGIS.app/Contents/MacOS/include/python3.9 -I. -I/opt/homebrew/include -I/opt/homebrew/include/postgresql/server -I/opt/homebrew/Cellar/icu4c/69.1/include -I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/readline/include -c psycopg/adapter_asis.c -o build/temp.macosx-10.13.0-x86_64-3.9/psycopg/adapter_asis.o
  In file included from psycopg/adapter_asis.c:28:
  ./psycopg/psycopg.h:35:10: error: 'Python.h' file not found with <angled> include; use "quotes" instead
  #include <Python.h>
           ^~~~~~~~~~
           "Python.h"
  ./psycopg/psycopg.h:35:10: warning: non-portable path to file '<python.h>'; specified path differs in case from file name on disk [-Wnonportable-include-path]
  #include <Python.h>
           ^~~~~~~~~~
           <python.h>
  In file included from psycopg/adapter_asis.c:28:
  In file included from ./psycopg/psycopg.h:35:
  psycopg/Python.h:31:2: error: "psycopg requires Python 3.6"
  #error "psycopg requires Python 3.6"
   ^
  psycopg/Python.h:34:10: fatal error: 'structmember.h' file not found
  #include <structmember.h>
           ^~~~~~~~~~~~~~~~
  1 warning and 3 errors generated.
  
  It appears you are missing some prerequisite to build the package from source.
  
  You may install a binary package by installing 'psycopg2-binary' from PyPI.
  If you want to install psycopg2 from source, please install the packages
  required for the build and try again.
  
  For further information please check the 'doc/src/install.rst' file (also at
  <https://www.psycopg.org/docs/install.html>).
  
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2
    ERROR: Command errored out with exit status 1:
     command: '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"'; __file__='"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-record-fkjtibr5/install-record.txt --single-version-externally-managed --compile --install-headers '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include/site/python3.9/psycopg2'
         cwd: /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/
    Complete output (55 lines):
    running install
    /Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13.0-x86_64-3.9
    creating build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/_json.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/extras.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/errorcodes.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/tz.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/_range.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/_ipaddress.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/__init__.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/extensions.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/errors.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/sql.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    copying lib/pool.py -> build/lib.macosx-10.13.0-x86_64-3.9/psycopg2
    warning: build_py: byte-compiling is disabled, skipping.
    
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.macosx-10.13.0-x86_64-3.9
    creating build/temp.macosx-10.13.0-x86_64-3.9/psycopg
    /usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -I/MISSING/DEPS//stage/include -I/MISSING/DEPS//stage/unixodbc/include -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140001 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include -I/Applications/QGIS.app/Contents/MacOS/include/python3.9 -I. -I/opt/homebrew/include -I/opt/homebrew/include/postgresql/server -I/opt/homebrew/Cellar/icu4c/69.1/include -I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/readline/include -c psycopg/adapter_asis.c -o build/temp.macosx-10.13.0-x86_64-3.9/psycopg/adapter_asis.o
    In file included from psycopg/adapter_asis.c:28:
    ./psycopg/psycopg.h:35:10: error: 'Python.h' file not found with <angled> include; use "quotes" instead
    #include <Python.h>
             ^~~~~~~~~~
             "Python.h"
    ./psycopg/psycopg.h:35:10: warning: non-portable path to file '<python.h>'; specified path differs in case from file name on disk [-Wnonportable-include-path]
    #include <Python.h>
             ^~~~~~~~~~
             <python.h>
    In file included from psycopg/adapter_asis.c:28:
    In file included from ./psycopg/psycopg.h:35:
    psycopg/Python.h:31:2: error: "psycopg requires Python 3.6"
    #error "psycopg requires Python 3.6"
     ^
    psycopg/Python.h:34:10: fatal error: 'structmember.h' file not found
    #include <structmember.h>
             ^~~~~~~~~~~~~~~~
    1 warning and 3 errors generated.
    
    It appears you are missing some prerequisite to build the package from source.
    
    You may install a binary package by installing 'psycopg2-binary' from PyPI.
    If you want to install psycopg2 from source, please install the packages
    required for the build and try again.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
    
    error: command '/usr/bin/clang' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: '/Users//Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"'; __file__='"'"'/private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-install-myo1zngt/psycopg2_e9a9698f63464cb99bc5bf3655675aa2/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/fj/blrljwxs22q3csr4fqw7ycmc0000gn/T/pip-record-fkjtibr5/install-record.txt --single-version-externally-managed --compile --install-headers '/Users/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/data_index-development/venv/include/site/python3.9/psycopg2' Check the logs for full command output.

What can fix it?

Helpmate answered 4/12, 2021 at 21:18 Comment(10)
Your screenshot shows that you installed psycopg2 for the system interpreter, but did you install it for the interpreter being used by PyCharm? Usually PyCharm creates a virtual environment for each project with its own isolated interpreter.Parasitize
Create a venv. 2º Then activate the venv on the command line before you run pip. 3º Choose the venv as interpreter in the IDE.Brandonbrandt
Welcome to Stack Overflow. Please edit the question to include any necessary source code, data, and error messages as text. Consider these reasons and guidelines.Brandonbrandt
@Brian Hi! updated the post with the error i get when trying to install in the virtual env and when install via the pycharm warning. Let me know what do you thinkHelpmate
@Brandonbrandt Thanks, updated that post with the error i got..Helpmate
@Helpmate have you found out any solution for this?Amrita
@SarthakMittal have you checked if you installed the module for the correct interpreter?Alcibiades
@AbhinavMathur yesAmrita
@SarthakMittal open terminal, run pip show psycopg2 to check whether it's really installed, then run pip -V. Now open Pycharm, open Terminal (Option + F12 by default), run pip -V, verify the output matches. Don't forget to drop the output here for further analysis.Leadin
@Leadin pip3 show psycopg2 -> WARNING: Package(s) not found: psycopg2 \b pip -V -> pip 22.2.2 from /opt/homebrew/lib/python3.10/site-packages/pip (python 3.10) pip -V in pycharm terminal -> pip 21.3.1 from /Users/sarthakmittal/Documents/Sarthak/mbs/MBS_backedn_uat/venv/lib/python3.8/site-packages/pip (python 3.8)Amrita
P
-2

Usually had something similar happen to me while using anaconda, and I had to manually delete the folder location and reinstall to be importable (even with new enviroment).

I would suggest you try anaconda, miniconda with the same requirements and see if those help you out with your environment problem. Note: This requires separate installation. Follow some of the creation guides but in general the essence would be something like:

conda create --name testenv python=3.8

conda activate testenv

conda install psycopg2"==2.9.1" -c conda-forge

After doing the last command in terminal, you are going to get something like this (just different version, but added into the command for 2.9.1): enter image description here

You generally can search on anaconda website if you aren't familiar with the channels and the commands.

To check if everything is alright in the environment itself:

Running psycopg2 in python terminal

Now try to use this environment in PyCharm (by changing the base interpreter to the testenv one), if you still have problems do include the error message.

This also separates the issue from PyCharm or Pip wheel, and see if you can run get a running environment.

Petrozavodsk answered 31/8, 2022 at 8:38 Comment(0)
R
6

You're trying to build the psycopg package from source. That requires development files for Python, such as Python.h, which usually don't come automatically on macOS.

Instead, try the suggestion in the error message: install psycopg_binary:

pip install psycopg2-binary

The installed package will just be psycopg2, but there is no need to compile it from source.

Rumormonger answered 31/8, 2022 at 8:44 Comment(0)
P
-2

Usually had something similar happen to me while using anaconda, and I had to manually delete the folder location and reinstall to be importable (even with new enviroment).

I would suggest you try anaconda, miniconda with the same requirements and see if those help you out with your environment problem. Note: This requires separate installation. Follow some of the creation guides but in general the essence would be something like:

conda create --name testenv python=3.8

conda activate testenv

conda install psycopg2"==2.9.1" -c conda-forge

After doing the last command in terminal, you are going to get something like this (just different version, but added into the command for 2.9.1): enter image description here

You generally can search on anaconda website if you aren't familiar with the channels and the commands.

To check if everything is alright in the environment itself:

Running psycopg2 in python terminal

Now try to use this environment in PyCharm (by changing the base interpreter to the testenv one), if you still have problems do include the error message.

This also separates the issue from PyCharm or Pip wheel, and see if you can run get a running environment.

Petrozavodsk answered 31/8, 2022 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.