2

I'm trying to follow Learn Python the Hard Way to teach myself python. I want to use the directory structure described in Exercise 46, which for my question I'll simplify down to this:

bin/
    app.py
data/
    __init__.py
    foobar.py

In exercise 50, he says to start the program from the project's top level directory like this:

$ python bin/app.py

Afterwards stating that you start it from the top level directory so the script can access other resources in the project.

But I can't seem to import modules that are in the data folder from app.py. Am I misunderstanding how to setup the directory structure?

Edit: Here's the bare-bones setup I have to try and figure this out

In app.py I have:

import data.foobar

I have __init__.py in the data directory and foobar.py just contains some nonsense like:

class Test:
    x = 0

The directory structure matches that of above.

fjc
  • 396
  • 1
  • 11

1 Answers1

6

I'm not sure what the exercise asks to do, but your top-level directory needs to be in the PYTHONPATH. Try:

$ export PYTHONPATH=$PYTHONPATH:$PWD
$ python bin/app.py
spinlok
  • 3,561
  • 18
  • 27
  • Thanks, this works. But I'm going to leave it unaccepted for now to see if I can find where I went wrong in the exercise. I can't for the life of me remember any mention of changing the path. – fjc Apr 01 '14 at 00:14
  • Nevermind, he does mention having to change the the path but not until a later exercise. – fjc Apr 01 '14 at 00:16