linkedge oss2踩坑记
环境:docker python3.6:alpine
问题症状:
File "/usr/local/lib/python3.6/site-packages/Crypto/Cipher/AES.py", line 50, in <module>
from Crypto.Cipher import _AES
ImportError: cannot import name '_AES'
发现并没有import文件夹里的module,反而去找系统目录里的module
在sys.path处添加
os.path.realpath('./aliyun_oss')
打印os.path
['/opt/test_oss', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages', '/opt/test_oss/aliyun_oss']
发现加载顺序不对,在__init__.py中修改加载顺序
sys.path.insert(1,os.path.realpath('./aliyun_oss'))
['/opt/test_oss', '/opt/test_oss/aliyun_oss', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages']
顺序对了,但是提示
File "/opt/test_oss/aliyun_oss/cryptography/hazmat/primitives/asymmetric/utils.py", line 6, in <module>
from cryptography.hazmat.bindings._rust import asn1
ImportError: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /opt/test_oss/aliyun_oss/cryptography/hazmat/bindings/_rust.abi3.so)
google相同问题,在https://github.com/grpc/grpc/issues/6126找到关于此问题的解决方法:
Adding a comment as found this error via Google and the solution worked for me. Had the same error, slightly different trace - but ultimately resolved by installing the libc6-compat package.
故在容器中apk add libc6-compat
问题解决

浙公网安备 33010602011771号