3

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!

  • just a quick check, can you try running `python` to see what version that launches? I have the feeling you *might* have python2 installed. I tried copying/pasting the pip install command and for me that worked – Edo Akse Apr 07 '22 at 12:18
  • @EdoAkse sure, this was the output: Python 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08) – josetribiani Apr 07 '22 at 12:31
  • @EdoAkse I just realised that square brackets are interpreted as a pattern on the command line - I needed to just escape the brackets and it worked! – josetribiani Apr 07 '22 at 12:38

2 Answers2

3

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]'
Jack Wotherspoon
  • 1,131
  • 3
  • 13
1

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.