pythonsnowflake-cloud-data-platformattributeerror

Issue with using snowflake-connector-python with Python 3.x


I've spent half a day trying to figure it out on my own but now I've run out of ideas and googling requests. So basically what I want is to connect to our Snowflake database using snowflake-connector-python package. I was able to install the package just fine (together with all the related packages that were installed automatically) and my current pip3 list results in this:

Package                    Version
-------------------------- ---------
asn1crypto                 1.3.0
azure-common               1.1.25
azure-core                 1.6.0
azure-storage-blob         12.3.2
boto3                      1.13.26
botocore                   1.16.26
certifi                    2020.6.20
cffi                       1.14.0
chardet                    3.0.4
cryptography               2.9.2
docutils                   0.15.2
gitdb                      4.0.5
GitPython                  3.1.3
idna                       2.9
isodate                    0.6.0
jmespath                   0.10.0
msrest                     0.6.17
oauthlib                   3.1.0
oscrypto                   1.2.0
pip                        20.1.1
pyasn1                     0.2.3
pyasn1-modules             0.0.9
pycparser                  2.20
pycryptodomex              3.9.8
PyJWT                      1.7.1
pyOpenSSL                  19.1.0
python-dateutil            2.8.1
pytz                       2020.1
requests                   2.23.0
requests-oauthlib          1.3.0
s3transfer                 0.3.3
setuptools                 47.3.1
six                        1.15.0
smmap                      3.0.4
snowflake-connector-python 2.2.8
urllib3                    1.25.9
wheel                      0.34.2

Just to be clear, it's a clean python-venv although I've tried it on the main one, too.

When running the following code in VScode:

#!/usr/bin/env python
import snowflake.connector

# Gets the version
ctx = snowflake.connector.connect(
    user='user',
    password='pass',
    account='acc')

I'm getting this error:

AttributeError: module 'snowflake' has no attribute 'connector'

Does anyone have any idea what could be the issue here?


Solution

  • AttributeError: module 'snowflake' has no attribute 'connector'

    Your test code is likely in a file named snowflake.py which is causing a conflict in the import (it is ending up importing itself). Rename the file to some other name and it should allow you to import the right module and run the connector functions.