0

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)

3
  • Do you have a init.py file in the directories? Commented Oct 20, 2017 at 8:34
  • I don't. Just the contents of the repo. Commented Oct 20, 2017 at 8:35
  • The program seems to import the module, since I am getting a different user with respect to authentication. The module even contacted the PSN and got a 403 response. Commented Oct 20, 2017 at 8:39

2 Answers 2

1

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

It worked after running pip3 install simplejson, pip3 install requests and then the command with python3 as python3 example.py.
1

Being in the repository root directory, you do:

touch src/__init__.py

This will create an empty file but it is necessary for the Python module search system. Then you should be able to run it without problems, unless there is some dependency on external libraries.

2 Comments

this did create the py file but I get the same error
Sorry, I made a mistake in my original response. You must run this in the root directory: touch src/__init__.py It's importante to note that it WILL NOT be a whitespace between the dot and the py extension. Just edited in my original reply. Can you try again?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.