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

笑着哭i 提交于 2019-12-02 04:23:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!