oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.17k stars 101 forks source link

import paramiko not working #404

Closed liuruibin closed 2 weeks ago

liuruibin commented 2 weeks ago
Package Version
bcrypt 4.1.3
cffi 1.16.0
cryptography 42.0.8
paramiko 2.12.0
pip 22.0.2
pycparser 2.22
PyNaCl 1.5.0
setuptools 59.6.0
six 1.16.0

org.graalvm.polyglot.PolyglotException: ImportError: cannot import name 'exceptions' from 'cryptography.hazmat.bindings._rust' (unknown location)

msimacek commented 2 weeks ago

On GraalPy 24.0.1 I can import paramiko successfully using these versions: PyNaCl-1.5.0 bcrypt-4.0.1 cffi-1.15.1 cryptography-41.0.3 paramiko-3.4.0 pycparser-2.22 six-1.16.0. Can you try those, please?

liuruibin commented 2 weeks ago
image image
msimacek commented 2 weeks ago

How did you create the virtualenv? It seem that you created it with CPython and are trying to use it with GraalPy, but that can't work. You need to create the virtualenv with GraalPy and use GraalPy to install things there. I.e. use graalpy -m venv my-venv, activate it, install the packages there and use the path to my-venv/bin/python as python.Executable option

liuruibin commented 2 weeks ago

Dockerfile

FROM ghcr.io/graalvm/graalpy-community:24.0.1

RUN source /app/graalenv/bin/activate && \
    pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0

still not woking, the error is as follows:

