470,631 Members | 1,704 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

Having trouble importing against PP2E files

List:

I'm trying to use the example files from Programming Python, 2nd Ed.

I've copied them into c:\Python24\Examples\PP2E.

Launching any of the examples programs by themselves seems to work
spiffily.

Using regedit, I appended "c:\Python24\Examples\PP2E" to Pythonpath

from the immediate window, executing the line:

from PP2E.launchmodes import PortableLauncher

Raises the exception:

Import Error: no module named PP2E.launchmodes

However if I copy launchmodes.py into my work directory, it imports
successfully.

Both "Examples" above and "Examples\PP2E" contain the __init__.py file.

Obviously, I'm missing a setup step here.

What magic do I need to perform to get Python to find modules in the
Examples heirarchy?

Is there any way to check from the immediate window where Python will
search for modules? Pythonpath appears to be correct, but the file
isn't importing unless I copy it to the current directory.

Thanx
Charles

Jul 21 '05 #1
3 1683
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Charles Krug wrote:
List:

I'm trying to use the example files from Programming Python, 2nd Ed.

I've copied them into c:\Python24\Examples\PP2E.

Launching any of the examples programs by themselves seems to work
spiffily.

Using regedit, I appended "c:\Python24\Examples\PP2E" to Pythonpath

from the immediate window, executing the line:

from PP2E.launchmodes import PortableLauncher

Raises the exception:

Import Error: no module named PP2E.launchmodes

However if I copy launchmodes.py into my work directory, it imports
successfully.

Both "Examples" above and "Examples\PP2E" contain the __init__.py file. Are both Examples and PP2E packages? In python if a folder is meant to
represent a package it should iclude the above mentioned file
__init__.py and by saying the above your suggesting that PP2E is a
package inside the package Examples.
Obviously, I'm missing a setup step here.

What magic do I need to perform to get Python to find modules in the
Examples heirarchy?

Is there any way to check from the immediate window where Python will
search for modules? Pythonpath appears to be correct, but the file
isn't importing unless I copy it to the current directory.

Thanx
Charles

If the above is correct, you should append the pythonpath with
c:\Python24\ and refer to the wanted .py with Examples.PP2E.launchmodes.
As such the import statement obviously should be "from
Examples.PP2E.launchmodes import PortableLauncher". If the above isn't
the case and there is still something unclear about this, reply with a
more detailed post about the situation.

Elmo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCztd7ctNFyQJObrsRAuXNAJwLF94iM0IwkJVHLUOo1E EBYQg6FACfQFfE
jcxspYU80N5MSZB9uqhbBh4=
=YquD
-----END PGP SIGNATURE-----
Jul 21 '05 #2
On Fri, 08 Jul 2005 22:43:55 +0300, Elmo Mšntynen <el****@jippii.fi>
wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Import Error: no module named PP2E.launchmodes

However if I copy launchmodes.py into my work directory, it imports
successfully.

Both "Examples" above and "Examples\PP2E" contain the __init__.py file. Are both Examples and PP2E packages?


They appear to be, yes.
In python if a folder is meant to represent a package it should iclude
the above mentioned file __init__.py and by saying the above your
suggesting that PP2E is a package inside the package Examples.
That appears to be the case, yes.
If the above is correct, you should append the pythonpath with
c:\Python24\ and refer to the wanted .py with Examples.PP2E.launchmodes.
As such the import statement obviously should be "from
Examples.PP2E.launchmodes import PortableLauncher". If the above isn't
the case and there is still something unclear about this, reply with a
more detailed post about the situation.


The registry value is this:

C:\Python24\Lib;C:\Python24\DLLs;C:\Python24\Lib\l ib-tk;
C:\Python24\Examples\PP2E

I'm not realy sure what other details are relavant. I've installed from
the Windows .msi package, and appended the directory I want to
PythonPath in the registry, and that doesn't do what I need.

This is WinXP Pro

Jul 21 '05 #3
On Sat, 09 Jul 2005 17:24:16 GMT, Charles Krug <cd****@worldnet.att.net>
declaimed the following in comp.lang.python:

C:\Python24\Lib;C:\Python24\DLLs;C:\Python24\Lib\l ib-tk;
C:\Python24\Examples\PP2E
Possibly you've gone one layer too deep. If there is an
__init__.py IN c:\python24\examples, I suspect you need the path to just
point to that -- c:\python24\examples

Then, specify the subpackage using

import Examples.PP2E

which should, with luck, find that Examples is a package (seeing ITS
__init__.py) and /then/ go for the package component PP2E

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rick Olson | last post: by
6 posts views Thread by Jeremy Cowles | last post: by
29 posts views Thread by Natan | last post: by
4 posts views Thread by kurt.kurtsmith | last post: by
reply views Thread by Basha J P M | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.