1

I have a working Python 3.6 and the package imutils is recognized, importable in its shell. Today I installed some packages on my Python 2 for another task, and now my IPython does not recognize imutils anymore:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-b01afa4ab41d> in <module>()
      4 import random
      5 import math
----> 6 import imutils
      7 import re
      8 import time

ImportError: No module named imutils

What's going on? How fragile are these things, seriously.

I run sys.executable on both environments and the result is the same:

/usr/bin/python3

I checked my Python2 and the package is not installed there:

sudo -H pip2.7 uninstall imutils
Skipping imutils as it is not installed.

Doing this:

 /usr/bin/python3 -V

Returns this:

Python 3.6.7

Restarting does not work. I did use sudo commands, installed, uninstalled several times - no luck. Something has screwed up my Python, I think.

P.S: I do use Python3 on my IPython as interpreter.

P.S: I don't use Python 3.4 as a kernel whatsoever, they are all 3.6.

EDIT: Okay it is clear that ROS installation screwed up my Python path since I see this:

os.getenv("PYTHONPATH")
'/home/user/ros_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages'

HOW CAN I SET IT BACK TO WHERE IT WAS BY DEFAULT?

Schütze
  • 1,044
  • 5
  • 28
  • 48
  • This thread has nothing to do with that one you linked @coldspeed. Read the text before taking such actions. – Schütze Dec 10 '18 at 17:28
  • I read it all right. You installed this package on python3.6, but linked python3.4 as a backend to your ipython. I suggest _you_ read the post before accusing others of not reading – cs95 Dec 10 '18 at 17:29
  • What Python 3.4? I don't have that even. Plus, I don't use Conda or virtualenv. The link you gave has zero useful information whatsoever. – Schütze Dec 10 '18 at 17:33
  • what does `/usr/bin/python3 -V` print for you on the terminal? – cs95 Dec 10 '18 at 17:42
  • 1
    Also `print(sys.path)` in both the Python 3 environment where `imutils` is importable and the Python 3 environment where `imutils` is not importable (and if you see a discrepancy, don't try to fix things by messing with `sys.path` or `PYTHONPATH` - that's likely to break things harder). – user2357112 Dec 10 '18 at 17:47
  • @user2357112 Hey, that returns Python 2.7 on Ipython due to some ROS installation. Although I DO set my kernel above to 3, it keeps returning 2.7 for some reason. My Pythonpath has to be changed I think, since ROS screwed it up. – Schütze Dec 10 '18 at 17:52
  • [install-imutils-within-ros](https://stackoverflow.com/questions/53280841/install-imutils-within-ros/53289275#53289275) – Benyamin Jafari Dec 12 '18 at 20:18

1 Answers1

0

It was due to the fact that ROS sourced its own Python version (2.7) by changing the PYTHONPATH.

Once I removed it from my .bashrc, it started to work again.

Schütze
  • 1,044
  • 5
  • 28
  • 48