Python Forum

Full Version: Nanpy import error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've got an odd error when using nanpy. If I open a session of Python, and then load my module and run it, it works fine. If I try and load my module via the terminal (or SSH), I get an import error.

Error:
ImportError: no module named nanpy
And where it's getting stuck is the first line!

from nanpy import (ArduinoApi, SerialManager)
Any ideas why it works in one and not the other?
Then there is a difference with your environment. Are you using a virtual environment?
Have you activated it?
Maybe you are using the wrong Python version.

To check it, just make one file with following content:

import sys


print('Executable:', sys.executable)
print('Module paths:')
print('\n'.join(sys.path))
Call it one time direct, then over ssh.
Can you see a difference?

You can also import nanpy with your working environment and print(nanpy.__file__).
Then you know the exact path of the module. It should be in site-packages.
dist-packages is from the linux distribution itself.

Just try this show us the output.
Ok, so from a python session:

Executable: /usr/bin/python3
Module paths:
/home/pi
/usr/lib/python35.zip
/usr/lib/python3.5
/usr/lib/python3.5/plat-arm-linux-gnueabihf
/usr/lib/python3.5/lib-dynload
/usr/local/lib/python3.5/dist-packages
/usr/lib/python3/dist-packages

then from ssh

('Executable:', '/usr/bin/python')
Module paths:
/home/pi
/usr/lib/python2.7
/usr/lib/python2.7/plat-arm-linux-gnueabihf
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/home/pi/.local/lib/python2.7/site-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages

Ahhh. Which would be different (same if ran from terminal).

So, how do I get both to be the same?

Wait, I've figured it....

Doh.

rather than type "Python ...."
type "python3....."

And then it works!