You Are Here:

Community: Developer Discussion Boards

#1 Old How to compile PY to PYC? - 2008-03-25, 00:00

Join Date: Mar 2003
Posts: 936
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
I just installed python 2.2.2 into Windows Vista and run "py_compile.compile("C:\\Symbian\\9.1\\S60_3rd_MR\\Epoc32\\winscw\\c\\python\\16puzzle.py")
which created a file named "16puzzle.pyc"

I moved the file from PC to E61i and tried to start it up from pyS60 python shell:

Quote:
Traceback (most recent call last):
File "C:\private\2000b1a5\default.py", line 81, in menu_action
f()
File "C:\private\2000b1a5\default.py", line 65, in query_and_exec
execfile(script_list[index][1].encode('utf-8'), script_namespace.namespace)
File "e:\python\16puzzle.pyc", line 2
I believe that line contains "import appuifw"... The script works ok in emulator and in E61i device when used as PY file. I can't figure out how to continue. What's the problem? How to debug this?

I don't have any external 3rd party libraries, everything is as default and basic as possible. I even have Main class for some reason, even thought it's really easy script. Howabout importing os and sys, shouldn't that be possible, too?

Start of script:
Quote:
import appuifw
import graphics
import e32
import key_codes
from random import randint
Reply With Quote

#2 Old Re: How to compile PY to PYC? - 2008-03-25, 12:47

Join Date: Mar 2008
Posts: 57
nokia_e70
Offline
Regular Contributor
Well, here's what I did. This is Hello.py:

Code:
import appuifw
appuifw.note(u"Hello World!")
Run python on windows, import Hello. Gives an error but compiles the file to Hello.pyc. Move the file to the phone (in c:\\Data). Run the python shell on the phone:

Code:
import sys
sys.path.append('c:\\Data')
import Hello
Reply With Quote

#3 Old Re: How to compile PY to PYC? - 2008-03-25, 22:02

Join Date: Mar 2003
Posts: 936
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Impressive,

After ten attempts I got this result below. No idea why I got just one step forward with each identical try... Using 1.4.1.

Btw (imported) filename may NOT start with (or possibly not even contain) numbers, only alphabets. Weird, but now I know and can avoid it.

Btw console output is using a variable-width font, not monospaced. This means that error output with that nice upwards arrow is pointing in wrong location! Wasted some time to figure this out.

Quote:
Traceback (most recent call last):
File "<console>", line 1, in ?
File "c:\resource\site.py", line 97, in platsec_import
return_original_import(name, globals, locals, fromlist)
File: "C:\Symbian\9.1\S60_3rd_MR\Epoc32\winscw\c\python\puzzle.py", line 57, in ?
File: "c:\resource\graphics.py", line 76, in open
img=Image(_graphics.ImageOpen(unicode(filename), finish_load))
SymbianError: [Errno -12] KErrPathNotFound
Now I know where that error is and can fix it - but this is still not right. I want to create and release a single file, easy to install and update and run without a separate script to launch it or force user to type this kind of complex commands.

Pre-compiled PYC was supposed to make that possible. Looks like not. If you want to use python even in semi-commercial way, you cannot release plain readable ascii text script file(s). No future doing that.

Hmph, guess I'll have to study creation of full-fledged SIS/SISX packages. Not the best use of available time and effort.

Thanx for help,

--jouni
Reply With Quote

#4 Old Re: How to compile PY to PYC? - 2008-06-10, 18:04

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Erm any ideas of how to do this?

I've read about py_compile but can't find it
Reply With Quote

#5 Old Re: How to compile PY to PYC? - 2008-06-10, 18:36

Join Date: May 2007
Posts: 2,737
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by Dansco View Post
Erm any ideas of how to do this?

I've read about py_compile but can't find it
Hi Dansco,

Should this help ?

http://discussion.forum.nokia.com/fo...36&postcount=2

Best Regards,
Croozeus
Reply With Quote

#6 Old Re: How to compile PY to PYC? - 2008-06-10, 22:54

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Quote:
Originally Posted by croozeus View Post
Hi Dansco,

Should this help ?

http://discussion.forum.nokia.com/fo...36&postcount=2

Best Regards,
Croozeus
Likes good mate so many thanx
Reply With Quote

#7 Old Re: How to compile PY to PYC? - 2008-06-11, 07:55

Join Date: Mar 2003
Posts: 936
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by Dansco View Post
Erm any ideas of how to do this?
I've read about py_compile but can't find it
I'll have to check that py2pyc tool, too, thanx for tip Croozeus!

My problem was a missing default.py, which would have loaded and launched the .pyc file. Otherwise everythng was ok, but seems like there is no way around it. I'll continue the experiments, when I manage to get the second last "just one more feature" working

Cheers,

--jouni
Reply With Quote

#8 Old Re: How to compile PY to PYC? - 2008-06-11, 19:51

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Sadly I thought this was a phone based app. I'm not brilliant with the PC Python version so any help with the command line etc please?
Reply With Quote

#9 Old Re: How to compile PY to PYC? - 2008-06-11, 21:25

Join Date: Mar 2003
Posts: 936
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by Dansco View Post
Sadly I thought this was a phone based app. I'm not brilliant with the PC Python version so any help with the command line etc please?
Well, as far as I recall any more, it's really simple to get started.

Install Python 2.2.2 (or 2.2.3) for Windows, start it up, import your script.py, ignore error message and that's about it. Now you should have script.pyc. I don't think you need to find and install py_compile, it just was the first thing I found when searching DiBo.

Never got any further, but you do need to write a default.py, which will setup your environment (sys.path) and load the script.pyc. ALso remember to add path(s) to your support files, such as graphics, text, audio etc.

Now that I got animation working, I'll just need one more thing before I'll continue this operation. Want to make an installable application, so please report what works or not

Cheers,

--jouni
Reply With Quote

#10 Old Re: How to compile PY to PYC? - 2008-06-11, 23:16

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Quote:
Originally Posted by JOM View Post
Well, as far as I recall any more, it's really simple to get started.

Install Python 2.2.2 (or 2.2.3) for Windows, start it up, import your script.py, ignore error message and that's about it. Now you should have script.pyc. I don't think you need to find and install py_compile, it just was the first thing I found when searching DiBo.

Never got any further, but you do need to write a default.py, which will setup your environment (sys.path) and load the script.pyc. ALso remember to add path(s) to your support files, such as graphics, text, audio etc.

Now that I got animation working, I'll just need one more thing before I'll continue this operation. Want to make an installable application, so please report what works or not

Cheers,

--jouni
I have Python v2.5 but will still try it mate. Thanx for the info
Reply With Quote

#11 Old Re: How to compile PY to PYC? - 2008-06-12, 07:54

Join Date: Mar 2003
Posts: 936
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by Dansco View Post
I have Python v2.5 but will still try it mate. Thanx for the info
Sorry,

Python v2.5 for Windows is not compatible with PyS60, which is based on python v2.2.2. It's documented, but furthermore I can also confirm that v.2.5 generated .pyc files won't work. Tried it, of course

I have installed both 2.2 and 2.5 for Windows, use for different reasons.

Cheers,

--jouni
Reply With Quote

#12 Old Re: How to compile PY to PYC? - 2008-06-12, 15:31

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Quote:
Originally Posted by JOM View Post
Sorry,

Python v2.5 for Windows is not compatible with PyS60, which is based on python v2.2.2. It's documented, but furthermore I can also confirm that v.2.5 generated .pyc files won't work. Tried it, of course

I have installed both 2.2 and 2.5 for Windows, use for different reasons.

Cheers,

--jouni
Yeah I know v2.5 doesn't work lol Didn't know you could have two different versions of Python on your PC - will do thanx again mate
Reply With Quote

#13 Old Re: How to compile PY to PYC? - 2008-06-12, 20:17

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Installed v2.2.3 and thought I'd done it right but still the same error.

Can you help me please create one? I can't do anything via the idle.pyw etc
Reply With Quote

#14 Old Re: How to compile PY to PYC? - 2008-06-13, 18:07

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
I found this - http://www.lfdm.net/thesis/index.php/2007/04/08/ and finally managed to get my file into a pyc

Sadly I now can't execute (run) another pyc or py file. The pyc says "module doesn't have .run()". Any ideas?
Last edited by Dansco : 2008-06-13 at 20:32.
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
Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile problems... malloc Symbian Tools & SDKs 4 2009-11-17 13:47
Compile error when upgrading from NDS 1.1 to Carbide.vs 2.0.1 ericcwhung Symbian Tools & SDKs 1 2006-04-24 08:58
to many include paths cannot compile brookp Carbide.c++ IDE and plug-ins 2 2005-05-31 23:27
SDK 7.0 (7710) failed to compile under .NET Jeepy Symbian Tools & SDKs 0 2005-02-17 16:46
PLEASE ANSWER: How to compile j2me with NDS? andreaslorenz Mobile Java General 3 2003-05-16 14:34

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 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