Message from discussion
Python 3.3 and .pyo files
Received: by 10.180.98.234 with SMTP id el10mr41391wib.3.1348281997410;
Fri, 21 Sep 2012 19:46:37 -0700 (PDT)
Path: ed8ni15172365wib.0!nntp.google.com!goblin3!goblin1!goblin.stu.neva.ru!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path: <python-python-l...@m.gmane.org>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@mail.python.org
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05;
'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229':
0.09; 'received:gmane.org': 0.09; 'received:list': 0.09;
'subject:files': 0.09; 'terry': 0.09; '-o,': 0.16; '3.3,': 0.16;
'__pycache__': 0.16; 'caches': 0.16; 'compromise': 0.16;
'deprecated.': 0.16; 'echo': 0.16; 'existence,': 0.16;
'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16;
'redundant,': 0.16; 'reedy': 0.16; 'subject:3.3': 0.16; 'wrote:':
0.17; 'compilation': 0.17; 'jan': 0.18; 'module': 0.19; 'code.':
0.20; 'discussion': 0.20; 'sort': 0.21; 'trying': 0.21; 'import':
0.21; 'defined': 0.22; 'posted': 0.22; '(this': 0.24; 'somewhere':
0.24; 'url:bugs': 0.24; 'header:In-Reply-To:1': 0.25; 'header
:User-Agent:1': 0.26; '---': 0.26; 'appear': 0.26; 'am,': 0.27;
'separate': 0.27; 'question': 0.27; 'module.': 0.27; 'header:X
-Complaints-To:1': 0.28; 'run': 0.28; 'source': 0.29; 'gets':
0.32; 'problem.': 0.32; 'url:python': 0.32; 'running': 0.32;
'could': 0.32; 'skip:_ 30': 0.32; 'directory,': 0.33; 'subject:
.': 0.33; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'exist':
0.35; 'moved': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org':
0.36; 'should': 0.36; 'execute': 0.37; 'does': 0.37; 'being':
0.37; 'why': 0.37; 'usual': 0.37; 'subject:: ': 0.38; 'some':
0.38; 'sure': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39;
'space': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40;
'between': 0.63; 'worth': 0.63; 'details': 0.63; 'night,': 0.65;
'saving': 0.72; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane: http://gmane.org/
To: python-l...@python.org
From: Terry Reedy <tjre...@udel.edu>
Subject: Re: Python 3.3 and .pyo files
Date: Fri, 21 Sep 2012 22:46:08 -0400
References: <k3hatd$kt...@speranza.aioe.org>
Mime-Version: 1.0
X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64;
rv:15.0) Gecko/20120824 Thunderbird/15.0
In-Reply-To: <k3hatd$kt...@speranza.aioe.org>
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/python-list>,
<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.1057.1348281994.27098.python-l...@python.org>
Lines: 52
NNTP-Posting-Host: 2001:888:2000:d::a6
X-Trace: 1348281994 news.xs4all.nl 6846 [2001:888:2000:d::a6]:43233
X-Complaints-To: ab...@xs4all.nl
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
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.
> $ 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.
> /home/marco/temp/foo.py
> $ ls
> foo.py __pycache__
> $ rm foo.py
> $ mv __pycache__/foo.cpython-33.pyo foo.pyo
> $ rm __pycache__ -r
> $ ls
> foo.pyo
> # The following works in Python3.2, but not in 3.3
> $ python3.3 -O -m foo
I would try just 'foo.pyo' in case the -m part is the problem.
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'.
> /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
"Indeed, since I posted last night, the pydev discussion has moved to
the question of whether -O, __debug__, and .pyo as now defined are worth
the nuisance they cause or whether some or all should be deprecated.
(Docstring stripping for saving space could then be a separate tool.)
---
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.)"
--
Terry Jan Reedy