Search code examples
pythonimportpython-module

Importing a python module to enable a script to be run from command line


I'm new to python and trying to test a script from this github repo (https://github.com/mgp25/psn-api).

The root directory has an example.py and I'm trying to run it with

$ python example.py

which gives this error:

Traceback (most recent call last):
  File "example.py", line 1, in <module>
    from src.Auth import Auth
ImportError: No module named src.Auth

How can I get this to run?

There is a folder in the root directory named src but because I'm new to python I don't know how to connect things so that the src.Auth module gets imported (or if that's even the right terminology)


Solution

  • Python 3.3+ will happily interpret it as a package without an __init__.py, fwiw, and I believe that's what the author wrote in.

    Also note from trying to run it just now, you'll need to install simplejson and requests. (Normally there'd be a requirements.txt or similar saying this.)