Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Nanpy import error
#1
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?
Quote
#2
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.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Quote
#3
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!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  import module error german77 4 541 Feb-28-2019, 02:29 PM
Last Post: german77
  Running pytest gives " 'cannot import name 'session' " error jasonblais 2 681 Oct-10-2018, 05:02 PM
Last Post: jasonblais
  Import Error Bravoseeker 3 1,539 Oct-05-2018, 03:00 PM
Last Post: Larz60+
  module import error bobsmith76 4 810 Sep-18-2018, 03:41 AM
Last Post: bobsmith76
  Invalid Syntax Error on Import arjunsingh2908 3 4,758 Jul-07-2018, 05:02 PM
Last Post: ichabod801
  Import error when trying to import DDE (part of PyWin32) fbicalho 0 1,085 Apr-21-2018, 07:26 PM
Last Post: fbicalho
  python import sybpydb error: DLL load failed: The specified module could not be found andieDu 3 2,406 Apr-04-2018, 06:58 AM
Last Post: Larz60+
  CSV unable to import (traceback error) learnermarx 3 2,076 Feb-09-2018, 03:24 PM
Last Post: buran
  error in import numba Sara 1 2,793 Oct-22-2017, 08:07 PM
Last Post: metulburr
  Module import error CoolSchoolBoy 2 1,679 Sep-14-2017, 06:21 AM
Last Post: Sagar

Forum Jump:


Users browsing this thread: 1 Guest(s)