Python import Error : cannot import module named _counter (which is a .so file)

时间:2015-04-23 05:39:35

标签: python-2.7 jython-2.7

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 个答案:

答案 0 :(得分:0)

this Python documentation中说:

  

Jython是Java平台的Python语言的实现。 Jython 2.7实现的语言与CPython 2.7 ....

     

... Jython程序当前无法使用用C编写的CPython扩展模块。这些模块通常具有扩展名为.so,.pyd或.dll的文件。

如果import _counterCrypto.Util位于同一位置,但是作为.so文件,这将解释为什么它不能从Jython运行。