0

I'm trying to use CircuitPython lib but got some troubles, I put the files from the Circuitpython bundle in /lib

  • this works

    $ ipython3
    Python 3.7.3, blabla info
    >> import sys
    >> sys.path.append("/lib/adafruit_hid")
    >> import adafruit_hid
    
  • this works too

    $ python3
    Python 3.7.3, same blabla info
    >> import sys
    >> sys.path.append("/lib/adafruit_hid")
    >> import adafruit_hid
    
  • this doesn't

    $ sudo python3
    Python 3.7.3, same blabla info
    >> import sys
    >> sys.path.append("/lib/adafruit_hid")
    >> import adafruit_hid
    ModuleNotFoundError: No module named 'adafruit_hid'
    

And as the script needs to run as root I'm stuck

azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

1

I believe this question is related to the one found here:

https://superuser.com/questions/600349/why-sudo-python-and-python-in-terminal-start-two-different-versions-python/600350

In essence, it's running different versions of python under sudo. This may mean it cannot run the library correctly.

Edit:
This may also be related to Cannot run Python script using sudo. (Try running with the -E flag.)

By default sudo runs commands in different environment. You can ask sudo to preserve environment with -E switch.

sudo -E python myScriptName.py

It comes with it's own security risks. So be careful

orca
  • 76
  • 9
  • I explictly use `python3` to avoid this kind of problem, I guess, and I want to solve it also :D – azro Mar 08 '20 at 10:18
  • @azro, I see that your version may differ in issue from these posts. I will look into this. – orca Mar 08 '20 at 10:21