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

Question:

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?

Asked By: john_jerome

||

Answers:

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.

Answered By: user13472370

Try importing ‘connector’ explicitly. I had the same error.

import pandas as pd
import snowflake as sf
from snowflake import connector
Answered By: Garglesoap

I installed python 3.6 again.
I removed this line from code

#!/usr/bin/env python

It worked.

Answered By: piedotpy
pip install snowflake-connector-python

Have you tried using this package instead in the jupyter notebook?

Answered By: JustCoder

If you have installed both snowflake and snowflake-connector-python, just uninstalling snowflake package will resolve the issue.

_

To list installed python packages, use command

pip list

Answered By: Sangameshwar

When I had this issue I had both the snowflake and snowflake-connector-python module installed in my environment, so it was confused on which one to use. If you’re trying to use connector, just pip uninstall snowflake

Answered By: mmarion

If anyone comes across this same issue and doesn’t get reprieve from the above fixes, my install had a snowflake.py file saved to the site-packages folder.

This caused the ‘import snowflake.connector’ statement to attempt to import from the snowflake.py file instead of the snowflake folder, and of course couldn’t find the connector module since the .py file isn’t a package. Renaming or moving that file solved my problem.

Answered By: samthom1

I had a sub-folder named snowflake, but depending on how I run the script it either could or could not import the snowflake.connector.

Answered By: NikoNyrh