Unable to Deploy streamlit app with snowflake-connector-python

Hi ,

I have built an streamlit app in Github.

In the requirements.txt I have below libraries.
charset-normalizer==2.0.12
snowflake-connector-python==2.7.9

In google colab application is running fine. But when I am trying to deploy the same from github I am getting below error message from stremlit cloud.

ERROR:

I have also tried to install charset-normalizer==2.0.12 ,but still I am getting the same error.

Kindly help me to resolve this issue.

1 Like

HI @Smita_Sahoo, welcome to the Streamlit community!

Can you post the actual code you are running (without any credentials)?

Best,
Randy

Hi @randyzwitch ,
Thank you for your response.
Kindly find my github URL for the code reference.

Regards
smita

The full error is as follows:

File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/scriptrunner/script_runner.py", line 554, in _run_script
    exec(code, module.__dict__)
File "View_RawData.py", line 7, in <module>
    import snowflake.connector
File "/home/appuser/venv/lib/python3.9/site-packages/snowflake/connector/__init__.py", line 16, in <module>
    from .connection import SnowflakeConnection
File "/home/appuser/venv/lib/python3.9/site-packages/snowflake/connector/connection.py", line 53, in <module>
    from .cursor import LOG_MAX_QUERY_LENGTH, SnowflakeCursor
File "/home/appuser/venv/lib/python3.9/site-packages/snowflake/connector/cursor.py", line 62, in <module>
    from .file_transfer_agent import SnowflakeFileTransferAgent
File "/home/appuser/venv/lib/python3.9/site-packages/snowflake/connector/file_transfer_agent.py", line 21, in <module>
    from .azure_storage_client import SnowflakeAzureRestClient
File "/home/appuser/venv/lib/python3.9/site-packages/snowflake/connector/azure_storage_client.py", line 18, in <module>
    from .encryption_util import EncryptionMetadata
File "/home/appuser/venv/lib/python3.9/site-packages/snowflake/connector/encryption_util.py", line 15, in <module>
    from Cryptodome.Cipher import AES
File "/home/appuser/venv/lib/python3.9/site-packages/Cryptodome/Cipher/__init__.py", line 27, in <module>
    from Cryptodome.Cipher._mode_ecb import _create_ecb_cipher
File "/home/appuser/venv/lib/python3.9/site-packages/Cryptodome/Cipher/_mode_ecb.py", line 29, in <module>
    from Cryptodome.Util._raw_api import (load_pycryptodome_raw_lib,
File "/home/appuser/venv/lib/python3.9/site-packages/Cryptodome/Util/_raw_api.py", line 81, in <module>
    ffi = FFI()
File "/home/appuser/.conda/lib/python3.7/site-packages/cffi/api.py", line 54, in __init__
    raise Exception("Version mismatch: this is the 'cffi' package version %s, located in %r.  When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r.  The two versions should be equal; check your installation." % (

I would guess the solution is to set the Python version explicitly in the advanced settings of Streamlit Cloud to whatever version you were using on Colab so that you don’t have a version mismatch with the Snowflake connector package.

Best,
Randy

I am facing the same error and i dont see a solution on how to match the versions. Can you share where i can look for advanced settings, i did not find them on streamlit.io. I have also tried multiple versions of snowflake python connector, but of no use. Please help.

The Advanced Settings screen is shown upon deployment:

Best,
Randy

Thanks Randy, The information is useful. Unfortunately its not helping. I tried all different versions 3.7, 3.8, 3.9 and 3.10. I have also tried with below code in requirements cffi==1.15.0 did not work, tried cffi==1.15.1 did not work. I still get below error, even after reboot and cache clearing. any other thoughts on what i should try to make it work?
Here is my repo link, if that helps.
renuka-tumati/first-streamlit-app (github.com)

File "/home/appuser/.conda/lib/python3.7/site-packages/cffi/api.py", line 54, in __init__
    raise Exception("Version mismatch: this is the 'cffi' package version %s, located in %r.  When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r.  The two versions should be equal; check your installation." % (
Exception: Version mismatch: this is the 'cffi' package version 1.15.0, located in '/home/appuser/.conda/lib/python3.7/site-packages/cffi/api.py'.  When we import the top-level '_cffi_backend' extension module, we get version 1.15.1, located in '/home/appuser/venv/lib/python3.9/site-packages/_cffi_backend.cpython-39-x86_64-linux-gnu.so'.  The two versions should be equal; check your installation.

Hi @renuka-tumati & @Smita_Sahoo :wave:

The Snowflake installation docs for the Python connector include 3 points:

https://docs.snowflake.com/en/user-guide/python-connector-install.html#step-1-install-the-connector

From this thread, it looks like users are skipping directly to point 3 which concerns pip install.

Point 2 states:

  1. To install the dependent libraries, run the pip (or pip3 ) command and point to the requirements file for that version of the connector.

For example, suppose the latest Snowflake Connector for Python version is 2.7.9 and you are using Python 3.9. To install the dependent libraries for that version of the connector, run the following command:
pip install -r https://raw.githubusercontent.com/snowflakedb/snowflake-connector-python/main/tested_requirements/requirements_39.reqs

Solution

  1. Determine the version of Python you want your app to use and specify the Python version in the Advanced settings modal on Streamlit Cloud
  2. Get the raw URL of the .reqs file for the corresponding version of Python from the Snowflake repo
  3. Add the raw link to the .reqs file in your requirements.txt file and prepend the line with -r

So, if you’re using the default Python 3.9 on Streamlit Cloud

  1. Select Python 3.9 from Advanced settings
  2. The corresponding .reqs file is requirements_39.reqs. The raw URL for that file is https://raw.githubusercontent.com/snowflakedb/snowflake-connector-python/main/tested_requirements/requirements_39.reqs
  3. The contents of your requirements.txt:
streamlit==1.11.0
-r https://raw.githubusercontent.com/snowflakedb/snowflake-connector-python/main/tested_requirements/requirements_39.reqs

Hi Snehan, Thanks for sharing!!
worked with below content atrequirements.txt:

streamlit==1.11.0

-r https://raw.githubusercontent.com/snowflakedb/snowflake-connector-python/v2.7.9/tested_requirements/requirements_37.reqs
snowflake-connector-python==2.7.9 :grinning::grinning::grinning: