ImportError: No module named transport (Paramiko,

2019-07-04 22:09发布

I installed PyCrypto and Paramiko (in their respective directories) with

python3 setup.py install

and both were installed successfully. However, when I try

import paramiko 

in the 3.2.5 interpreter, I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/paramiko/__init__.py", line 64, in <module>
     from transport import SecurityOptions, Transport
ImportError: No module named transport

I have no idea why it's doing this, as I checked in the folder and the transport.py module is there. Why is there then an ImportError?

1条回答
聊天终结者
2楼-- · 2019-07-04 22:35

It appears Paramiko is trying a relative import, which is not recognised in this form in Python 3 anymore. See the changes in Python 3. The import statements in Paramiko should be one of

from .transport import SecurityOptions, Transport

(note the leading dot), or

from paramiko.transport import SecurityOptions, Transport

You can either fix the paramiko source code, or as a workaround, you could add /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/paramiko to your PYTHONPATH. Neither are preferred.

Did you run the 2to3 tool before you ran python3 setup.py install? I'm not sure if that would fix this though, since the tool probably can't distinguish between a relative or absolute import in the way it is used here.

Do check on the Paramiko forums (if there are) and file a bug against Paramiko for Python 3 compatibility.

Edit

It appears you already did file a bug report.

查看更多
登录 后发表回答