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
  Which app do I import to fix this error? ErnestTBass 6 347 Apr-26-2020, 08:43 PM
Last Post: snippsat
  Error while humansize module import. johnkgson 3 469 Apr-26-2020, 08:37 AM
Last Post: johnkgson
  Importing module from a package results in import error goghvv 2 285 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Python 2.7 Import error. Directory and filename conflict petcoo00 2 272 Feb-02-2020, 08:46 PM
Last Post: snippsat
  Error in python code 'import callbot' Lou_Reed 3 369 Jan-07-2020, 09:33 PM
Last Post: Clunk_Head
  import error (unknown location) pseudo 1 2,282 Nov-14-2019, 11:47 PM
Last Post: pseudo
  import module error german77 4 1,527 Feb-28-2019, 02:29 PM
Last Post: german77
  Running pytest gives " 'cannot import name 'session' " error jasonblais 2 1,158 Oct-10-2018, 05:02 PM
Last Post: jasonblais
  Import Error Bravoseeker 3 2,640 Oct-05-2018, 03:00 PM
Last Post: Larz60+
  module import error bobsmith76 4 1,125 Sep-18-2018, 03:41 AM
Last Post: bobsmith76

Forum Jump:


Users browsing this thread: 1 Guest(s)