0

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?

  • Can you give an example on how are you compiling. Which version of python are you using? – mkc Dec 4 '13 at 21:57
  • try python -mcompileall – jfs Dec 16 '13 at 0:38
2

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.

  • 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
2

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

  • 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. – mkc 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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