2024-06-29T05:10:58.3870614Z #7 [linux/arm64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:11:05.5193873Z #7 7.283 Collecting PyNaCl==1.5.0
2024-06-29T05:11:05.6249186Z #7 7.388   Downloading PyNaCl-1.5.0.tar.gz (3.4 MB)
2024-06-29T05:11:06.6158419Z #7 8.225      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 4.4 MB/s eta 0:00:00
2024-06-29T05:11:08.2571332Z #7 ...
2024-06-29T05:11:08.2571963Z 
2024-06-29T05:11:08.2573296Z #8 [linux/amd64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:11:08.2575111Z #8 7.296 Collecting PyNaCl==1.5.0
2024-06-29T05:11:08.2576347Z #8 7.405   Downloading PyNaCl-1.5.0.tar.gz (3.4 MB)
2024-06-29T05:11:08.2577522Z #8 8.667      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 2.9 MB/s eta 0:00:00
2024-06-29T05:11:20.0529683Z #8 ...
2024-06-29T05:11:20.0530144Z 
2024-06-29T05:11:20.0531434Z #7 [linux/arm64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:11:20.0533242Z #7 21.82 Looking for GraalPy patches for PyNaCl
2024-06-29T05:11:20.1606529Z #7 21.87   Installing build dependencies: started
2024-06-29T05:11:30.1194697Z #7 ...
2024-06-29T05:11:30.1195303Z 
2024-06-29T05:11:30.1196677Z #8 [linux/amd64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:11:30.1198522Z #8 21.92 Looking for GraalPy patches for PyNaCl
2024-06-29T05:11:30.1199738Z #8 21.98   Installing build dependencies: started
2024-06-29T05:12:20.2667803Z #8 82.03   Installing build dependencies: still running...
2024-06-29T05:12:20.4489381Z #8 ...
2024-06-29T05:12:20.4545343Z 
2024-06-29T05:12:20.4547177Z #7 [linux/arm64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:12:20.4549074Z #7 82.06   Installing build dependencies: still running...
2024-06-29T05:12:45.1685880Z #7 ...
2024-06-29T05:12:45.1686350Z 
2024-06-29T05:12:45.1687643Z #8 [linux/amd64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:12:45.1690263Z #8 106.9   Installing build dependencies: finished with status 'error'
2024-06-29T05:12:45.4412375Z #8 107.2   error: subprocess-exited-with-error
2024-06-29T05:12:45.4413238Z #8 107.2   
2024-06-29T05:12:45.4414531Z #8 107.2   × pip subprocess to install build dependencies did not run successfully.
2024-06-29T05:12:45.4415697Z #8 107.2   │ exit code: 1
2024-06-29T05:12:45.4416482Z #8 107.2   ╰─> [112 lines of output]
2024-06-29T05:12:45.4417363Z #8 107.2       Collecting setuptools>=40.8.0
2024-06-29T05:12:45.4418526Z #8 107.2         Downloading setuptools-70.1.1-py3-none-any.whl (883 kB)
2024-06-29T05:12:45.4419889Z #8 107.2            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 883.3/883.3 kB 913.5 kB/s eta 0:00:00
2024-06-29T05:12:45.4421038Z #8 107.2       Collecting wheel
2024-06-29T05:12:45.4422041Z #8 107.2         Downloading wheel-0.41.2-py3-none-any.whl (64 kB)
2024-06-29T05:12:45.4423479Z #8 107.2            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.8/64.8 kB 617.7 kB/s eta 0:00:00
2024-06-29T05:12:45.4424413Z #8 107.2       Collecting cffi>=1.4.1
2024-06-29T05:12:45.4425509Z #8 107.2         Downloading cffi-1.15.1.tar.gz (508 kB)
2024-06-29T05:12:45.4426909Z #8 107.2            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 508.5/508.5 kB 2.3 MB/s eta 0:00:00
2024-06-29T05:12:45.4428711Z #8 107.2       auto-patching C API usages in /tmp/pip-install-mocz_ie3/cffi_38a00dd95fd646eba48b0a51a64ece51/c/minibuffer.h
2024-06-29T05:12:45.4431820Z #8 107.2       auto-patching C API usages in /tmp/pip-install-mocz_ie3/cffi_38a00dd95fd646eba48b0a51a64ece51/c/_cffi_backend.c
2024-06-29T05:12:45.4433382Z #8 107.2       Looking for GraalPy patches for cffi
2024-06-29T05:12:45.4434872Z #8 107.2       Patching package cffi using /opt/graalpy-24.0.1/lib/graalpy24.0/patches/cffi/cffi-1.15.1.patch
2024-06-29T05:12:45.4436252Z #8 107.2       patching file c/_cffi_backend.c
2024-06-29T05:12:45.4437253Z #8 107.2       patching file c/lib_obj.c
2024-06-29T05:12:45.4438083Z #8 107.2       patching file c/misc_thread_common.h
2024-06-29T05:12:45.4438966Z #8 107.2         Preparing metadata (setup.py): started
2024-06-29T05:12:45.4440495Z #8 107.2         Preparing metadata (setup.py): finished with status 'done'
2024-06-29T05:12:45.4441425Z #8 107.2       Collecting pycparser
2024-06-29T05:12:45.4442433Z #8 107.2         Downloading pycparser-2.22-py3-none-any.whl (117 kB)
2024-06-29T05:12:45.4443915Z #8 107.2            ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.6/117.6 kB 1.9 MB/s eta 0:00:00
2024-06-29T05:12:45.4445154Z #8 107.2       Installing collected packages: wheel, setuptools, pycparser, cffi
2024-06-29T05:12:45.4446388Z #8 107.2       Looking for GraalPy patches for wheel
2024-06-29T05:12:45.4447885Z #8 107.2       Patching package wheel using /opt/graalpy-24.0.1/lib/graalpy24.0/patches/wheel/wheel-0.41.2.patch
2024-06-29T05:12:45.4449209Z #8 107.2       patching file wheel/vendored/packaging/tags.py
2024-06-29T05:12:45.4450392Z #8 107.2       Looking for GraalPy patches for setuptools
2024-06-29T05:12:45.4452060Z #8 107.2       Patching package setuptools using /opt/graalpy-24.0.1/lib/graalpy24.0/patches/setuptools/setuptools-65.patch
2024-06-29T05:12:45.4453505Z #8 107.2       patching file _distutils_hack/__init__.py
2024-06-29T05:12:45.4454692Z #8 107.2       Hunk #1 succeeded at 37 (offset -7 lines).
2024-06-29T05:12:45.4455709Z #8 107.2       Hunk #2 succeeded at 195 (offset -7 lines).
2024-06-29T05:12:45.4456735Z #8 107.2       Hunk #3 succeeded at 208 with fuzz 1 (offset -7 lines).
2024-06-29T05:12:45.4458276Z #8 107.2       patching file setuptools/_vendor/importlib_metadata/_compat.py
2024-06-29T05:12:45.4459382Z #8 107.2       Hunk #1 succeeded at 37 (offset 1 line).
2024-06-29T05:12:45.4460279Z #8 107.2       Looking for GraalPy patches for pycparser
2024-06-29T05:12:45.4463838Z #8 107.2         DEPRECATION: cffi is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
2024-06-29T05:12:45.4466987Z #8 107.2         Running setup.py install for cffi: started
2024-06-29T05:12:45.4468345Z #8 107.2         Running setup.py install for cffi: finished with status 'error'
2024-06-29T05:12:45.4469557Z #8 107.2         error: subprocess-exited-with-error
2024-06-29T05:12:45.4470368Z #8 107.2       
2024-06-29T05:12:45.4471359Z #8 107.2         × Running setup.py install for cffi did not run successfully.
2024-06-29T05:12:45.4472412Z #8 107.2         │ exit code: 1
2024-06-29T05:12:45.4473203Z #8 107.2         ╰─> [60 lines of output]
2024-06-29T05:12:45.4474371Z #8 107.2             Package libffi was not found in the pkg-config search path.
2024-06-29T05:12:45.4475573Z #8 107.2             Perhaps you should add the directory containing `libffi.pc'
2024-06-29T05:12:45.4476589Z #8 107.2             to the PKG_CONFIG_PATH environment variable
2024-06-29T05:12:45.4477808Z #8 107.2             Package 'libffi', required by 'virtual:world', not found
2024-06-29T05:12:45.4478989Z #8 107.2             Package libffi was not found in the pkg-config search path.
2024-06-29T05:12:45.4480244Z #8 107.2             Perhaps you should add the directory containing `libffi.pc'
2024-06-29T05:12:45.4481387Z #8 107.2             to the PKG_CONFIG_PATH environment variable
2024-06-29T05:12:45.4482896Z #8 107.2             Package 'libffi', required by 'virtual:world', not found
2024-06-29T05:12:45.4484107Z #8 107.2             Package libffi was not found in the pkg-config search path.
2024-06-29T05:12:45.4485472Z #8 107.2             Perhaps you should add the directory containing `libffi.pc'
2024-06-29T05:12:45.4486530Z #8 107.2             to the PKG_CONFIG_PATH environment variable
2024-06-29T05:12:45.4487832Z #8 107.2             Package 'libffi', required by 'virtual:world', not found
2024-06-29T05:12:45.4489098Z #8 107.2             Package libffi was not found in the pkg-config search path.
2024-06-29T05:12:45.4490235Z #8 107.2             Perhaps you should add the directory containing `libffi.pc'
2024-06-29T05:12:45.4491464Z #8 107.2             to the PKG_CONFIG_PATH environment variable
2024-06-29T05:12:45.4492632Z #8 107.2             Package 'libffi', required by 'virtual:world', not found
2024-06-29T05:12:45.4493878Z #8 107.2             Package libffi was not found in the pkg-config search path.
2024-06-29T05:12:45.4495195Z #8 107.2             Perhaps you should add the directory containing `libffi.pc'
2024-06-29T05:12:45.4496278Z #8 107.2             to the PKG_CONFIG_PATH environment variable
2024-06-29T05:12:45.4497439Z #8 107.2             Package 'libffi', required by 'virtual:world', not found
2024-06-29T05:12:45.4499910Z #8 107.2             /app/graalenv/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
2024-06-29T05:12:45.4501845Z #8 107.2               warnings.warn(msg, warning_class)
2024-06-29T05:12:45.4502655Z #8 107.2             running install
2024-06-29T05:12:45.4504985Z #8 107.2             /app/graalenv/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
2024-06-29T05:12:45.4506978Z #8 107.2               warnings.warn(
2024-06-29T05:12:45.4507804Z #8 107.2             running build
2024-06-29T05:12:45.4508584Z #8 107.2             running build_py
2024-06-29T05:12:45.4509476Z #8 107.2             creating build
2024-06-29T05:12:45.4510528Z #8 107.2             creating build/lib.linux-x86_64-3.10
2024-06-29T05:12:45.4511579Z #8 107.2             creating build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4512689Z #8 107.2             copying cffi/lock.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4514059Z #8 107.2             copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4515380Z #8 107.2             copying cffi/verifier.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4516614Z #8 107.2             copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4518198Z #8 107.2             copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4522859Z #8 107.2             copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4524359Z #8 107.2             copying cffi/model.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4525744Z #8 107.2             copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4527059Z #8 107.2             copying cffi/cparser.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4528494Z #8 107.2             copying cffi/commontypes.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4529760Z #8 107.2             copying cffi/api.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4531029Z #8 107.2             copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4532498Z #8 107.2             copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4533852Z #8 107.2             copying cffi/recompiler.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4535087Z #8 107.2             copying cffi/error.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4536694Z #8 107.2             copying cffi/__init__.py -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4537882Z #8 107.2             copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4539253Z #8 107.2             copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4540680Z #8 107.2             copying cffi/_embedding.h -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4541944Z #8 107.2             copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.10/cffi
2024-06-29T05:12:45.4543017Z #8 107.2             running build_ext
2024-06-29T05:12:45.4543883Z #8 107.2             building '_cffi_backend' extension
2024-06-29T05:12:45.4544777Z #8 107.2             creating build/temp.linux-x86_64-3.10
2024-06-29T05:12:45.4545917Z #8 107.2             creating build/temp.linux-x86_64-3.10/c
2024-06-29T05:12:45.4548841Z #8 107.2             gcc -DNDEBUG -D_GNU_SOURCE=1 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/app/graalenv/include -I/opt/graalpy-24.0.1/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.10/c/_cffi_backend.o
2024-06-29T05:12:45.4551587Z #8 107.2             c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
2024-06-29T05:12:45.4552727Z #8 107.2                15 | #include <ffi.h>
2024-06-29T05:12:45.4553474Z #8 107.2                   |          ^~~~~~~
2024-06-29T05:12:45.4554326Z #8 107.2             compilation terminated.
2024-06-29T05:12:45.4555438Z #8 107.2             error: command '/usr/bin/gcc' failed with exit code 1
2024-06-29T05:12:45.4556329Z #8 107.2             [end of output]
2024-06-29T05:12:45.4557007Z #8 107.2       
2024-06-29T05:12:45.4558062Z #8 107.2         note: This error originates from a subprocess, and is likely not a problem with pip.
2024-06-29T05:12:45.4641191Z #8 107.2       error: legacy-install-failure
2024-06-29T05:12:45.4642206Z #8 107.2       
2024-06-29T05:12:45.4643175Z #8 107.2       × Encountered error while trying to install package.
2024-06-29T05:12:45.4644161Z #8 107.2       ╰─> cffi
2024-06-29T05:12:45.4645303Z #8 107.2       
2024-06-29T05:12:45.4646164Z #8 107.2       note: This is an issue with the package mentioned above, not pip.
2024-06-29T05:12:45.4647241Z #8 107.2       hint: See above for output from the failure.
2024-06-29T05:12:45.4648132Z #8 107.2       [end of output]
2024-06-29T05:12:45.4648747Z #8 107.2   
2024-06-29T05:12:45.4649662Z #8 107.2   note: This error originates from a subprocess, and is likely not a problem with pip.
2024-06-29T05:12:45.6832144Z #8 107.3 error: subprocess-exited-with-error
2024-06-29T05:12:45.6833033Z #8 107.3 
2024-06-29T05:12:45.6834182Z #8 107.3 × pip subprocess to install build dependencies did not run successfully.
2024-06-29T05:12:45.6835705Z #8 107.3 │ exit code: 1
2024-06-29T05:12:45.6836518Z #8 107.3 ╰─> See above for output.
2024-06-29T05:12:45.6837410Z #8 107.3 
2024-06-29T05:12:45.6838359Z #8 107.3 note: This error originates from a subprocess, and is likely not a problem with pip.
2024-06-29T05:12:45.9269462Z #8 ERROR: process "/bin/sh -c source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0" did not complete successfully: exit code: 1
2024-06-29T05:12:45.9272234Z 
2024-06-29T05:12:45.9274047Z #7 [linux/arm64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:12:46.1588514Z #7 CANCELED
2024-06-29T05:12:46.1656231Z ------
2024-06-29T05:12:46.1657917Z  > [linux/amd64 2/3] RUN source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0:
2024-06-29T05:12:46.1659884Z 107.2       [end of output]
2024-06-29T05:12:46.1660429Z 107.2   
2024-06-29T05:12:46.1661331Z 107.2   note: This error originates from a subprocess, and is likely not a problem with pip.
2024-06-29T05:12:46.1663230Z 107.3 error: subprocess-exited-with-error
2024-06-29T05:12:46.1663947Z 107.3 
2024-06-29T05:12:46.1664994Z 107.3 × pip subprocess to install build dependencies did not run successfully.
2024-06-29T05:12:46.1666379Z 107.3 │ exit code: 1
2024-06-29T05:12:46.1667093Z 107.3 ╰─> See above for output.
2024-06-29T05:12:46.1667824Z 107.3 
2024-06-29T05:12:46.1668905Z 107.3 note: This error originates from a subprocess, and is likely not a problem with pip.
2024-06-29T05:12:46.1670039Z ------
2024-06-29T05:12:46.1670690Z Dockerfile.graalpy:3
2024-06-29T05:12:46.1671245Z --------------------
2024-06-29T05:12:46.1671789Z    2 |     
2024-06-29T05:12:46.1672479Z    3 | >>> RUN source /app/graalenv/bin/activate && \
2024-06-29T05:12:46.1673986Z    4 | >>>     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
2024-06-29T05:12:46.1675334Z    5 |     
2024-06-29T05:12:46.1675947Z --------------------
2024-06-29T05:12:46.1678432Z ERROR: failed to solve: process "/bin/sh -c source /app/graalenv/bin/activate &&     pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0" did not complete successfully: exit code: 1
2024-06-29T05:12:46.1728331Z ##[error]Process completed with exit code 1.
msimacek commented 2 weeks ago

