So I’ve been working the last exercise of Learn Python the Hard Way and it states that before I run the program Ive been working on, you have to set the Pythonpath environment variable like this:
export PYTHONPATH=$PYTHONPATH:.
I’ve done this, and after it wasn’t working (Im assuming thats why when I try to run my program, I get an ImportError), I did some research on pythonpath. It’s essentially says that Pythonpath is to find where to look for modules to import. So I set Pythonpath to the actual location of the module I’m trying to import and still to no avail.
Here’s my directory:
- User/_myname_/python_stuff/projects/GothonWeb
- bin/
- __init__.py
- app.py
- gothonweb/
- __init__.py
- maps.py
- templates (web.py)
- game.html
- index.html
- layout.html
- so forth and so on.
Im trying to run the app.py, which tries to import the main.py module:
from gothonweb import maps
But I still get this error:
Traceback (most recent call last):
File "python_stuff/projects/GothonWeb/bin/app.py", line 2, in <module>
from gothonweb import maps
ImportError: No module named gothonweb
Anyone know whats up? Oh, some other details. Running on Python 2.7 on Mac Os X Lion, if that helps any.
Run the application like this:
However, if you did this:
A lot of users tend to do this mistake, and here is a nice explanation by Zed Shaw, on why not to run your app like this!
Then you are doing it wrong. In all python projects you do not cd into a lower directory to run things. You stay at the top and run everything from there so that all of the system can access all the modules and files.