3

I'm trying to test out an example from a book and I'm getting an ImportError.

The example starts out like:

from tkinter import *
from PP4E.Gui.Tools.widgets import frame, button, entry

And if I put an import sys; print(sys.path) at the beginning of the code, the output is

['/Users/aaa/Documents/workspace/programming-python/PP4E/Lang/Calculator', 
 '/usr/local/lib/python3.4/site-packages/setuptools-12.2-py3.4.egg',
 '/usr/local/lib/python3.4/site-packages/pip-6.0.8-py3.4.egg',
 '/User/aaa/Documents/workspace/programming-python',... ]

This is what a truncated version of my programming-python directory looks like:

❯ tree
.
├── PP4E
│   ├── __init__.py
│   ├── Gui
│   │   ├── Tools
│   │   │   ├── __init__.py
│   │   │   └── widgets.py
│   │   └── __init__.py
│   ├── Lang
│   │   └── Calculator
│   │       ├── __init__.py
│   │       └── calc0.py
└── site-packages
    └── PP4E.pth

The error message I'm getting is:

❯ python3 calc0.py                                                            

Traceback (most recent call last):
  File "calc0.py", line 2, in <module>
    from PP4E.Gui.Tools.widgets import frame, button, entry
ImportError: No module named 'PP4E'

Does anybody know what I have to do to get Python to find the PP4E module? Thanks.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
jay
  • 1,524
  • 4
  • 25
  • 45
  • 2
    Try looking at [this](http://stackoverflow.com/questions/4383571/importing-files-from-different-folder-in-python) answer. – Tom May 10 '15 at 20:43
  • Thanks, but unfortunately, my PYTHONPATH environment variable is already set (which is where the fourth string in that `sys.path` array comes from). Also, all of my directories have an `__init__.py` file in them, which I thought would fix the problem. Any other ideas? – jay May 11 '15 at 23:28
  • can't you just add the directory to the path variable? Have a look at [this](https://support.enthought.com/hc/en-us/articles/204469160-How-do-I-set-PYTHONPATH-and-other-environment-variables-for-Canopy-) – Tom May 12 '15 at 08:17

1 Answers1

5

I had my PYTHONPATH wrong -- the root directory is /Users, not /User. Thanks.

jay
  • 1,524
  • 4
  • 25
  • 45