ImportError even module is in the same folder

  • Hi,
    I am new with Pycom and Python in general. I am working on a new project and since then, keep struggling with the same issue. I cannot import modules I need. For example, if I need the onewire module and its OneWire class, I get this error "ImportError: no module named 'onewire'", even if I put it in the same project folder where my main code is. For now, I put the whole definition of the class and its methods in my main to avoid the importation but this makes a really long code then. I already read many topics about that, especially about adding manually the modules with sys.path.insert/append and modifying the Python Path but it still does not work. I am using Atom as IDE and I download Pymakr to have an REPL.
    I can provide you with further information if needed.
    Thanks for your help

  • @robert-hh that's true, you can have the libraries anywhere (with Pymakr as well)

  • @dan Not to my experience. Libraries and module can be in any folder specified in sys.path. And the default includes the local directory at first place. I almost never use the lib folder.
    But pymakr may play it's own game.

  • @brossingo you need to put the libraries in the lib/ folder. To use the OneWire lib, here's how you can import it: from onewire import OneWire. You can find a basic example here.

Pycom on Twitter