且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ubuntu Python“没有名为paramiko的模块”

更新时间:2023-09-20 18:51:52

简短版:你正在混合Ubuntu的Python打包版本( / usr / bin / python )以及本地构建和安装的版本( / usr / local / bin / python )。

Short version: You're mixing Ubuntu's packaged version of Python (/usr/bin/python) and a locally built and installed version (/usr/local/bin/python).

长版:


  • 您使用 apt-get install python -paramiko 将Ubuntu的官方Paramiko软件包安装到 /usr/lib/python2.7/dist-p ackages

  • 您使用(我假设)Ubuntu的 pip 版本,安装到 /usr/local/lib/python2.7/dist-packages 。 (请参阅此处。)

  • 您使用的是本地构建的Python版本,并且因为它是本地构建的,它使用 /usr/local/lib/python2.7 而不是 /usr/lib/python2.7 ,并且因为它没有Debian / Ubuntu自定义,所以它不会检查使用 dist-packages

  • You used apt-get install python-paramiko to install Ubuntu's official Paramiko package to /usr/lib/python2.7/dist-packages.
  • You used (I assume) Ubuntu's version of pip, which installs to /usr/local/lib/python2.7/dist-packages. (See here.)
  • You used a locally built version of Python, and because it's locally built, it uses /usr/local/lib/python2.7 instead of /usr/lib/python2.7, and because it doesn't have Debian/Ubuntu customizations, it doesn't check use dist-packages.

解决方案:您应该能够将 /usr/local/lib/python2.7/dist-packages 添加到您的 / usr / local / bin / python sys.path ,但是因为你使用的是Ubuntu,所以最容易让Ubuntu为你做的工作:

Solution: You should be able to add /usr/local/lib/python2.7/dist-packages to your /usr/local/bin/python's sys.path, but since you're using Ubuntu, it's easiest to let Ubuntu do the work for you:


  • 使用/ usr / bin / python而不是本地版本。

  • 尽可能使用Ubuntu的软件包(即使用 apt-get 而不是 pip )。

  • 其余使用virtualenv(以便在Ubuntu打包和个人安装的模块之间保持清晰的分离)。

  • Use /usr/bin/python instead of a local version.
  • Use Ubuntu's packages wherever possible (i.e., use apt-get instead of pip).
  • Use virtualenv for the rest (to keep a clean separation between Ubuntu-packaged and personally installed modules).

我会这么做的r卸载本地版本的Python并删除 /usr/local/lib/python2.7 ,以确保不会发生进一步的不匹配。如果您不想那么激烈,那么您可以在 / usr / local / bin之前编辑$ PATH以放入 / usr / bin 默认情况下运行Python的系统版本。

I'd go so far as to uninstall the local version of Python and delete /usr/local/lib/python2.7, to ensure that no further mismatches occur. If you don't want to be that drastic, then you can edit your $PATH to put /usr/bin before /usr/local/bin to run the system version of Python by default.