User avatar
RDK
Posts: 254
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Python vs Python 3 - can't find module??

Mon Apr 08, 2019 3:24 pm

I have a problem with Python 3 not finding a module library, but Python 2.7 does. Here is a VERY simple program:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyModbusTCP.client import ModbusClient

print("hello world")
Below you can see back to back runs of this program only switching from python to Python3.
me@V2B_Stretch_Test:~ $ python /mnt/usbdrive/pgms/modbus/PrintHi.py
hello world
me@V2B_Stretch_Test:~ $ python3 /mnt/usbdrive/pgms/modbus/PrintHi.py
Traceback (most recent call last):
File "/mnt/usbdrive/pgms/modbus/PrintHi.py", line 4, in <module>
from pyModbusTCP.client import ModbusClient
ImportError: No module named 'pyModbusTCP'

I suspect I have a location or permissions issue, but my expertise stops before this. Can someone help?....RDK

pcmanbob
Posts: 6627
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Python vs Python 3 - can't find module??

Mon Apr 08, 2019 3:36 pm

Did you install it just for python ( ie python 2 )

Code: Select all

sudo pip install pyModbusTCP

If so you probably need to run the install again this time for python 3

Code: Select all

sudo pip3 install pyModbusTCP
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
B.Goode
Posts: 8234
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Python vs Python 3 - can't find module??

Mon Apr 08, 2019 3:37 pm

Human beings can see that python(2) and Python3 are pretty much the same thing.

But from the viewpoint of the Raspbian Operating System they are two completely different languages, mythically named Adder and Anaconda.

A library installed for 'Adder' will not be recognised or imported by 'Anaconda', or vice-versa.

It is the same for Python2 and Python3...

User avatar
RDK
Posts: 254
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Python vs Python 3 - can't find module??

Mon Apr 08, 2019 4:26 pm

OK, well, I in fact installed it from the GIT

Code: Select all

sudo git clone https://github.com/sourceperl/pyModbusTCP.git
Now should I reinstall as you propose? How do I remove the clone installed library?

Thinking about it I have many libraries which I installed via the clone process, for example RTL_433. Is there a general fix so that both can access the library?.....RDK

User avatar
B.Goode
Posts: 8234
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Python vs Python 3 - can't find module??

Mon Apr 08, 2019 5:43 pm

RDK wrote:
Mon Apr 08, 2019 4:26 pm
OK, well, I in fact installed it from the GIT

Code: Select all

sudo git clone https://github.com/sourceperl/pyModbusTCP.git
Now should I reinstall as you propose? How do I remove the clone installed library?

Thinking about it I have many libraries which I installed via the clone process, for example RTL_433. Is there a general fix so that both can access the library?.....RDK

So, reading the documentation for that Repository...

You have chosen not to use the easy way...

Instead you have probably done:

Code: Select all

git clone https://github.com/sourceperl/pyModbusTCP.git
cd pyModbusTCP
sudo python setup.py install

So 'the simplest thing that might work' is, still in that same directory:

Code: Select all

sudo python3 setup.py install
Since the developer/maintainer says "The module is currently test on Python 2.6, 2.7, 3.2, 3.3, 3.4 and 3.5.", if that doesn't work maybe ask for advice via the Issues page for the Repository.

Return to “Beginners”