Ubuntu Python“没有名为paramiko的模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28991319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ubuntu Python "No module named paramiko"
提问by Delliardo
So I'm trying to use Paramiko on Ubuntu with Python 2.7, but import paramiko causes this error:
所以我试图在带有 Python 2.7 的 Ubuntu 上使用 Paramiko,但 import paramiko 导致此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named paramiko
The other questions on this site don't help me since I'm new to Ubuntu.
由于我是 Ubuntu 新手,因此该站点上的其他问题对我没有帮助。
Here are some important commands that I ran to check stuff:
以下是我用来检查内容的一些重要命令:
sudo pip install paramiko
pip install paramiko
sudo apt-get install python-paramiko
Paramiko did "install". These are the only commands I used to "install" paramiko. I'm new to Ubuntu, so if I need to run more commands, lay them on me.
Paramiko 确实“安装”了。这些是我用来“安装”paramiko 的唯一命令。我是 Ubuntu 的新手,所以如果我需要运行更多命令,请将它们放在我身上。
which python
/usr/local/bin/python
python -c "from pprint import pprint; import sys; pprint(sys.path);"
['',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
In the python interpreter, I ran help("modules")
and Paramiko is not in the list.
在 python 解释器中,我跑了help("modules")
,Paramiko 不在列表中。
two paramiko folders are located in usr/local/lib/python2.7/dist-packages
.
两个 paramiko 文件夹位于usr/local/lib/python2.7/dist-packages
.
采纳答案by Josh Kelley
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
).
简短版本:您正在混合 Ubuntu 的 Python 打包版本 ( /usr/bin/python
) 和本地构建和安装的版本 ( /usr/local/bin/python
)。
Long version:
长版:
- 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 usedist-packages
.
- 您曾经
apt-get install python-paramiko
将 Ubuntu 的官方 Paramiko 软件包安装到/usr/lib/python2.7/dist-packages
. - 您使用(我假设)Ubuntu 的 版本
pip
,它安装到/usr/local/lib/python2.7/dist-packages
. (见这里。) - 您使用了本地构建的 Python 版本,并且因为它是本地构建的,所以它使用
/usr/local/lib/python2.7
代替/usr/lib/python2.7
,并且因为它没有 Debian/Ubuntu 自定义,所以它不会检查 usedist-packages
。
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/local/lib/python2.7/dist-packages
到您的/usr/local/bin/python
's 中sys.path
,但是由于您使用的是 Ubuntu,因此最容易让 Ubuntu 为您完成工作:
- Use /usr/bin/python instead of a local version.
- Use Ubuntu's packages wherever possible (i.e., use
apt-get
instead ofpip
). - Use virtualenv for the rest (to keep a clean separation between Ubuntu-packaged and personally installed modules).
- 使用 /usr/bin/python 而不是本地版本。
- 尽可能使用 Ubuntu 的软件包(即使用
apt-get
代替pip
)。 - 其余部分使用 virtualenv(以保持 Ubuntu 打包的模块和个人安装的模块之间的清晰分离)。
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.
我什至会卸载 Python 的本地版本并删除/usr/local/lib/python2.7
,以确保不会发生进一步的不匹配。如果您不想那么激烈,那么您可以编辑您的 $PATH 以放置/usr/bin
在/usr/local/bin
默认情况下运行系统版本的 Python之前。
回答by Josh Kelley
Try downloading the zip file from https://github.com/paramiko/paramikoand running this command in the unzipped directory :
尝试从https://github.com/paramiko/paramiko下载 zip 文件并在解压后的目录中运行此命令:
python setup.py install
回答by khelili miliana
There are two others methodes for add modules in python :
在 python 中添加模块还有另外两种方法:
The first :
首先 :
- Download the package.
- Create directory and paste the package in it.
- Tap in the terminal :
- export PYTHONPATH=$PYTHONPATH:path_of_package
- 下载软件包。
- 创建目录并将包粘贴到其中。
- 点击终端:
- 导出 PYTHONPATH=$PYTHONPATH:path_of_package
The second :
第二 :
- open python interpreter:
import sys
sys.path.insert(0, "path_of_package")
- 打开python解释器:
import sys
sys.path.insert(0, "path_of_package")
回答by user8090410
try type pi then tap, this give you this
尝试输入 pi 然后点击,这会给你这个
:$ pi
:$ pi
pic piconv pidstat pinentry-curses ping6
pic picov pidstat pinentry-curses ping6
pip3 pivot_root
pic2graph pidof pinentry ping pinky
pic2graph pidof pinentry ping 小指
pip3.6
then you type in whereis pip3
然后你输入 whereis pip3
$ whereis pip3
$ 哪里是 pip3
pip3: /usr/local/bin/pip3.6 /usr/local/bin/pip3
pip3:/usr/local/bin/pip3.6 /usr/local/bin/pip3
xg@xx-ppmaster:/xg/scripts/pyth
xg@xx-ppmaster:/xg/scripts/pyth
$ sudo /usr/local/bin/pip3 install paramiko
$ sudo /usr/local/bin/pip3 安装 paramiko
This should let you install paramiko
这应该让你安装 paramiko
more on python installation
更多关于python安装
https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/
https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/
回答by user8090410
Try installing only through commands.
尝试仅通过命令安装。
- Download paramiko package from git using this command:
git clone https://github.com/paramiko/paramiko.git
- Go to unzipped directory and run
export PYTHONPATH=$PYTHONPATH:<path_to_paramiko>
- If you find libffi package not found then run this command:
sudo apt-get install libffi6 libffi-dev
and If you haven't properly installed the header files and static libraries for python dev then run this command:sudo apt-get install python-dev
- 使用以下命令从 git 下载 paramiko 包:
git clone https://github.com/paramiko/paramiko.git
- 转到解压目录并运行
export PYTHONPATH=$PYTHONPATH:<path_to_paramiko>
- 如果您发现未找到 libffi 包,请运行以下命令:
sudo apt-get install libffi6 libffi-dev
如果您尚未正确安装 python dev 的头文件和静态库,请运行以下命令:sudo apt-get install python-dev
Enjoy :)
享受 :)
回答by ddwolf
Also, mind the version of python, if the error was reported by python3, then install python3's paramiko.
另外要注意python的版本,如果是python3报错,那就安装python3的paramiko。
回答by Aditya
If you're using Python 3, type the below command
如果您使用的是 Python 3,请输入以下命令
$ sudo -H pip3 install paramiko --ignore-installed