Python: Can't use mysql.connector, getting No module named '_version'

I just added a step and just by writing import mysql.connector

from pipedream.script_helpers import (steps, export)
import mysql.connector

# Reference data from previous steps
print(steps["trigger"]["context"]["id"])


# Return data for use in future steps
export("foo", {"test":True})

But this is throwing an error

    import mysql.connector
  File "/tmp/ee/python/mysql/connector/__init__.py", line 34, in <module>
    import _version
ModuleNotFoundError: No module named '_version'

The docs discuss import mapping

pip install mysql_connector_repackaged translates to import mysql

so I changed import to

...
import mysql
import mysql.connector
...

but still getting same error

Any ideas?

Hi @korayem

First off, welcome to the Pipedream community. Happy to have you!

This is a bit different from normal Python importing, but you need to start with the aliased import mysql first.

This import statement brings in the entire module, then I believe you can reference the mysql.connector like so:

from pipedream.script_helpers import (steps, export)
import mysql

# Connect to server
cnx = mysql.connector.connect(
    host=process.env.MYSQL_HOST,
    port=3306,
    user=process.env.MYSQL_USER,
    password=process.env.MYSQL_PASSWORD)


Thanks @pierce for your prompt response

Indeed, pipedream is a “dream” really. Coming from n8n, I find it more developer friendly which is perfect.

I forgot to mention that your suggestion was the first thing I tried after checking the docs but I got AttributeError: module 'mysql' has no attribute 'connector' which made me naturally think of import mysql.connector

We’re mainly typscript engineering team but I figured while giving pipedream a spin to test some of our maintenance cron python scripts

1 Like

Ah I received a different error when I tried with invalid credentials. Found a public mysql database to test against and I finally got the same error.

I believe this is is due to the . character in the import name. It’s a known bug with our underlying Python module system:

It’s a problem with the upstream package manager utility we use. We’re possibility moving off if it to standardize Python with other languages and fix this bug at the same time.

You can follow that issue for updates when it’s finally fixed. Sorry, but the Node.js mysql modules should work just fine, glad you’re getting value out of using Pipedream already :slight_smile:

1 Like