Open NoahELE opened 1 year ago
It works after I run pip install psycopg_binary
, maybe it should be included as a dependency?
Nice work @NoahELE, you solved your own problem 🎉 . :)
In fact, we have a binary requirement for the Windows platform specified here:
https://github.com/dbcli/pgcli/blob/69dcceb5f6d3ecbcc9e7a0a48c9bdabeed470dcd/setup.py#L31-L32
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?
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
Well, that is interesting. Does your platform.system()
report as 'Windows'?
python -c 'import platform; print(platform.system())'
> python -c 'import platform; print(platform.system())'
Windows
Nice work @NoahELE, you solved your own problem 🎉 . :)
In fact, we have a binary requirement for the Windows platform specified here:
https://github.com/dbcli/pgcli/blob/69dcceb5f6d3ecbcc9e7a0a48c9bdabeed470dcd/setup.py#L31-L32
I wonder why things didn't work for you. Did you install
pgcli
into a fresh virtual environment, or was this an update? Perhapspsycopg
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
.
@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.)
@dbaty
Yes, this makes sense. We don't need to install both.
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]"
Hi! @j-bennet & @dbaty. I incorporated this change with a small pull request.
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?
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).
Description
Your environment
pgcli
fails with all args, so I cannot see its version, but it should be the latest version.pip freeze
command.