Python 2.7 importing pyc files without py files

M

Mircescu Andrei

Hi,


I encountered a strange issue. I have an application which uses extensively python 2.7.6 (CPython).


The issue that I see is the following:
If there are only pyc files, the loading time of the application is much more than if I have pyc and py files. It is behind with 2 minutes more than if it had py files

Do you have any idea why this is happening ? Maybe is because, python tries to search the py file in all the paths and this search is exhaustive ? This is the best guess I could figure it out but I'm not sure.

Also, if this is the scenario, there is a way I can stop this, to not search for the py files ? is there an api ? or a compiling flag I should set ?
 
E

Emile van Sebille

If there are only pyc files, the loading time of the application is
much more than if I have pyc and py files. It is behind with 2
minutes more than if it had py files

You may get some clues by starting python as

/path/to/python/python2.7 -vv

which will provide the details of attempts to import:

[root@vsds4 log]# python2.7 -vv
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# trying /usr/local/lib/python2.7/site.so
# trying /usr/local/lib/python2.7/sitemodule.so
# trying /usr/local/lib/python2.7/site.py
# /usr/local/lib/python2.7/site.pyc matches /usr/local/lib/python2.7/site.py
import site # precompiled from /usr/local/lib/python2.7/site.pyc
# trying /usr/local/lib/python2.7/os.so
# trying /usr/local/lib/python2.7/osmodule.so
# trying /usr/local/lib/python2.7/os.py
# /usr/local/lib/python2.7/os.pyc matches /usr/local/lib/python2.7/os.py
import os # precompiled from /usr/local/lib/python2.7/os.pyc
....



HTH,

Emile
 
T

Terry Reedy

Hi,


I encountered a strange issue. I have an application which uses
extensively python 2.7.6 (CPython).


The issue that I see is the following: If there are only pyc files,
the loading time of the application is much more than if I have pyc
and py files. It is behind with 2 minutes more than if it had py
files

Do you have any idea why this is happening ? Maybe is because, python
tries to search the py file in all the paths and this search is
exhaustive ? This is the best guess I could figure it out but I'm not
sure.

It seems plausible. Once .py is found, the .pyc is in the same directory.
Also, if this is the scenario, there is a way I can stop this, to not
search for the py files ?

Try reducing sys.path to the minimum needed.
 
M

Mircescu Andrei

joi, 20 februarie 2014, 00:25:41 UTC+2, Emile van Sebille a scris:
If there are only pyc files, the loading time of the application is
much more than if I have pyc and py files. It is behind with 2
minutes more than if it had py files



You may get some clues by starting python as



/path/to/python/python2.7 -vv



which will provide the details of attempts to import:



[root@vsds4 log]# python2.7 -vv

# installing zipimport hook

import zipimport # builtin

# installed zipimport hook

# trying /usr/local/lib/python2.7/site.so

# trying /usr/local/lib/python2.7/sitemodule.so

# trying /usr/local/lib/python2.7/site.py

# /usr/local/lib/python2.7/site.pyc matches /usr/local/lib/python2.7/site.py

import site # precompiled from /usr/local/lib/python2.7/site.pyc

# trying /usr/local/lib/python2.7/os.so

# trying /usr/local/lib/python2.7/osmodule.so

# trying /usr/local/lib/python2.7/os.py

# /usr/local/lib/python2.7/os.pyc matches /usr/local/lib/python2.7/os.py

import os # precompiled from /usr/local/lib/python2.7/os.pyc

...







HTH,



Emile

I cannot start python since i'm embedding it in .net with pythonnet solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top