You Are Here:

Community: Developer Discussion Boards

#1 Old Setting module paths for libraries and executing via PED vs. executing via Python she - 2008-02-08, 09:28

Join Date: Feb 2008
Posts: 3
vluukkal
Offline
Registered User
Hello,

I'd like to toy around with google's gdata API on my E90
(3rd edition v 07.40.1.2 dated 3-10-2007).

I have downloaded the gdata Python API (1.0.10.1) and the required
Elementtree library. I have installed my Python interpreter at
E:\\Python and in this directory I have the 'elementtree'
directory and I have put the 'gdata' directory here as well.

I have my code in E:\\Python\Test.py and there I modify the sys.path
list to contain the aforementioned directories for gdata and
elementtree so I can import them. Then I get the accesspoint so that
I can connect to the web.
When I run my Test.py via the PED editor the imports work fine,
I am asked for my access point, but after selecting one I get
KErrPermissionDenied [Errno -46]. I suppose this happens because
PED isn't signed for sufficient capabilities for IP access.
When I try to run the same script via the standalone Python interpreter,
elementtree is imported fine, but gdata is not; I get

ImportError: No module named gdata.docs.service

Why this difference? Why is ElementTree nevertheless imported properly?

The 'gdata' directory has several further subdirectories, 'docs'
being one of them, both of them have a file called __init.py__
and there is a file gdata\docs\service.py. I'm not really fluent
in Python so I probably don't quite get the module import
system. Does the subdirectory structure need to be reflected in the
additions to sys.path somehow?

I understand that one way of installing Python libraries is to
make a .sis out of them, but I don't know how to proceed with
something like the gdata library and furthermore I suppose I'd
need to install the SDK. This all sounds like a lot of work.

Am I on the right track with the sys.path modification approach?
I seem to be fairly close of getting this working -- I hope I'm
missing something obvious.
Is there some other, preferred way of dealing with self-installed libraries?
Could PED be tweaked somehow that the interpreter could run
with enough rights to use the network?

I'm using PED 2.17 final (prints out 'Python 1.4.1 final').
Standalone Python interpreter is 1.4.1.

BR, Vesa

Here's the relevant code:

import sys
# Make the interpreter look for the modules in the right place
sys.path.append('E:\\Python\elementtree')
sys.path.append('E:\\Python\gdata')
sys.path.append('E:\\Python\gdata\service')

from elementtree import ElementTree # This works ...
import gdata.docs.service # ... but this does not
import socket

# Get the socket access
api=socket.select_access_point()
apo=socket.access_point(api)
apo.start()

# Do what you have to do here ...
Reply With Quote

#2 Old Re: Setting module paths for libraries and executing via PED vs. executing via Python - 2008-02-08, 12:19

Join Date: Feb 2008
Posts: 3
vluukkal
Offline
Registered User
Hi,

I noted a typing error in my code, I had:

sys.path.append('E:\\Python\gdata\service')

but it should be

sys.path.append('E:\\Python\gdata\docs')

and that is what I used to produce the behaviour
I saw. The problem still stands.

BR, Vesa
Reply With Quote

#3 Old Re: Setting module paths for libraries and executing via PED vs. executing via Python - 2008-02-08, 17:33

Join Date: Mar 2003
Posts: 125
Location: UK
aya42
Offline
Regular Contributor
Quote:
Originally Posted by vluukkal View Post
When I run my Test.py via the PED editor the imports work fine, I am asked for my access point, but after selecting one I get KErrPermissionDenied [Errno -46]. I suppose this happens because PED isn't signed for sufficient capabilities for IP access.
Correct.

Quote:
Originally Posted by vluukkal View Post
When I try to run the same script via the standalone Python interpreter, elementtree is imported fine, but gdata is not; I get

ImportError: No module named gdata.docs.service

Why this difference? Why is ElementTree nevertheless imported properly?
I haven't read the source for either the Python Script Shell or PED, but it is possible to override the default import mechanism by modifying the __builtin__.__import__ function, which could account for the discrepancy.

Quote:
Originally Posted by vluukkal View Post
The 'gdata' directory has several further subdirectories, 'docs' being one of them, both of them have a file called __init.py__ and there is a file gdata\docs\service.py. I'm not really fluent in Python so I probably don't quite get the module import system. Does the subdirectory structure need to be reflected in the additions to sys.path somehow?
If the directory contains an __init__.py, it signifies a nested import capability. You need only add the root directory to sys.path, and the subdirectories will be available as nested modules.

Quote:
Originally Posted by vluukkal View Post
I understand that one way of installing Python libraries is to make a .sis out of them, but I don't know how to proceed with something like the gdata library and furthermore I suppose I'd need to install the SDK. This all sounds like a lot of work.
Additional libraries can be included in the SIS file, and imported as normal. You can use ensymble if you don't wish to install the full SDK.

Quote:
Originally Posted by vluukkal View Post
Am I on the right track with the sys.path modification approach?
It should work.

Quote:
Originally Posted by vluukkal View Post
Could PED be tweaked somehow that the interpreter could run with enough rights to use the network?
You can re-sign the SIS file with sufficient rights to make network connections. Ensymble will do this also.

Quote:
Originally Posted by vluukkal View Post
...code snipped...
It's not clear from your post what the exact contents of the directories are, but given the following structure...

Code:
E:\Python\gdata\__init__.py
E:\Python\gdata\docs\__init__.py
E:\Python\gdata\docs\service.py
...then adding 'E:\Python' to sys.path would allow those 3 files to be imported with...

Code:
import gdata
import gdata.docs
import gdata.docs.service
...respectively. If you instead add 'E:\Python\gdata' to sys.path, those imports become...

Code:
import __init__
import docs
import docs.service
Reply With Quote

#4 Old Re: Setting module paths for libraries and executing via PED vs. executing via Python - 2008-02-09, 14:05

Join Date: Feb 2008
Posts: 3
vluukkal
Offline
Registered User
Hello,

Quote:
Originally Posted by aya42 View Post
If the directory contains an __init__.py, it signifies a nested import capability. You need only add the root directory to sys.path, and the subdirectories will be available as nested modules.
OK, this makes sense.

Quote:
Originally Posted by aya42 View Post
It's not clear from your post what the exact contents of the directories are, but given the following structure...

Code:
E:\Python\gdata\__init__.py
E:\Python\gdata\docs\__init__.py
E:\Python\gdata\docs\service.py
...then adding 'E:\Python' to sys.path would allow those 3 files to be imported with...

Code:
import gdata
import gdata.docs
import gdata.docs.service
This solved the problem, I now have only one addition to
the sys.path:

Code:
sys.path.append('E:\\Python')
and the packages are imported properly without other changes.
I guess I'll look into Ensymble as being able to run things from PED is so much
more easier.

Thanks for the explanation, Vesa
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia