Python 3.3 and .pyo files

Terry Reedy tjreedy at udel.edu
Sat Sep 22 18:54:12 EDT 2012


On 9/22/2012 9:21 AM, Steven D'Aprano wrote:
> On Fri, 21 Sep 2012 22:46:08 -0400, Terry Reedy wrote:
>
>> On 9/21/2012 5:10 AM, Marco wrote:
>>> I was trying to import a pyo module in Python 3.3, but Python does not
>>> find it:
>>
>> You appear to be trying to *run*, not *import* a .pyo module.
>
> Marco is using the standard mechanism for finding, importing, and running
> a module. I don't believe his use of -m should be a problem. It works in
> 3.2, and it works with .pyc files in 3.3, I see nothing to suggest it
> shouldn't work with .pyo files in 3.3.
>
>
>>> $ echo "print(__file__)" > foo.py
>>> $ python3.3 -O -m foo
>>
>> Since foo.py is in the current directory, I am not sure why you use '-m
>> foo' instead of 'foo.py'. -m is for running a module somewhere on
>> sys.path.
>
> Yes, and the current directory is on sys.path.
>
> I would be astonished if python -m could not find a module that happened
> to be in the current directory.
>
>
> [...]
>> Also, the
>> -O is sort of redundant, or perhaps interfering, since its usual effect
>> to to say 'get and put, from and to the cache, .pyo instead of .pyc'.
>
> No it is not redundant. You link specifically to an bug tracker issue
> below where is is clearly decided that if you want to run a .pyo file you
> *must* use the -O switch. (I approve of this decision.)
>
>
>>> /usr/local/bin/python3.3: No module named foo
>>>
>>> How come? Thanks in advance, Marco
>>
>> You might read some of http://bugs.python.org/issue12982
>>
>> in particular, from http://bugs.python.org/issue12982#msg162814
>
> Whose words are these following?
>
>
>> Python interpreters exist to run Python code. The existence,
>> persistence, and other details of compilation caches are
>> version-dependent implementation details. Being able to execute from
>> such caches without source present is also an implementation detail, and
>> for CPython, it gets secondary support at best. (This is a compromise
>> between full support and no support.)"
>
> I'm not sure if these are your words, or if you are quoting some random
> commenter on the pydev list, or one of the lead developers who might
> actually know what he is talking about.

My words summarizing the discussion on pydev which included at least a 
few lead developers. My initial post was probably 6/12/2012


-- 
Terry Jan Reedy




More information about the Python-list mailing list