Skip to content

az postgres flexible-server connect failing #22889

Closed

Description

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az postgres flexible-server connect

Errors:

The command failed with an unexpected error. Here is the traceback:
No module named 'psycopg2._psycopg'
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 561, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/__init__.py", line 515, in load_arguments
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 318, in load_arguments
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/commands.py", line 104, in load_arguments
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 125, in arguments_loader
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 59, in get_op_handler
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\azext_rdbms_connect\custom.py", line 10, in <module>
    import psycopg2
  File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\psycopg2\__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az postgres flexible-server connect -n {} -u {} -d {} --interactive

Expected Behavior

Environment Summary

Windows-10-10.0.19043-SP0
Python 3.10.4
Installer: MSI

azure-cli 2.37.0

Extensions:
rdbms-connect 1.0.2

Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1

Additional Context

Activity

  1. ghost added
    customer-reportedIssues that are reported by GitHub users external to the Azure organization.
    on Jun 15, 2022
  2. ghost added on Jun 15, 2022
  3. ghost added
    CXP AttentionThis issue is handled by CXP team.
    on Jun 15, 2022
  4. yonzhan commented on Jun 15, 2022

    @yonzhan
    Collaborator

    route to CXP team

  5. navba-MSFT commented on Jun 20, 2022

    @navba-MSFT
    Contributor

    @azeem2020 Apologies for the late reply. Thanks for reaching out to us and sharing this feedback. We are looking into this issue and we will provide an update.

  6. navba-MSFT commented on Jun 20, 2022

    @navba-MSFT
    Contributor

    @azeem2020 Could you please delete the rdbms-connect folder n the ~/.azure/cliextensions/ location and install the most recent version of this extension using the below command ?

    az extension add --name rdbms-connect

    Post this, you can try to run the AzCli command az postgres flexible-server connect again and check if you see the issue. Awaiting your reply.

  7. muhd-azeem commented on Jun 20, 2022

    @muhd-azeem
    Author

    navba-MSFT (@navba-MSFT) Still getting the similar error. Can you please suggest the other workaround?

    PS C:\Users\M66445> az postgres flexible-server connect -n pgxxx-xxxx-001 -u xxxx -d postgres -p xxxx --interactive
    Traceback (most recent call last):
      File "runpy.py", line 196, in _run_module_as_main
      File "runpy.py", line 86, in _run_code
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\bin\pgcli.exe\__main__.py", line 4, in <module>
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\pgcli\main.py", line 3, in <module>
        from pgspecial.namedqueries import NamedQueries
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\pgspecial\__init__.py", line 13, in <module>
        from . import iocommands
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\pgspecial\iocommands.py", line 9, in <module>
        import psycopg
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\psycopg\__init__.py", line 9, in <module>
        from . import pq  # noqa: F401 import early to stabilize side effects
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\psycopg\pq\__init__.py", line 114, in <module>
        import_from_libpq()
      File "C:\Users\M66445\.azure\cliextensions\rdbms-connect\psycopg\pq\__init__.py", line 106, in import_from_libpq
        raise ImportError(
    ImportError: no pq wrapper available.
    Attempts made:
    - couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
    - couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
    - couldn't import psycopg 'python' implementation: libpq library not found
    
  8. navba-MSFT commented on Jun 21, 2022

    @navba-MSFT
    Contributor

    @azeem2020 Thanks for reopenning the issue and reaching out to us. Could you try running the below command and check if that helps ?

    pip install psycopg
    pip install psycopg-c
    pip install psycopg-binary

  9. navba-MSFT commented on Jun 23, 2022

    @navba-MSFT
    Contributor

    @azeem2020 A quick follow-up to check if you have tried the above action plan. Please let me know if you have any update on this.

  10. muhd-azeem commented on Jun 24, 2022

    @muhd-azeem
    Author

    Apology for late response as I was unavailable. Please see below error for pip install psycopg-c

    pip install psycopg-c
    Defaulting to user installation because normal site-packages is not writeable
    Collecting psycopg-c
      Downloading psycopg-c-3.0.15.tar.gz (594 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 594.9/594.9 kB 705.3 kB/s eta 0:00:00
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
      Preparing metadata (pyproject.toml) ... error
      error: subprocess-exited-with-error
    
      × Preparing metadata (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [10 lines of output]
          C:\Users\M66445\AppData\Local\Temp\pip-build-env-zgajm2s_\overlay\Lib\site-packages\setuptools\config\setupcfg.py:463: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
            warnings.warn(msg, warning_class)
          running dist_info
          creating C:\Users\M66445\AppData\Local\Temp\pip-modern-metadata-rzx3aatx\psycopg_c.egg-info
          writing C:\Users\M66445\AppData\Local\Temp\pip-modern-metadata-rzx3aatx\psycopg_c.egg-info\PKG-INFO
          writing dependency_links to C:\Users\M66445\AppData\Local\Temp\pip-modern-metadata-rzx3aatx\psycopg_c.egg-info\dependency_links.txt
          writing top-level names to C:\Users\M66445\AppData\Local\Temp\pip-modern-metadata-rzx3aatx\psycopg_c.egg-info\top_level.txt
          writing manifest file 'C:\Users\M66445\AppData\Local\Temp\pip-modern-metadata-rzx3aatx\psycopg_c.egg-info\SOURCES.txt'
          couldn't run 'pg_config' --includedir: [WinError 2] The system cannot find the file specified
          error: [WinError 2] The system cannot find the file specified
          [end of output]
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.
    
  11. 8 remaining items

  12. muhd-azeem commented on Jul 4, 2022

    @muhd-azeem
    Author

    I cannot find anything for pg_config in my local directory to update PATH variable for system or User. The only folder structure for PostgreSQL we have is pgAdmin and Python as shown below and this path already updated.

    PS C:\Program Files\pgAdmin 4\v4\runtime> ls
    
        Directory: C:\Program Files\pgAdmin 4\v4\runtime
    
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    d-----         6/30/2022  10:01 AM                imageformats
    d-----         6/30/2022  10:01 AM                platforms
    -a----         1/18/2021   2:03 PM          15360 comerr64.dll
    -a----         1/18/2021   2:03 PM         384512 gssapi64.dll
    -a----         1/18/2021   2:03 PM          64000 k5sprt64.dll
    -a----         1/18/2021   2:05 PM          27136 kinit.exe
    -a----         1/18/2021   2:03 PM        1210368 krb5_64.dll
    -a----         10/1/2020  12:34 PM        2840064 libcrypto-1_1-x64.dll
    -a----        11/26/2020   2:38 PM         301056 libpq.dll
    -a----         10/1/2020  12:34 PM         675840 libssl-1_1-x64.dll
    -a----         1/25/2021   1:39 PM         588288 pgAdmin4.exe
    -a----        11/26/2020   2:39 PM         456704 pg_dump.exe
    -a----        11/26/2020   2:39 PM         136192 pg_dumpall.exe
    -a----        11/26/2020   2:39 PM         213504 pg_restore.exe
    -a----        11/26/2020   2:39 PM         499200 psql.exe
    -a----         9/23/2020   4:00 PM         100368 python.exe
    -a----         9/23/2020   4:00 PM        4205584 python38.dll
    -a----         9/23/2020   4:00 PM          98832 pythonw.exe
    -a----         1/25/2021   1:39 PM             28 qt.conf
    -a----         3/27/2020  12:18 PM        6193272 Qt5Core.dll
    -a----         3/27/2020  12:18 PM        7129720 Qt5Gui.dll
    -a----         3/27/2020  12:18 PM        1381496 Qt5Network.dll
    -a----         3/27/2020   5:41 PM         337528 Qt5Svg.dll
    -a----         3/27/2020  12:18 PM        5596280 Qt5Widgets.dll
    -a----         5/29/2020  12:24 PM          84992 zlib.dll
    
  13. ghost added
    needs-team-attentionThis issue needs attention from Azure service team or SDK team
    on Jul 4, 2022
  14. ghost removed
    needs-author-feedbackMore information is needed from author to address the issue.
    on Jul 4, 2022
  15. added
    Service AttentionThis issue is responsible by Azure service team.
    and removed
    CXP AttentionThis issue is handled by CXP team.
    on Jul 5, 2022
  16. navba-MSFT commented on Jul 5, 2022

    @navba-MSFT
    Contributor

    @azeem2020 Thanks for getting back. I am adding Service team to look into this issue.

    sunilagarwal, @lfittl-msft, Sridhar Ranganathan (@sr-msft), Nik Larin (@niklarin) Could you please look into this and provide some pointers when you get a chance ? Awaiting your reply.

  17. sr-msft commented on Jul 5, 2022

    @sr-msft
  18. navba-MSFT commented on Jul 5, 2022

    @navba-MSFT
    Contributor

    Daeun Yim (@DaeunYim) for visibility

  19. sr-msft commented on Jul 5, 2022

    @sr-msft
  20. alanenriqueo commented on Aug 2, 2022

    @alanenriqueo
    Member

    Hi @azeem2020, the MSI installer of azure-cli requires 32-bit version of libpq.dll available in PATH; that's because the MSI installer comes with its own version of 32-bit python. Can we try that?

  21. nachoalonsoportillo commented on Jun 10, 2024

    @nachoalonsoportillo
    Member

    Yong Zhang (@yonzhan) Can we please close this one. It should have been resolved with Alan's suggestion.

  22. PingvinB commented on Oct 7, 2025

    @PingvinB

    Does "az postgresl flexible-server" have a dependency on a local installation of pgadmin/pgsql? Where am I supposed to get "libpq.dll" from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Auto-AssignAuto assign by botPostgreSQLService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionThis issue needs attention from Azure service team or SDK team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions