snowflake-connector-python icon indicating copy to clipboard operation
snowflake-connector-python copied to clipboard

SNOW-179596: Executable file doesn't work, but script does

Open maranax opened this issue 6 years ago • 16 comments

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using (python --version)? 3.7

  2. What operating system and processor architecture are you using (python -c 'import platform; print(platform.platform())')? Windows

  3. What are the component versions in the environment (pip list)? Package Version


-nowflake-connector-python 2.2.8 altgraph 0.17 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 future 0.18.2 idna 2.9 isodate 0.6.0 jmespath 0.10.0 msrest 0.6.17 numpy 1.19.0 oauthlib 3.1.0 oscrypto 1.2.0 pandas 1.0.5 pefile 2019.4.18 pip 20.1.1 pyarrow 0.17.1 pycparser 2.20 pycryptodomex 3.9.8 PyInstaller 3.6 PyJWT 1.7.1 pyodbc 4.0.30 pyOpenSSL 19.1.0 python-dateutil 2.8.1 pytz 2020.1 pywin32-ctypes 0.2.0 requests 2.23.0 requests-oauthlib 1.3.0 s3transfer 0.3.3 setuptools 41.2.0 six 1.15.0 snowflake 0.0.3 snowflake-connector-python 2.2.9 snowflake-sqlalchemy 1.2.3 SQLAlchemy 1.2.12 urllib3 1.25.9

  1. What did you do? Have a script to transfer data from SQL Server table to a Snowflake table. Script works fine, no issues. I try to create an executable file in order to run it on schedule. I use pyinstaller: pyinstaller --OneFile DataToSF.py It's created. However, when I run it, it get an error message: Traceback (most recent call last): File "DataToSF.py", line 4, in from snowflake.connector.pandas_tools import write_pandas File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in load_unlocked File "c:\python376\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module exec(bytecode, module.dict) File "site-packages\snowflake\connector_init.py", line 17, in File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "c:\python376\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module exec(bytecode, module.dict) File "site-packages\snowflake\connector\connection.py", line 47, in File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "c:\python376\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module exec(bytecode, module.dict) File "site-packages\snowflake\connector\cursor.py", line 48, in File "arrow_result.pyx", line 12, in init snowflake.connector.arrow_result SystemError: initialization of arrow_iterator raised unreported exception [12484] Failed to execute script DataToSF

Why is that?

maranax avatar Jul 30 '20 15:07 maranax

Hi @maranax I'd guess that you will need to add our compiled C code manually to your pyinstaller file.

sfc-gh-mkeller avatar Jul 30 '20 17:07 sfc-gh-mkeller

Hi @sfc-gh-mkeller . Thank you for your response. Sorry, I have no idea how to do it. It would be greatly appreciated if you walk me through.

maranax avatar Jul 30 '20 17:07 maranax

What files are needed to add?

maranax avatar Jul 30 '20 19:07 maranax

Hi @sfc-gh-mkeller,

My team is struggling with the same problem here. When I run a debug on our packaged exe that includes a snowflake connector, I get the same error as @maranax. Our script also runs without any import errors.

Can you please provide the name and location of the files that need to be included in the pyinstaller setup?

Packaging a database connector into an application is a very basic requirement. My team is unable to make use of our company's migration to snowflake because we cannot resolve this issue. Thank you.

wstreyer avatar Oct 21 '20 04:10 wstreyer

@sf-gh-mkeller, please consider contributing a pyinstaller hook file so that snowflake can be packaged into an application out of the box.

https://github.com/pyinstaller/pyinstaller-hooks-contrib

wstreyer avatar Oct 21 '20 17:10 wstreyer

We were finally able to package our application by doing the following (we are using a .spec file):

  • add 'snowflake' to hiddenimports
  • create a hook file for snowflake, add its path to hookspath

hook-snowflake.py

from PyInstaller.utils.hooks  import  copy_metadata
datas = []
datas.append(copy_metadata('snowflake-sqlalchemy')[0])
datas.append(copy_metadata('snowflake-connector-python')[0])

We are not certain each of these steps is necessary, but here is the breakthrough:

conda install pyarrow or pip install pyarrow

This was apparently not installed with the snowflake packages. Scripts could run without it, but our packaged application failed otherwise.

For reference, this forum post was a great help to us: https://community.snowflake.com/s/question/0D50Z00009Huss0SAB/how-to-get-pyinstaller-to-pack-snowflake-sqlalchemy-dialect

wstreyer avatar Oct 21 '20 22:10 wstreyer

Thank you, @wstreyer. At least it's something. I really appreciate it.

maranax avatar Oct 21 '20 23:10 maranax

When I have a chance I will post some pyinstsller debugging tricks that we relied on.

On Wed, Oct 21, 2020, 6:02 PM maranax [email protected] wrote:

Thank you, @wstreyer https://github.com/wstreyer. At least it's something. I really appreciate it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/snowflakedb/snowflake-connector-python/issues/346#issuecomment-713932201, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDJZIKTW3MATL2WLDDOY2TSL5R65ANCNFSM4POCIJRA .

wstreyer avatar Oct 21 '20 23:10 wstreyer

As a follow up, after successfully packaging and starting our application, the snowflake functionality still didn't work. We were able to confirm that it all works from a script or command line, but there is still something that doesn't get packaged that is needed during runtime.

Wish SF would provide some help.

wstreyer avatar Dec 04 '20 17:12 wstreyer

@sfc-gh-mkeller An even better solution would be to provide and test PyInstaller hooks within your repo. It is very easy, see the example at https://github.com/pyinstaller/hooksample Since @wstreyer already posted a working hook, this comes down to copy some file into your repo, adjust another file and add some simple tests. If you want me to take this job, feel free to contact me.

htgoebel avatar Jan 14 '21 13:01 htgoebel

@wstreyer

When I have a chance I will post some pyinstsller debugging tricks that we relied on.

May I suggest you to improve the PyInstaller wiki https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong and https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly

htgoebel avatar Jan 14 '21 13:01 htgoebel

We gave up on receiving any support from Snowflake and built a REST API to execute the queries for us. This way we only need to package the standard modules for supporting web protocols, which we were already using anyway. This approach has worked well for us.

wstreyer avatar Jan 18 '21 19:01 wstreyer

It looks like our compiled C++ code is not included. Take a look at https://github.com/snowflakedb/snowflake-connector-python/blob/0c3e6c4cbf84f8f16d9f035bf92534766508def4/src/snowflake/connector/arrow_result.pyx#L12

So to build these extension, you can run the following from the repo's root directory: $ pip wheel --no-deps -w dist --no-clean -v . this will tell you where the temporary location of the build is while building stuff. For me the built sos was here: /tmp/pip-req-build-2feu88ht/build/lib.linux-x86_64-3.6/snowflake/connector/arrow_iterator.cpython-36m-x86_64-linux-gnu.so and /tmp/pip-req-build-2feu88ht/build/lib.linux-x86_64-3.6/snowflake/connector/arrow_result.cpython-36m-x86_64-linux-gnu.so.

I think that these sos are not included by PyInstaller.

sfc-gh-mkeller avatar Jan 19 '21 17:01 sfc-gh-mkeller

This is not something we can pickup in the short term. Adding it to our backlog. If anyone here is able to contribute PyInstaller hooks, our team can review.

sfc-gh-hkapre avatar Jun 10 '21 21:06 sfc-gh-hkapre

I think I found a solution for this problem: a hook file for snowflake makes the trick: Create the following file in your root folder

# hook-snowflake.py
# snow_logging is mandatory to get arrow working

hiddenimports = ["snowflake.connector.snow_logging"]

when you generate your exe, just add --additional-hooks-dir . to take the hook file in account.

example: pyinstaller --additional-hooks-dir . --noconfirm --onefile main.py

lilian-arnaud avatar Dec 22 '22 14:12 lilian-arnaud

To clean up and re-prioritize bugs and feature requests we are closing all issues older than 6 months as of March 1, 2023. If there are any issues or feature requests that you would like us to address, please re-create them. For urgent issues, opening a support case with this link Snowflake Community is the fastest way to get a response

sfc-gh-achandrasekaran avatar Mar 14 '23 18:03 sfc-gh-achandrasekaran