I am having issues understanding the pycache folder. Running some simple scripts today I noticed my pycache folder was created and had the .pyc file for ONE of the two scripts I was running. Why not .pyc files for both. This is in Liunux, using the #! /user/bin/python3 line at the top of my scripts so I can run the simple by typing ./script_name. Just to ensure I was not confused, I deleted the pycache folder and ran both scripts again, but now no pycache folder was created. I also ran them as python3 my_scripts, still no pycache folder is getting created. Can someone explain to me how this works, or point me to a GOOD article explaining this. I know why it gets created, but I dont know why it si sometimes not even if I dont use flags or env vars to suppress it's creation. Thanks
Asked
Active
Viewed 1,434 times
0
-
3Possible duplicate of [What is \_\_pycache\_\_?](https://stackoverflow.com/questions/16869024/what-is-pycache) – Rajen Raiyarela Jan 09 '19 at 11:41
-
Nope, dont think so. I know what the __pycache__ folder is for, what I dont understand is why it is sometimes created and sometimes not. I do know that you can use flags or ENV vars to make python not create it, but I am not using those. – mikeg Jan 09 '19 at 11:43
-
3`__pycache__` is created when you import the file (in another script), not when you run it. – mportes Jan 09 '19 at 11:47
-
myrmica, thanks, I just ran some quick tests and you are absolutely correct. That was mention in the post that Rajen pointed me to, but there was conflicting responses. Thank you very much. – mikeg Jan 09 '19 at 11:56
-
1@mikeg Also, you will get a `.pyc` file when you run the file as a module from command line, e.g. `python3 -m name`. (as opposed to `python3 name.py`) – mportes Jan 21 '19 at 12:21