Some of the packages need additional dependencies in the system to build. Here's a modified Dockerfile that works for me:

FROM ghcr.io/graalvm/graalpy-community:24.0.1

RUN yum -y install libffi-devel rust cargo && yum clean all

RUN source /app/graalenv/bin/activate && \
    pip install PyNaCl==1.5.0 bcrypt==4.0.1 cffi==1.15.1 cryptography==41.0.3 paramiko==3.4.0 pycparser==2.22 six==1.16.0
liuruibin commented 2 weeks ago
public class TestMain {
    @Test
    public void test1() {
        try (Context context = Context.newBuilder("python")
                .allowAllAccess(true)
                .option("python.PythonPath", "/app/graalenv/lib/python3.10/site-packages")
//                .option("python.Executable", "/app/graalenv/bin/python")
                .build()) {
            String script3 = """
                    import sys
                    print('PYTHONPATH:', sys.path)
                    import paramiko
                    print('paramiko imported successfully')
                    """;
            context.eval("python", script3);
        }
    }

    @Test
    public void test2() {
        try (Context context = Context.newBuilder("python")
                .allowAllAccess(true)
                .option("python.PythonPath", "/app/graalenv/lib/python3.10/site-packages")
//                .option("python.Executable", "/app/graalenv/bin/python")
                .build()) {
            String script3 = """
                    import sys
                    print('PYTHONPATH:', sys.path)
                    import paramiko
                    print('paramiko imported successfully')
                    """;
            context.eval("python", script3);
        }
    }
}

test1 is ok, test2 error:

SystemError: no bitcode found for /app/graalenv/lib/python3.10/site-packages/cryptography/hazmat/bindings/_rust.pyd
        at <python> <module>(Unknown)
        at org.graalvm.polyglot.Context.eval(Context.java:428)
        at io.metersphere.python.scriptengine.TestMain.test2(TestMain.java:37)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
msimacek commented 2 weeks ago

Due to technical limitations, only one context in the process can properly use native modules (the modules implemented in C/rust, like cryptography), other contexts will try to fall back to llvm emulation (which wouldn't work for packages that are in rust, like cryptography). Please use one context for all tests using paramiko.