ImportError: No module named transport (Paramiko, Python 3.2.5)

為{幸葍}努か 提交于 2019-12-10 20:36:07

问题


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:


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.



来源:https://stackoverflow.com/questions/18179156/importerror-no-module-named-transport-paramiko-python-3-2-5

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