在Python 3.7中安装Cloud-Sql-Python-Connector [PG8000]的错误

发布于 2025-01-19 17:13:30 字数 753 浏览 4 评论 0原文

我正在尝试通过我本地计算机通过Python 3.7连接到云SQL SQL SQL PostgreSQL实例。我正在遵循readme

pip install cloud-sql-python-connector[pg8000]

但是,当我在终端中运行它时,我会收到以下错误:

zsh: no matches found: cloud-sql-python-connector[pg8000]

确实存在软件包conder> cloud> cloud-sql-sql-sql-python-connector < 建立连接的部分,因为pg8000未定义:

def getconn() -> pg8000.connections.Connection:
    conn: pg8000.connections.Connection = connector.connect(
        "project:region:instance",
        "pg8000",
        user="postgres",
        password="XXXXXXXX",
        db="your-db-name"
    )
    return conn

/code>没有[PG8000]与之关联的部分,但是我无法运行下一个 我可能做错了什么,将不胜感激!

I am trying to connect to a Cloud SQL postgresql instance through python 3.7 from my local machine. I am following the guide from the README cloud-sql-python-connector. There it says to pip install the necessary module with the following command, for a postgresql instance:

pip install cloud-sql-python-connector[pg8000]

But when I run this in my terminal, I get the following error:

zsh: no matches found: cloud-sql-python-connector[pg8000]

There does exist the package cloud-sql-python-connector without the [pg8000] part associated to it, but then I can't run the next part establishing a connection, because pg8000 is not defined:

def getconn() -> pg8000.connections.Connection:
    conn: pg8000.connections.Connection = connector.connect(
        "project:region:instance",
        "pg8000",
        user="postgres",
        password="XXXXXXXX",
        db="your-db-name"
    )
    return conn

Any advice on what I might be doing wrong would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肥爪爪 2025-01-26 17:13:30

看来这实际上是 Mac 用户的 zsh 终端长期存在的问题。它不喜欢使用方括号进行 pip 安装。请参阅详细信息

如上所述,转义方括号是可行的,因此以下内容也应该如此:

pip install 'cloud-sql-python-connector[pg8000]'

It seems this is actually a long-running issue with the zsh terminal for mac users. It doesn't like pip installs with the square brackets. See details here

As mentioned escaping the square brackets works and so should the following:

pip install 'cloud-sql-python-connector[pg8000]'
情痴 2025-01-26 17:13:30

最后,我需要做的就是逃脱PIP安装命令中的方括号。这是因为方括号被解释为命令行上的模式( a>)。因此,最终的命令是:

pip install cloud-sql-python-connector\[pg8000\]

我仍然是终端的新手,但希望这对其他遇到此类问题的人有帮助。

In the end all I needed to do was escape the square brackets in the pip install command. This is because square brackets are interpreted as a pattern on the command line (article). So the final command that worked was:

pip install cloud-sql-python-connector\[pg8000\]

I'm still new to the terminal, but hopefully this helps anyone else having such problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文