Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on windows 11 #1413

Open
3 tasks done
NoahELE opened this issue Jul 28, 2023 · 12 comments
Open
3 tasks done

Not working on windows 11 #1413

NoahELE opened this issue Jul 28, 2023 · 12 comments

Comments

@NoahELE
Copy link

NoahELE commented Jul 28, 2023

Description

> pgcli postgres://xxx:xxx@localhost:5432
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\admin\.local\bin\pgcli.exe\__main__.py", line 4, in <module>
  File "C:\Users\admin\.local\pipx\venvs\pgcli\Lib\site-packages\pgcli\main.py", line 2, in <module>
    from pgspecial.namedqueries import NamedQueries
  File "C:\Users\admin\.local\pipx\venvs\pgcli\Lib\site-packages\pgspecial\__init__.py", line 12, in <module>
    from . import dbcommands
  File "C:\Users\admin\.local\pipx\venvs\pgcli\Lib\site-packages\pgspecial\dbcommands.py", line 7, in <module>
    from psycopg.sql import SQL
  File "C:\Users\admin\.local\pipx\venvs\pgcli\Lib\site-packages\psycopg\__init__.py", line 9, in <module>
    from . import pq  # noqa: F401 import early to stabilize side effects
    ^^^^^^^^^^^^^^^^
  File "C:\Users\admin\.local\pipx\venvs\pgcli\Lib\site-packages\psycopg\pq\__init__.py", line 114, in <module>
    import_from_libpq()
  File "C:\Users\admin\.local\pipx\venvs\pgcli\Lib\site-packages\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

Your environment

  • Please provide your OS and version information.
    Window 11 with Python 3.11.4
  • Please provide your CLI version.
    pgcli fails with all args, so I cannot see its version, but it should be the latest version.
  • What is the output of pip freeze command.
cli-helpers==2.3.0
click==8.1.6
colorama==0.4.6
configobj==5.0.8
pendulum==2.1.2
pgcli==3.5.0
pgspecial==2.1.0
prompt-toolkit==3.0.39
psycopg==3.1.9
Pygments==2.15.1
python-dateutil==2.8.2
pytzdata==2020.1
setproctitle==1.3.2
six==1.16.0
sqlparse==0.4.4
tabulate==0.9.0
typing_extensions==4.7.1
tzdata==2023.3
wcwidth==0.2.6
@NoahELE
Copy link
Author

NoahELE commented Jul 28, 2023

It works after I run pip install psycopg_binary, maybe it should be included as a dependency?

@j-bennet
Copy link
Contributor

j-bennet commented Jul 28, 2023

Nice work @NoahELE, you solved your own problem 🎉 . :)

In fact, we have a binary requirement for the Windows platform specified here:

pgcli/setup.py

Lines 31 to 32 in 69dcceb

if platform.system() == "Windows":
install_requirements.append("psycopg-binary >= 3.0.14")

I wonder why things didn't work for you. Did you install pgcli into a fresh virtual environment, or was this an update? Perhaps psycopg was already present in your environment?

@NoahELE
Copy link
Author

NoahELE commented Jul 29, 2023

In fact I install pgcli with pipx, strangely it does not install psycopg-binary automatically, so I have to manually inject it.

However, when I test installation on a fresh venv, the psycopg-binary is not installed automatically also, here's the log. In this case, manual installation of psycopg-binary is still needed.

