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?

john_jerome
  • 276
  • 1
  • 2
  • 8

8 Answers8

15

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.

  • I just tried this, and renamed to snowflake_pacakges and still same error - was there another step I needed to do? – 0004 Apr 14 '22 at 02:10
5

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

import pandas as pd
import snowflake as sf
from snowflake import connector
Garglesoap
  • 565
  • 6
  • 18
  • 1
    Had the same problem and this solved it. Snowflake is an awesome tool with subpar python libraries - even their documentation uses `snowflake.connector`! :-/ – Philipp_Kats Jun 12 '21 at 19:22
5

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

mmarion
  • 859
  • 8
  • 20
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

1

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.

samthom1
  • 11
  • 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](/help/how-to-answer). – Community Nov 07 '22 at 06:30
0

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

#!/usr/bin/env python

It worked.

Dharman
  • 30,962
  • 25
  • 85
  • 135
piedotpy
  • 11
  • 2
0
pip install snowflake-connector-python

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

JustCoder
  • 327
  • 1
  • 4
  • 13
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.

NikoNyrh
  • 3,578
  • 2
  • 18
  • 32