5

So I'm trying to use Paramiko on Ubuntu with Python 2.7, but import paramiko causes this error:

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.

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.

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.

two paramiko folders are located in usr/local/lib/python2.7/dist-packages.

Delliardo
  • 175
  • 2
  • 3
  • 15
  • Did you try to install it inside a virtualenv? –  Mar 11 '15 at 15:59
  • @DivakarDass, no, I was hoping to avoid virtualenv since I won't be using Ubuntu for too long, just trying to keep it short and simple. – Delliardo Mar 11 '15 at 16:03
  • 1
    Looks like you have a locally-built installation of Python, which is being executed rather than the system-provided one. Try running `/usr/bin/python` instead. – Colonel Thirty Two Mar 11 '15 at 16:06
  • @ColonelThirtyTwo, well, that fixes that, that's interesting. Thanks! Is there a way to get the terminal to run the appropriate python? – Delliardo Mar 11 '15 at 16:12

7 Answers7

12

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).

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 use dist-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:

  • 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).

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.

Community
  • 1
  • 1
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
  • _"Use virtualenv for the rest (to keep a clean separation between Ubuntu-packaged and personally installed modules)."_ Doesn't Ubuntu PIP install to `/usr/local/`? – Colonel Thirty Two Mar 11 '15 at 16:30
  • @ColonelThirtyTwo - Yes, it does. I'm just really paranoid about separating personal modules from systemwide (`/usr` and `/usr/local`) modules, but thanks for the correction. – Josh Kelley Mar 11 '15 at 16:32
4

Try downloading the zip file from https://github.com/paramiko/paramiko and running this command in the unzipped directory :

python setup.py install
1

There are two others methodes for add modules in python :

The first :

  1. Download the package.
  2. Create directory and paste the package in it.
  3. Tap in the terminal :
  4. export PYTHONPATH=$PYTHONPATH:path_of_package

The second :

  1. open python interpreter:
  2. import sys
  3. sys.path.insert(0, "path_of_package")
khelili miliana
  • 3,730
  • 2
  • 15
  • 28
0

Try installing only through commands.

  1. Download paramiko package from git using this command: git clone https://github.com/paramiko/paramiko.git
  2. Go to unzipped directory and run export PYTHONPATH=$PYTHONPATH:<path_to_paramiko>
  3. 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

Enjoy :)

0

Also, mind the version of python, if the error was reported by python3, then install python3's paramiko.

ddwolf
  • 91
  • 2
  • 10
0

If you're using Python 3, type the below command

$ sudo -H pip3 install paramiko --ignore-installed
Aditya Malviya
  • 1,907
  • 1
  • 20
  • 25
-1

try type pi then tap, this give you this

:$ pi

pic piconv pidstat pinentry-curses ping6

       pip3             pivot_root       

pic2graph pidof pinentry ping pinky

        pip3.6      

then you type in whereis pip3

$ whereis pip3

pip3: /usr/local/bin/pip3.6 /usr/local/bin/pip3

xg@xx-ppmaster:/xg/scripts/pyth

$ sudo /usr/local/bin/pip3 install paramiko

This should let you install paramiko

more on python installation

https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/