> pip install -U pgcli
Collecting pgcli
  Downloading pgcli-3.5.0-py3-none-any.whl (80 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 80.8/80.8 kB 4.7 MB/s eta 0:00:00
Collecting pgspecial>=2.0.0 (from pgcli)
  Downloading pgspecial-2.1.0-py3-none-any.whl (35 kB)
Collecting click>=4.1 (from pgcli)
  Downloading click-8.1.6-py3-none-any.whl (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 5.5 MB/s eta 0:00:00
Collecting Pygments>=2.0 (from pgcli)
  Downloading Pygments-2.15.1-py3-none-any.whl (1.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 9.1 MB/s eta 0:00:00
Collecting prompt-toolkit<4.0.0,>=2.0.6 (from pgcli)
  Downloading prompt_toolkit-3.0.39-py3-none-any.whl (385 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 385.2/385.2 kB 8.2 MB/s eta 0:00:00
Collecting psycopg>=3.0.14 (from pgcli)
  Downloading psycopg-3.1.9-py3-none-any.whl (167 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 167.8/167.8 kB 9.8 MB/s eta 0:00:00
Collecting sqlparse<0.5,>=0.3.0 (from pgcli)
  Downloading sqlparse-0.4.4-py3-none-any.whl (41 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.2/41.2 kB ? eta 0:00:00
Collecting configobj>=5.0.6 (from pgcli)
  Downloading configobj-5.0.8-py2.py3-none-any.whl (36 kB)
Collecting pendulum>=2.1.0 (from pgcli)
  Downloading pendulum-2.1.2.tar.gz (81 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 81.2/81.2 kB ? eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting cli-helpers[styles]>=2.2.1 (from pgcli)
  Downloading cli_helpers-2.3.0-py3-none-any.whl (19 kB)
Collecting setproctitle>=1.1.9 (from pgcli)
  Downloading setproctitle-1.3.2-cp311-cp311-win_amd64.whl (11 kB)
Collecting tabulate[widechars]>=0.8.2 (from cli-helpers[styles]>=2.2.1->pgcli)
  Downloading tabulate-0.9.0-py3-none-any.whl (35 kB)
Collecting colorama (from click>=4.1->pgcli)
  Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting six (from configobj>=5.0.6->pgcli)
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting python-dateutil<3.0,>=2.6 (from pendulum>=2.1.0->pgcli)
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 7.7 MB/s eta 0:00:00
Collecting pytzdata>=2020.1 (from pendulum>=2.1.0->pgcli)
  Downloading pytzdata-2020.1-py2.py3-none-any.whl (489 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 490.0/490.0 kB 7.6 MB/s eta 0:00:00
Collecting wcwidth (from prompt-toolkit<4.0.0,>=2.0.6->pgcli)
  Downloading wcwidth-0.2.6-py2.py3-none-any.whl (29 kB)
Collecting typing-extensions>=4.1 (from psycopg>=3.0.14->pgcli)
  Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting tzdata (from psycopg>=3.0.14->pgcli)
  Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 kB 7.1 MB/s eta 0:00:00
Building wheels for collected packages: pendulum
  Building wheel for pendulum (pyproject.toml) ... done
  Created wheel for pendulum: filename=pendulum-2.1.2-cp311-cp311-win_amd64.whl size=129987 sha256=bbae2eaf405521df262530bda08ecf0f8b354364c514660e79a34467d1fb290a
  Stored in directory: c:\users\admin\appdata\local\pip\cache\wheels\a4\b7\10\a86f4f49b1bdf8a0cf3da42d48f499e4cb7529ebab7aad3550
Successfully built pendulum
Installing collected packages: wcwidth, tzdata, typing-extensions, tabulate, sqlparse, six, setproctitle, pytzdata, Pygments, prompt-toolkit, colorama, python-dateutil, psycopg, configobj, click, pgspecial, pendulum, cli-helpers, pgcli
Successfully installed Pygments-2.15.1 cli-helpers-2.3.0 click-8.1.6 colorama-0.4.6 configobj-5.0.8 pendulum-2.1.2 pgcli-3.5.0 pgspecial-2.1.0 prompt-toolkit-3.0.39 psycopg-3.1.9 python-dateutil-2.8.2 pytzdata-2020.1 setproctitle-1.3.2 six-1.16.0 sqlparse-0.4.4 tabulate-0.9.0 typing-extensions-4.7.1 tzdata-2023.3 wcwidth-0.2.6

@j-bennet
Copy link
Contributor

Well, that is interesting. Does your platform.system() report as 'Windows'?

python -c 'import platform; print(platform.system())'

@NoahELE
Copy link
Author

NoahELE commented Jul 29, 2023

> python -c 'import platform; print(platform.system())'
Windows

@AFanaei
Copy link

AFanaei commented Nov 12, 2023

Nice work @NoahELE, you solved your own problem 🎉 . :)

In fact, we have a binary requirement for the Windows platform specified here:

pgcli/setup.py

Lines 31 to 32 in 69dcceb

if platform.system() == "Windows":
install_requirements.append("psycopg-binary >= 3.0.14")

I wonder why things didn't work for you. Did you install pgcli into a fresh virtual environment, or was this an update? Perhaps psycopg was already present in your environment?

I had the same problem that was fixed by installing psycopg_binary. i installed into a fresh environment maybe the problem is because psycopg_binary is appended to install_requirments after psycopg in setup.py.

@dbaty
Copy link
Member

dbaty commented Nov 15, 2023

@j-bennet : I did not look into why exactly we require psycopg-binary on Windows only, but @AFanaei probably has a good lead. With the current code on Windows, we try to install both psycopg and psycopg-binary (and the installation of the former may fail). Should we not do something like this:

install_requirements = [
    "pgspecial>=2.0.0",
    # ... do NOT include "psycopg" here
]

if platform.system() == "Windows":
    install_requirements.append("psycopg-binary >= 3.0.14")
else:
    install_requirements.append("psycopg >= 3.0.14")

Or, more simply:

install_requires = [
    "psycopg >= 3.0.14; sys_platform != 'win32'"
    "psycopg-binary >= 3.0.14; sys_platform == 'win32'",
]

(See here for a list of sys_platform values.)

@j-bennet
Copy link
Contributor

@dbaty

Yes, this makes sense. We don't need to install both.

@liewrichmond
Copy link

I hit the same issue trying to install in Windows10 and also on WSL FWIW.
In both cases I was able to get around the issue by doing a separate

pip install "psycopg[binary,pool]"

ERYoung11 added a commit to ERYoung11/pgcli that referenced this issue Feb 4, 2024
ERYoung11 added a commit to ERYoung11/pgcli that referenced this issue Feb 4, 2024
@ERYoung11
Copy link
Contributor

Hi! @j-bennet & @dbaty. I incorporated this change with a small pull request.

j-bennet added a commit that referenced this issue Feb 6, 2024
* Fix Issue #1413, win32 psycopg

* Fix Issue #1413, win32 psycopg

* fixing syntax error

* black fix to a test

---------

Co-authored-by: Irina Truong <637013+j-bennet@users.noreply.github.com>
@nkruglikov
Copy link

Just hit this problem trying to install pgcli on MacOS via pipx.

$ pipx install pgcli
  installed package pgcli 4.0.1, installed using Python 3.12.1
  These apps are now globally available
    - pgcli
done! ✨ 🌟 ✨

$ pgcli
Traceback (most recent call last):
  File "/Users/untech/.local/bin/pgcli", line 5, in <module>
    from pgcli.main import cli
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/pgcli/main.py", line 2, in <module>
    from pgspecial.namedqueries import NamedQueries
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/pgspecial/__init__.py", line 12, in <module>
    from . import dbcommands
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/pgspecial/dbcommands.py", line 7, in <module>
    from psycopg.sql import SQL
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/psycopg/__init__.py", line 9, in <module>
    from . import pq  # noqa: F401 import early to stabilize side effects
    ^^^^^^^^^^^^^^^^
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/psycopg/pq/__init__.py", line 114, in <module>
    import_from_libpq()
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/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

This fix works:

$ pipx inject pgcli psycopg_binary
  injected package psycopg-binary into venv pgcli
done! ✨ 🌟 ✨

$ pgcli
connection is bad: No such file or directory
        Is the server running locally and accepting connections on that socket?

@kanpov
Copy link

kanpov commented Apr 13, 2024

Just hit this problem trying to install pgcli on MacOS via pipx.

$ pipx install pgcli
  installed package pgcli 4.0.1, installed using Python 3.12.1
  These apps are now globally available
    - pgcli
done! ✨ 🌟 ✨

$ pgcli
Traceback (most recent call last):
  File "/Users/untech/.local/bin/pgcli", line 5, in <module>
    from pgcli.main import cli
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/pgcli/main.py", line 2, in <module>
    from pgspecial.namedqueries import NamedQueries
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/pgspecial/__init__.py", line 12, in <module>
    from . import dbcommands
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/pgspecial/dbcommands.py", line 7, in <module>
    from psycopg.sql import SQL
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/psycopg/__init__.py", line 9, in <module>
    from . import pq  # noqa: F401 import early to stabilize side effects
    ^^^^^^^^^^^^^^^^
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/psycopg/pq/__init__.py", line 114, in <module>
    import_from_libpq()
  File "/Users/untech/.local/pipx/venvs/pgcli/lib/python3.12/site-packages/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

This fix works:

$ pipx inject pgcli psycopg_binary
  injected package psycopg-binary into venv pgcli
done! ✨ 🌟 ✨

$ pgcli
connection is bad: No such file or directory
        Is the server running locally and accepting connections on that socket?

Had the same issue with the same fix working on Linux (openSUSE Tumbleweed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants