Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-909618: snowflake connector is erroring out on import using python 3.11 #1724

Closed
dreddy415 opened this issue Sep 6, 2023 · 12 comments
Closed
Assignees
Labels

Comments

@dreddy415
Copy link

Python version

3.11.4

Operating system and processor architecture

macOS-13.2.1-arm64-arm-64bit

Installed packages

absl-py==1.4.0
accelerate==0.18.0
aiohttp==3.8.5
aiosignal==1.3.1
alembic==1.12.0
anyio==4.0.0
appdirs==1.4.4
asn1crypto==1.5.1
async-timeout==4.0.3
attrs==23.1.0
blinker==1.6.2
boto3==1.26.130
botocore==1.29.165
cachetools==5.3.1
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==3.2.0
click==8.1.7
cloudpickle==2.2.1
contourpy==1.1.0
cryptography==41.0.3
cycler==0.11.0
databricks-cli==0.17.7
datasets==2.8.0
dill==0.3.6
docker==6.1.3
docker-pycreds==0.4.0
entrypoints==0.4
et-xmlfile==1.1.0
exceptiongroup==1.1.3
filelock==3.12.3
Flask==2.3.3
fonttools==4.42.1
frozenlist==1.4.0
fsspec==2023.9.0
ftfy==6.1.1
gitdb==4.0.10
GitPython==3.1.34
google-auth==2.22.0
google-auth-oauthlib==1.0.0
grpcio==1.57.0
grpcio-tools==1.57.0
gunicorn==20.1.0
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==0.17.3
httpx==0.24.1
huggingface-hub==0.16.4
hyperframe==6.0.1
idna==3.4
importlib-metadata==4.13.0
itsdangerous==2.1.2
Jinja2==3.1.2
jmespath==1.0.1
joblib==1.3.2
kiwisolver==1.4.5
label-studio-sdk==0.0.23
label-studio-tools==0.0.3
langcodes==3.3.0
lxml==4.9.3
Mako==1.2.4
Markdown==3.4.4
markdown-it-py==2.2.0
MarkupSafe==2.1.3
matplotlib==3.7.2
mdurl==0.1.2
mlflow==1.29.0
mpmath==1.3.0
msgpack==1.0.5
multidict==6.0.4
multiprocess==0.70.14
networkx==3.1
nltk==3.8.1
numpy==1.25.2
oauthlib==3.2.2
openai==0.27.2
openpyxl==3.1.2
oscrypto==1.3.0
packaging==21.3
pandas==1.5.3
pandas-stubs==2.0.3.230814
pathtools==0.1.2
Pillow==10.0.0
platformdirs==3.8.1
plotly==5.16.1
portalocker==2.7.0
prometheus-client==0.17.1
prometheus-flask-exporter==0.22.4
promise==2.3
protobuf==4.24.2
psutil==5.9.5
pyarrow==11.0.0
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
pycryptodomex==3.18.0
pydantic==1.10.8
Pygments==2.16.1
PyJWT==2.8.0
PyMySQL==1.0.2
pyOpenSSL==23.2.0
pyparsing==3.0.9
pysbd==0.3.4
python-dateutil==2.8.2
pytz==2022.7.1
PyYAML==6.0.1
qdrant-client==1.1.7
querystring-parser==1.2.4
rank-bm25==0.2.2
regex==2023.8.8
requests==2.31.0
requests-oauthlib==1.3.1
responses==0.18.0
rich==13.3.5
rsa==4.9
s3transfer==0.6.2
scikit-learn==1.3.0
scipy==1.11.2
sentence-transformers==2.2.2
sentencepiece==0.1.99
sentry-sdk==1.30.0
seqeval==1.2.2
setproctitle==1.3.2
shortuuid==1.0.11
six==1.16.0
smmap==5.0.0
sniffio==1.3.0
snowflake-connector-python==3.1.1
sortedcontainers==2.4.0
SQLAlchemy==1.4.49
sqlparse==0.4.4
sympy==1.12
tabulate==0.9.0
tenacity==8.2.3
tensorboard==2.13.0
tensorboard-data-server==0.7.1
threadpoolctl==3.2.0
tokenizers==0.13.3
tomli==2.0.1
tomlkit==0.12.1
torch==2.0.1
torchvision==0.15.2
tqdm==4.66.1
transformers==4.28.1
types-pytz==2023.3.0.1
typing_extensions==4.7.1
urllib3==1.26.16
wandb==0.13.4
wcwidth==0.2.6
websocket-client==1.6.2
Werkzeug==2.3.7
wordfreq==3.0.3
xxhash==3.3.0
yarl==1.9.2
zipp==3.16.2

What did you do?

import os
import sys
from textwrap import dedent

import pandas as pd
import pytest
import pymysql
import snowflake.connector as connector
from unittest.mock import Mock, patch


Error on the import snowflake.connector as connector line of a pytest file.

What did you expect to see?

Expected it to run normally given this works locally, just not on github.

Can you set logging to DEBUG and collect the logs?

Run PYTHONPATH=./yext_ds_common pipenv run pytest -v yext_ds_common/automatcher
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.1.2, pluggy-1.3.0 -- /home/runner/.local/share/virtualenvs/yext_ds_common-btVlcoZc/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/yext_ds_common/yext_ds_common/yext_ds_common
plugins: devpi-server-6.9.2, anyio-4.0.0
collecting ... collected 9 items / 1 error

==================================== ERRORS ====================================
__________ ERROR collecting automatcher/tests/test_PrepareDataATM.py ___________
yext_ds_common/automatcher/tests/test_PrepareDataATM.py:12: in <module>
    import snowflake.connector as connector
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/__init__.py:17: in <module>
    from .connection import SnowflakeConnection
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/connection.py:30: in <module>
    from . import errors, proxy
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/errors.py:15: in <module>
    from .compat import BASE_EXCEPTION_CLASS
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/compat.py:19: in <module>
    from . import constants
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/constants.py:12: in <module>
    from .options import pyarrow as pa
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/options.py:130: in <module>
    pandas, pyarrow, installed_pandas = _import_or_missing_pandas_option()
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/options.py:83: in _import_or_missing_pandas_option
    installed_packages = {
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.9/site-packages/snowflake/connector/options.py:83: in <dictcomp>
    installed_packages = {
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/importlib/metadata.py:511: in <genexpr>
    return itertools.chain.from_iterable(
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/importlib/metadata.py:433: in __init__
    self.base = os.path.basename(self.root).lower()
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/posixpath.py:142: in basename
    p = os.fspath(p)
E   TypeError: expected str, bytes or os.PathLike object, not NoneType
=========================== short test summary info ============================
ERROR yext_ds_common/automatcher/tests/test_PrepareDataATM.py - TypeError: ex...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 2.23s ===============================
Error: Process completed with exit code 2.
@github-actions github-actions bot changed the title snowflake connector is erroring out on import using python 3.11 SNOW-909618: snowflake connector is erroring out on import using python 3.11 Sep 6, 2023
@sfc-gh-mkeller
Copy link
Collaborator

How weird, I wonder if this is caused by pipenv. @dreddy415 could you please switch momentarily to using a regular virtualenv in the short-term, please? I'm not sure if anyone on the team is familiar with pipenv
@sfc-gh-bwarsaw , do you have an idea?

For what it's worth I tried reproing your issue myself in a virtualenv, but things just worked. Here's how I tried to reproduce:

virtualenv -ppython3.11 venv311
. venv311/bin/activate
pip install -r /tmp/reqs.txt
python /tmp/s.py

@sfc-gh-bwarsaw
Copy link
Contributor

You don't mention what version of pipenv you're using. Also, while you mention that you're using Python 3.11, I see this in your output:

platform linux -- Python 3.9.18, pytest-7.1.2, pluggy-1.3.0 -- /home/runner/.local/share/virtualenvs/yext_ds_common-btVlcoZc/bin/python

i.e. Python 3.9.

While I personally prefer to use the venv stdlib library (i.e. python3 -m venv) and pipenv uses the 3rd party virtualenv package, and there are some differences that are likely not relevant, probably the Python version mismatch is what's causing the problem.

@sfc-gh-mkeller
Copy link
Collaborator

I just tried to repro with the newest pipenv version, but things worked for me:

$ pipenv --version
pipenv, version 2023.9.8
$ pipenv shell
Launching subshell in virtual environment...
 . /Users/mkeller/.local/share/virtualenvs/snowflake-connector-python-4s62fUmE/bin/activate
$  . /Users/mkeller/.local/share/virtualenvs/snowflake-connector-python-4s62fUmE
/bin/activate
$ python -c "import snowflake.connector as connector"
Failed to import ArrowResult. No Apache Arrow result set format can be used. ImportError: dlopen(/Users/mkeller/snowflakedb/snowflake-connector-python/src/snowflake/connector/arrow_iterator.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libarrow.1000.dylib
  Referenced from: <8037BD56-DE71-3894-9A22-2A9F6EA745F2> /Users/mkeller/snowflakedb/snowflake-connector-python/src/snowflake/connector/arrow_iterator.cpython-311-darwin.so
  Reason: tried: '/Users/mkeller/snowflakedb/snowflake-connector-python/src/snowflake/connector/libarrow.1000.dylib' (no such file), '/Users/mkeller/snowflakedb/snowflake-connector-python/src/snowflake/connector/libarrow.1000.dylib' (no such file), '/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/../../../../../../../lib/libarrow.1000.dylib' (no such file), '/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/../../../../../../../../../../../lib/libarrow.1000.dylib' (no such file), '/usr/local/lib/libarrow.1000.dylib' (no such file), '/usr/lib/libarrow.1000.dylib' (no such file, not in dyld cache)
(snowflake-connector-python)

@lroberts7
Copy link

lroberts7 commented Sep 12, 2023

FWIW we're also seeing this in a gh action on the same repo, in python3.11. The github action runs on ubuntu-22.04 so we're using pipenv run there, specifically pipenv run pytest -v <directory>

__________ ERROR collecting automatcher/tests/test_PrepareDataATM.py ___________
yext_ds_common/automatcher/tests/test_PrepareDataATM.py:12: in <module>
    import snowflake.connector as connector
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/__init__.py:17: in <module>
    from .connection import SnowflakeConnection
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/connection.py:30: in <module>
    from . import errors, proxy
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/errors.py:15: in <module>
    from .compat import BASE_EXCEPTION_CLASS
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/compat.py:19: in <module>
    from . import constants
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/constants.py:12: in <module>
    from .options import pyarrow as pa
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/options.py:1[30](https://github.com/yext/yext_ds_common/actions/runs/6161835934/job/16721961863?pr=38#step:6:31): in <module>
    pandas, pyarrow, installed_pandas = _import_or_missing_pandas_option()
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/options.py:83: in _import_or_missing_pandas_option
    installed_packages = {
../../../.local/share/virtualenvs/yext_ds_common-btVlcoZc/lib/python3.11/site-packages/snowflake/connector/options.py:83: in <dictcomp>
    installed_packages = {
/opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/importlib/metadata/__init__.py:915: in <genexpr>
    path.search(prepared) for path in map(FastPath, paths)
/opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/importlib/metadata/__init__.py:813: in search
    return self.lookup(self.mtime).search(name)
/opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/importlib/metadata/__init__.py:818: in mtime
    return os.stat(self.root).st_mtime
E   TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

The github action env:

env:
    pythonLocation: /opt/hostedtoolcache/Python/3.11.[5](https://github.com/yext/yext_ds_common/actions/runs/6161835934/job/16721961863?pr=38#step:6:5)/x[6](https://github.com/yext/yext_ds_common/actions/runs/6161835934/job/16721961863?pr=38#step:6:6)4
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.5/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.5/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.5/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.5/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.5/x64/lib

To be clear this happens during the test collection phase of running the relevantpytest command above.

@lroberts7
Copy link

Not sure if I'm looking in the correct repo but it looks like here:

https://github.com/python/importlib_metadata/blob/main/importlib_metadata/__init__.py#L709

it's checking for OSError but here a TypeError is raised b/c the input is None.

@lroberts7
Copy link

This thread looks relevant

@lroberts7
Copy link

lroberts7 commented Sep 12, 2023

it's also possible this is a pytest issue, e.g.

pytest-dev/pytest#9586

that also seems to exhibit similar behavior

EDIT: Will double back to this but need to focus on smth else for a bit

@lroberts7
Copy link

I looked into this a bit more. IIUC what's happening is a result of this python bug which is described here:
https://bugs.python.org/issue47060

@sfc-gh-bwarsaw
Copy link
Contributor

Issue link after migration to GitHub: python/cpython#91216

@sfc-gh-aling
Copy link
Collaborator

@lroberts7 are you still seeing the issue or it's fixed in your env already?

@lroberts7
Copy link

lroberts7 commented Feb 22, 2024

IIRC we fixed this issue via: https://community.snowflake.com/s/article/Python-Connector-fails-to-connect-with-LibraryNotFoundError-Error-detecting-the-version-of-libcrypto#openssl
so @dreddy415 unless you're still seeing this issue on your end you can mark this issue closed. I do not have permissions to close the issue.

@sfc-gh-aling
Copy link
Collaborator

closing assuming the issue is already fixed, feel free to reopen if the issue still exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants