Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Lab Assistant
Original Poster
#1 Old 18th Sep 2014 at 5:41 AM
Default How is a pyo file created in Python 3.3.5 Shell?
It's probably easy but I'm not able to get the syntax correct when guessing and can't find a lot searching for an answer on google.

I've tried

python -o foo.py --> syntax error
py_compile.compile("foo.py") --> this gives a pyc result

I've tried a bunch of ways, just get syntax errors and can't hit it. Any help?
Advertisement
Lab Assistant
Original Poster
#2 Old 18th Sep 2014 at 5:47 AM
Ok this works:

py_compile.compile("foo.py",None,None,False,1)

whew
Test Subject
#3 Old 20th Sep 2014 at 8:21 AM Last edited by fetusdip : 20th Sep 2014 at 8:22 AM. Reason: wasn't clear that the dot was a part of the command
If you need to compile more than one file I recommend this:
Code:
python -O -m compileall .
Lab Assistant
#4 Old 20th Sep 2014 at 10:28 AM
Compiling one file is pretty easy. I do it like by opening the command line in Windows and typing this:

Code:
C:\python33\python.exe -O
>>>import mymodule


First of all, you'll need to put your module in the python33 directory. Also, you'll find the compiled file in the __pycache__ folder of your python33 directory.
Lab Assistant
#5 Old 26th Sep 2014 at 2:17 AM
Hey mgomez, can you help me out?
I'm try to compile py scripts and I always end up failing because of a missing module. For example, I am trying to compile a mod from this site (the mod includes a pyo file already but I just want to see if I can do it). I place the mod in the directory (Scripts) with alongside the pyhton files from the sims 4 folder, and I type this:
Code:
python -O Scripts/ChangeSimGender.py


To compile this, it has to import some sims 4 modules. It imports sims4.commands, enums, and so on.
When it tries to compile sims4.log, I get an error on line 1 because it can't find module _trace (which is imported on line one of sims4.log)

What am I doing wrong?

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Lab Assistant
#6 Old 26th Sep 2014 at 8:02 AM
Quote: Originally posted by MasterDinadan
Hey mgomez, can you help me out?
I'm try to compile py scripts and I always end up failing because of a missing module. For example, I am trying to compile a mod from this site (the mod includes a pyo file already but I just want to see if I can do it). I place the mod in the directory (Scripts) with alongside the pyhton files from the sims 4 folder, and I type this:
Code:
python -O Scripts/ChangeSimGender.py


To compile this, it has to import some sims 4 modules. It imports sims4.commands, enums, and so on.
When it tries to compile sims4.log, I get an error on line 1 because it can't find module _trace (which is imported on line one of sims4.log)

What am I doing wrong?


You don't have to import them or anything. Just compile it like that with the missing modules. It will yield a pyo with your script as long as there are no syntax errors. You should see your PYO in the __pycache__ folder of Python33.
Back to top