Where do we set PYTHONDONTWRITEBYTECODE=1.?
Anywhere in your environment, .bashrc for example.
Hello everyone, I have the same problem with creation of __pycache__ I added PYTHONDONTWRITEBYTECODE=1 in my /etc/environment but it still creates. Is there other way? thanks!
Hi @clorieanne,
Not sure, pytest certainly respects that:
Also I just tested this and setting the PYTHONDONTWRITEBYTECODE=1 correctly prevents pytest from writing the __pycache__ folder.
Perhaps is some other library creating the folder?
In order to prevent both ./.pytest_cache _and_ ./**/__pycache__ from being generated.
The only thing that worked for me was using both the above solution _as well as_ disabling caching
PYTHONDONTWRITEBYTECODE=1 python -m pytest -p no:cacheprovider
(source)
As far as I can tell, the above command does not generate any artifacts. IMHO no:cacheprovider should be the default. If users want performance enhancements they should have to explicitly specify that.
@golubitsky indeed .pytest_cache is created regardless... we should think how better support running pytest on readonly file systems.
FWIW cacheprovider is not about performance, but to persist data between test sessions, and provides --lf and --ff flags. And sorry, but performance enhancements should be enabled by default if that were the case, as many other things in Python are. For example you get accelerator modules when importing some builtin modules (like pickle) automatically by default.
Opened #3557 as followup.
Hello, everyone
I have the same problem when I build Python package by setup.py, and how do I package and install the Python package without creating __pycache__ directory.
Thanks!
@SharanyaVR You need to export the PYTHONDONTWRITEBYTECODE variable, not enough to only create it in the current shell.
Most helpful comment
In order to prevent both
./.pytest_cache_and_./**/__pycache__from being generated.The only thing that worked for me was using both the above solution _as well as_ disabling caching
(source)
As far as I can tell, the above command does not generate any artifacts. IMHO
no:cacheprovidershould be the default. If users want performance enhancements they should have to explicitly specify that.