Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have read that python will compile the source file .py by itself to produce .pyc, but this doesn't happen in my case. I have the source file inside /opt/osqa folder where I always have to use sudo privileges.

How can I compile this source file manually. I am using ArchLinux. Do I need any specific package?

share|improve this question
    
Can you give an example on how are you compiling. Which version of python are you using? –  Ketan Dec 4 '13 at 21:57
    
try python -mcompileall –  J.F. Sebastian Dec 16 '13 at 0:38

2 Answers 2

up vote 2 down vote accepted

The .pyc files are created when files are imported. Usually running a script by itself will not create a compiled file. For instance:

% cat tmp.py
print 'in tmp.py'

When I run the file normally:

% python tmp.py 
in tmp.py

there is no .pyc file created:

% ls tmp.py*
tmp.py

However, if I import tmp from a live Python interpreter:

% python
Python 2.7.6 (default, Nov 14 2013, 09:55:56) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tmp
in tmp.py
>>> 

then the compiled file is created:

% ls tmp.py*
tmp.py  tmp.pyc

So, it may be normal behaviour depending on how you are running your script.

share|improve this answer
    
I opened python by sudo python and then executed import settings_style.py the compilation began but I got an error. Well as it conserns me this question is solved... –  71GA Dec 5 '13 at 6:28

I suspect the .pyc files are not being created because of permission settings in the directory that you have your python sources. See this for more info: http://effbot.org/pyfaq/how-do-i-create-a-pyc-file.htm

share|improve this answer
    
I was thinking of this too. This is why I also mentioned it. I have also read the link you posted but i have no py command mentioned in the link. So do i need any speciffic package for this? There is no package py in the official repo archlinux.org/packages/… and none in AUR repo aur.archlinux.org/packages/?O=0&K=py –  71GA Dec 4 '13 at 22:17
    
Try copying the python code to your home directory and compile. Just use normal python yourcode.py and see if yourcode.pyc gets created. –  Ketan Dec 4 '13 at 22:23
    
I tried and the compilation started but was terminated because the source file was moved and was therefore not finding the other dependant source files. I ll have to find a way t ocompile it in the folder as is. Will try changing the folder rights to 777 and see what happens. –  71GA Dec 5 '13 at 6:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.