Search code examples
pythonpython-3.xpippycharmpsycopg2

Package requirement 'psycopg2==2.9.1' not satisfied pycharm macos


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?


Solution

  • 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.