Questions tagged [pyc]

Python source code is automatically compiled into Python byte code by the CPython interpreter. Compiled code is usually stored in .pyc files, and is regenerated when the source is updated, or when otherwise necessary.

195 questions
7
votes
4 answers

Python: Programmatically compiling a Python package into pyc or pyo files

This is for my test suite. I have an automatically-generated Python package in a temporary folder. It's all .py files. I want to programmatically compile these into (a) .pyc and (b) .pyo files. (One test will do .pyc, another will do .pyo.) This…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
7
votes
1 answer

How to run a Python project using __pycache__ folder?

I want to run a Pythonic project using Python compilation (.pyc or __pycache__). In order to do that in Python2, I haven't any problem. Here is a simplified example in a Python2 project: Project tree: test2 ├── main.py └── subfolder ├──…
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
7
votes
1 answer

How to control where $py.class files go?

When importing modules for the first time, Jython creates $py.class files (Jython equivalent of .pyc) in the same directory as the corresponding .py file. A problem arises when the process has no permissions to write into that directory (everything…
Joonas Pulakka
  • 36,252
  • 29
  • 106
  • 169
7
votes
1 answer

Python threading.Timer object not functioning when compiled to .exe

This is a follow up to https://stackoverflow.com/questions/37684111/ironpython-exe-file-closing-immediately-no-exception-thrown I figured out that my program is not working once compiled due to an issue with the Timer object in the threading…
Inagnikai
  • 281
  • 1
  • 15
7
votes
2 answers

How do I compile multiple py files as one?

I am new to Python and am totally lost as to where to even start to get this done. I have written many small modules (a toolset for maya) that need to be compiled into on single .pyc file. Is there a module that just does this? Or can you tell me…
user12294
  • 91
  • 1
  • 2
7
votes
3 answers

Why are python libraries not supplied as pyc?

If I am right in understanding, Python compile files are cross platform. So why are most libraries released requiring a build and install? Is it laziness on the part of the distributer, or am I wrong in saying they could simply distribute the pyc…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
7
votes
2 answers

Cannot run a specific .pyc file

After compiling a in unix-working python file using import py_compile py_compile.compile('server.py') I get the .pyc file in the same directory, but when I try to run this file using './server.pyc' in putty all I get is scrambled code as an output…
Lazykiddy
  • 1,525
  • 1
  • 11
  • 18
7
votes
4 answers

What to do with pyc files when Django or python is used with Mercurial?

Just started to use Mercurial. Wow, nice application. I moved my database file out of the code directory, but I was wondering about the .pyc files. I didn't include them on the initial commit. The documentation about the .hgignore file includes an…
kd4ttc
  • 1,075
  • 1
  • 10
  • 28
6
votes
3 answers

How to run a .pyc file when it imports some other .py files?

main.py import other def main(): other.test() main() other.py def test(): print("Hello") By using python3 -m py_compile *.py, I can have 2 .pyc files. However, main.pyc cannot be run if there is no module named other, which is the error I…
idontknoooo
  • 261
  • 1
  • 3
  • 12
6
votes
1 answer

When do Python cached bytecode (pyc) files get updated?

Sometimes I am running unittest on a specific module by pointing to make PYTHON_TEST=path_of_module_to_test test and if this module path_of_module_to_test test imports some other python module that was updated, will importing done from this module…
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
5
votes
2 answers

Stop python from generating pyc files

When I change my Python code, I often need to delete the associated pyc file, or Python will not regenerate it and will run the old code. Is there a way to tell Python not to generated pyc files?
maolingzhi
  • 681
  • 3
  • 8
  • 16
5
votes
2 answers

Disabling pyc files in production

pyc files have been the cause of grief in the past and I have just recently seen a few posts about preventing python from generating them. Currently we just run a script to clean them up after any code changes to ensure fresh ones get generated but…
Jared Mackey
  • 3,998
  • 4
  • 31
  • 50
5
votes
1 answer

Should I generate *.pyc files when deploying?

When developing a Python web app (Flask/uWSGI) and running it on my local machine, *.pyc files are generated by the interpreter. My understanding is that these compiled files can make things load faster, but not necessarily run faster. When I deploy…
smitelli
  • 6,835
  • 3
  • 31
  • 53
5
votes
2 answers

How to execute compiled python code

I have a compiled Python file, path/program.pyc. I want to execute it with my current globals() and locals(). I tried: with open('path/program.pyc','rb') as f: code = f.read() exec(code, globals(), locals()) More specifically, what I want to…
Sait
  • 19,045
  • 18
  • 72
  • 99
5
votes
2 answers

python: Is there a way in python to delete the old .pyc before running the file

It seems that sometimes when I pull from the git the old .pyc runs instead of the new pulled .py file is there a way to automatically clear the .pyc file so it runs always the fresh version ?
Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
1 2
3
12 13