0

I have a problem very similar to this one. I too am working from Programming Python 4th edition. I am using a mac powerbook. I have a directory structure similar to:

programming\ python
├── PP4E
│   ├── GUI
│   │   ├── Tour
│   │   │   ├── __init__.py
│   │   │   ├── demoAll-prg.py
│   │   │   ├── demoAll-win.py
│   │   │   ├── demoCheck.py
│   │   │   ├── demoDlg.py
│   │   │   ├── demoRadio.py
│   │   │   ├── demoScale.py
│   │   ├── __init__.py
│   ├── __init__.py
│   └── launchmodes.py
└── __init__.py

The demoAll-prg.py tries from PP4E.launchmodes import PortableLauncher, but returns ImportError: No module named 'PP4E'.

Answers on SO generally say to make sure the folders have __init__.py files present (done!), and/or to add the parent directory (here, "programming python") to PYTHONPATH. This also agrees with Learning Python, 5th ed., p. 709.

I tried a few different ways of editing my python path, such as described here, to no avail. Currently my .bash_profile has this added to the end:

PYTHONPATH=“/Users/geoffreysametz/google drive/programming python”
export PYTHONPATH

but this is not solving the issue. I have closed and reopened the terminal, and have rebooted the computer.

Any advice on how to fix this problem is greatly appreciated.

Community
  • 1
  • 1
Geoffrey Sametz
  • 618
  • 1
  • 6
  • 17

1 Answers1

0

If you specify python path using bash, any white space should be preceded by \.

PYTHONPATH=“/Users/geoffreysametz/google\ drive/programming\ python”
Hun
  • 3,707
  • 2
  • 15
  • 15
  • That does fix the $PYTHONPATH, but not the error. `echo $PYTHONPATH` returns `“/Users/geoffreysametz/google drive/programming python”`, but `python demoAll-prg.py` run in the "tour" directory returns `ImportError: No module named 'PP4E'` – Geoffrey Sametz Apr 18 '16 at 12:22
  • Before any import statement in demoAll-prg.py, try this. import sys; print(sys.path); and see if that indeed includes the path. – Hun Apr 18 '16 at 15:56
  • This reveals an odd error. The first path is `'/Users/geoffreysametz/Google Drive/Programming Python/PP4E/GUI/Tour'` (presumably on path b/c program is launched from here), and the second is `'/Users/geoffreysametz/Google Drive/Programming Python/PP4E/GUI/Tour/“/Users/geoffreysametz/Google Drive/Programming Python”'`, where the .bash_profile path (complete with double quotes) is mashed onto a copy of the previous path. – Geoffrey Sametz Apr 18 '16 at 16:24
  • In your original description all path name is in lower case. But in the print statement some are in upper case. – Hun Apr 18 '16 at 16:28
  • Sorry, I should have added that I changed the case used in the .bash_profile to match the real file names after the initial post, since case sensitivity might have been a problem. The paths above are direct cut and paste of the real, current output. – Geoffrey Sametz Apr 18 '16 at 17:19