问题
I 'm using Jython to execute a python script connect_host.py which uses paramiko module to connect to a specified host.
paramiko module internally uses Crypto module, and Crypto.Util module uses Counter.py which in turn tries to import _counter,which is present in the same location Crypto.Util but as an .so file .
On execution, python throws the following error:
File "/location/helper/connect_host.py", line 3, in <module>
import paramiko
File "/python/modules/paramiko/__init__.py", line 69, in <module>
from transport import SecurityOptions, Transport
File "/python/modules/paramiko/transport.py", line 32, in <module>
from paramiko import util
File "/python/modules/paramiko/util.py", line 32, in <module>
from paramiko.common import *
File "/python/modules/paramiko/common.py", line 98, in <module>
from Crypto import Random
File "/python/modules/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/python/modules/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/python/modules/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
import FortunaGenerator
File "/python/modules/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in <module>
from Crypto.Util import Counter
File "/python/modules/Crypto/Util/Counter.py", line 29, in <module>
from Crypto.Util import _counter
ImportError: cannot import name _counter
How to make Jython load _counter module,which is a .so file??????
回答1:
In this Python documentation it says:
Jython is an implementation of the Python language for the Java platform. Jython 2.7 implements the same language as CPython 2.7 ....
... Jython programs cannot currently use CPython extension modules written in C. These modules usually have files with the extension .so, .pyd or .dll.
If import _counter
, is present in the same location as Crypto.Util
but as an .so
file, this would explain why it won't run from Jython.
来源:https://stackoverflow.com/questions/29814603/python-import-error-cannot-import-module-named-counter-which-is-a-so-file