Home > front end >  Error installing cloud-sql-python-connector[pg8000] in Python 3.7
Error installing cloud-sql-python-connector[pg8000] in Python 3.7

Time:04-08

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!

CodePudding user response:

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]'

CodePudding user response:

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.

  • Related