Compile .py into .pyo

A forum for general discussion of the Python programming language.

Compile .py into .pyo

Postby josephgrab » Sat Apr 13, 2013 9:28 pm

I am not a student. I am trying to get my contacts off my cell phone and am using a program called BitPim. It works well but with my phone has a bug in that it cannot complete the phone book reading. I came across a bug fix. In order to get the program to work I have to compile two .py files into .pyo . I do not know how to do this. I have looked at the python -O command, compile_all, and several others. I cannot get the syntax right, the path right, I just get errors no matter what I do. I tried the command line python and the Windows GUI edition. I can check the file for errors and it checks good. I have programming experience in FORTRAN and BASIC, but none in other languages. I understand what compiling is, I just cannot get the commands correct. Any help would be greatly appreciated.
josephgrab
 
Posts: 5
Joined: Sat Apr 13, 2013 9:25 pm

Re: Compile .py into .pyo

Postby metulburr » Sat Apr 13, 2013 9:34 pm

*Moved your question from tutorials to general discussions. Tutorials is for posting tutorials*

what is the full command you are giving?
What errors exactly do you get?

Code: Select all
python -O path_to_file.py
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1562
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Compile .py into .pyo

Postby josephgrab » Sat Apr 13, 2013 10:36 pm

Code: Select all
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> python -O C:\Users\Dad\Desktop\New folder\p_lgvx11000.py
SyntaxError: invalid syntax
>>> python -O \Users\Dad\Desktop\New folder\p_lgvx11000.py
SyntaxError: unexpected character after line continuation character
>>> python -0 \Users\Dad\Desktop\New folder\p_lgvx11000.py
SyntaxError: unexpected character after line continuation character
>>>
Last edited by stranac on Sun Apr 14, 2013 9:12 am, edited 2 times in total.
Reason: Code tags
josephgrab
 
Posts: 5
Joined: Sat Apr 13, 2013 9:25 pm

Re: Compile .py into .pyo

Postby stranac » Sun Apr 14, 2013 9:14 am

You're not supposed to run that from the python interpreter.
Run it from the os shell/terminal/command line/whatever you want to call it.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm

Re: Compile .py into .pyo

Postby josephgrab » Tue Apr 16, 2013 12:12 pm

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Windows\system32> cd .

C:\Windows\system32>cd ..

C:\Windows>cd ..

C:\>python -O C:\Users\Dad\Desktop\BitPim Python Files\com_lgvx11000.py
python: can't open file 'C:\Users\Dad\Desktop\BitPim': [Errno 2] No such file or
directory

C:\>python -O C:\Users\Dad\Desktop\BitPimPythonFiles\com_lgvx11000.py
Traceback (most recent call last):
File "C:\Users\Dad\Desktop\BitPimPythonFiles\com_lgvx11000.py", line 19, in <m
odule>
import common
ImportError: No module named common

C:\>python -O C:\Users\Dad\Desktop\BitPimPythonFiles\p_lgvx11000.py
Traceback (most recent call last):
File "C:\Users\Dad\Desktop\BitPimPythonFiles\p_lgvx11000.py", line 12, in <mod
ule>
from p_lgvx9600 import *
ImportError: No module named p_lgvx9600

C:\>
Last edited by josephgrab on Tue Apr 16, 2013 12:43 pm, edited 1 time in total.
josephgrab
 
Posts: 5
Joined: Sat Apr 13, 2013 9:25 pm

Re: Compile .py into .pyo

Postby setrofim » Tue Apr 16, 2013 12:23 pm

Run it form inside the Windows command line (cmd.exe), not from Python command line interpreter.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Compile .py into .pyo

Postby josephgrab » Tue Apr 16, 2013 12:48 pm

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Dad>python -O Desktop\BitPimPythonFiles\com_lgvx11000.py
Traceback (most recent call last):
File "Desktop\BitPimPythonFiles\com_lgvx11000.py", line 19, in <module>
import common
ImportError: No module named common

C:\Users\Dad>python -O Desktop\BitPimPythonFiles\p_lgvx11000.py
Traceback (most recent call last):
File "Desktop\BitPimPythonFiles\p_lgvx11000.py", line 12, in <module>
from p_lgvx9600 import *
ImportError: No module named p_lgvx9600

C:\Users\Dad>
josephgrab
 
Posts: 5
Joined: Sat Apr 13, 2013 9:25 pm

Re: Compile .py into .pyo

Postby setrofim » Tue Apr 16, 2013 12:53 pm

Where are common.py and p_lgvx9600.py on your system? You need to make sure that they are either in the same directory as the scripts you're trying to compile or somewhere in your PYTHONPATH.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Compile .py into .pyo

Postby josephgrab » Tue Apr 16, 2013 12:58 pm

It took me a while to figure out what you guys were saying, but, I found the windows command line two different ways (cmd.exe being the easier), tried to compile, then added the other modules in, then this is what I received:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Dad>python -O Desktop\BitPimPythonFiles\p_lgvx11000.py
Traceback (most recent call last):
File "Desktop\BitPimPythonFiles\p_lgvx11000.py", line 12, in <module>
from p_lgvx9600 import *
ImportError: Bad magic number in C:\Users\Dad\Desktop\BitPimPythonFiles\p_lgvx96
00.pyo

C:\Users\Dad>python -O Desktop\BitPimPythonFiles\com_lgvx11000.py
Traceback (most recent call last):
File "Desktop\BitPimPythonFiles\com_lgvx11000.py", line 19, in <module>
import common
ImportError: No module named common

C:\Users\Dad>python -O Desktop\BitPimPythonFiles\com_lgvx11000.py
Traceback (most recent call last):
File "Desktop\BitPimPythonFiles\com_lgvx11000.py", line 19, in <module>
import common
ImportError: Bad magic number in C:\Users\Dad\Desktop\BitPimPythonFiles\common.p
yo

C:\Users\Dad>
josephgrab
 
Posts: 5
Joined: Sat Apr 13, 2013 9:25 pm

Re: Compile .py into .pyo

Postby setrofim » Tue Apr 16, 2013 1:16 pm

Try removing p_lgvx9600.pyo and common.pyo and re-generating them from the corresponding .py files.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm


Return to General Discussions

Who is online

Users browsing this forum: snippsat and 5 guests