Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error installing cloud-sql-python-connector[pg8000] in Python 3.7

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!

like image 777
josetribiani Avatar asked Jan 25 '26 14:01

josetribiani


2 Answers

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]'
like image 109
Jack Wotherspoon Avatar answered Jan 28 '26 04:01

Jack Wotherspoon


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.

like image 25
josetribiani Avatar answered Jan 28 '26 04:01

josetribiani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!