Issue with using snowflake-connector-python with Python 3.x
Asked Answered
A

8

13

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?

Argos answered 30/6, 2020 at 13:43 Comment(0)
B
16

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.

Blub answered 30/6, 2020 at 15:16 Comment(1)
I just tried this, and renamed to snowflake_pacakges and still same error - was there another step I needed to do?Whirlybird
R
10

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

Remillard answered 4/10, 2022 at 15:8 Comment(0)
P
6

Try importing 'connector' explicitly. I had the same error.

import pandas as pd
import snowflake as sf
from snowflake import connector
Pesky answered 6/10, 2020 at 2:6 Comment(2)
Had the same problem and this solved it. Snowflake is an awesome tool with subpar python libraries - even their documentation uses snowflake.connector! :-/Reichert
2023 still works!Slow
D
3

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.

Derk answered 3/11, 2022 at 14:17 Comment(3)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Verrazano
There were no sources needed. I did the exact same thing and couldn't figure out why it wasn't working. I changed the name of the file to snowflake_connection and it immediately found the package.Mulry
This works in 2024!Moyers
N
2

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

Norris answered 23/9, 2022 at 16:21 Comment(0)
B
0

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

#!/usr/bin/env python

It worked.

Brookes answered 22/11, 2020 at 13:16 Comment(0)
E
0
pip install snowflake-connector-python

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

Epicurus answered 18/5, 2022 at 20:10 Comment(0)
N
0

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.

Nutritious answered 9/11, 2022 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.