Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something like __pycache__ for Python 2.x?

I would like to avoid cluttering up my working directory with Python bytecode *.pyc files. Python 3.2+ uses a subdirectory called __pycache__ for this purpose.

Since many of the projects I work on are Python 2.7, I'm wondering if there are any workarounds or utilities that can allow me to implement some similar behavior in my case?

like image 485
Stew Avatar asked May 26 '16 17:05

Stew


People also ask

What is __ Pycache __ in Python?

__pycache__ is a directory that contains bytecode cache files that are automatically generated by python, namely compiled python, or . pyc , files.

Can we delete __ Pycache __?

__pycache__ is a folder containing Python 3 bytecode compiled and ready to be executed. I don't recommend routinely laboriously deleting these files or suppressing creation during development as it wastes your time.

Should you push Pycache?

__pycache__ is among the directories that shouldn't be pushed to remote repositories. Therefore, all you need to do is specify the directory in . gitignore file. Note that for Python projects in general, there are a lot more files that need to go into .

How do I clear all cache in Python?

In the Project Tool Window , right-click a project or directory, where Python compiled files should be deleted from. On the context menu, choose Clean Python compiled files .


1 Answers

You can try the -B option of Python:

-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x

So, you can run python -B test.py or set PYTHONDONTWRITEBYTECODE appropriately.

like image 97
ForceBru Avatar answered Oct 28 '22 13:10

ForceBru