I'm new to this RPI world and also to python although I completed the basic courses I'm still getting used to this so I will appreciate your patience I'll try to express my self the best way.

I downloaded a few packages to work with a 16x02 LCD (QAPASS 1602a) using "Terminal" and there were no problems on the installation process but when I tried to import them on a python script using Thonny IDE i keep getting this error message :

Python 3.5.3 (/usr/bin/python3)
>>> import RPLCD
Traceback (most recent call last):
  File "<pyshell>", line 1, in <module>
ImportError: No module named 'RPLCD'

To install this I used:

sudo pip install RPLCD

I figured out what the problem is ** but I don't know how to fix it or what causes it because I don't have enough knowledge for the moment to do this, But I will be really thankful if you guys can give any advice on were took look at this kind of stuff like posts or courses.

Problem: I don't know how but the package installed can't be "read" by python 3 as you can see above but if I go on into "terminal" and do the following:

pi@raspberrypi:~ $ python2
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPLCD

everything looks correct and no errors are shown.

It looks like python 3.5.3 interpreter is not able to use this packages and python 2.7.13 is.

I've also installed the adafriut library doing the following and I had the same results.

git clone https://github.com/adafruit/Adafruit_Python_CharLCD.git
cd ./Adafruit_Python_CharLCD
sudo python setup.py install
  • 1
    Python 2 and Python 3 are different programming languages. What works for one may not work for the other. You need to download modules for the language you want to use. – joan Jul 27 at 19:49
  • So you don't need to tell which with interpreter you what use the module. The thing is that maybe that module is not for python 3 right ??? – Carlos Echeverria St Jul 27 at 20:57
  • Every Python module has to be compiled against the specific Python version you want to use. A version compiled against 2.1.2 will not work with 2.1.3 or 2.1.1 or 3.1 etc. You need to download a version for the Python version you are using. – joan Jul 27 at 21:07
  • with the answer below now i know what i did wrong thank you! – Carlos Echeverria St Jul 27 at 21:10
  • I think it is more a fault with Python, not the user. – joan Jul 27 at 21:17

Python installations generally do not share modules between them. Modules installed for Python 2 will not be shared with the Python 3 installation (they are stored in different locations, etc).

At least for now, python and pip refer to the Python 2 versions of the toolchain. As such, most Python tools have a Python 3 equivalent. If you used

sudo pip install RPLCD

to install RPLCD, a Raspberry Pi LCD library, you would have installed the Python 2 version of the library. You need to explicitly use pip3, Python 3's version of Pip, to install the Python 3 version; like so:

sudo pip3 install RPLCD

See also the documentation from the Python Software Foundation for working with multiple Python versions if you're interested in more information.

  • Thanks a lot, you really helped me out with the answers I was looking for !!! I will look at the documentation right now :) – Carlos Echeverria St Jul 27 at 21:09

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.