Python Forum
Unable to disable creation of __pycache__ and .pyc files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to disable creation of __pycache__ and .pyc files
#1
When I install a package using pip, I would like to disable the creation of __pycache__ folders and .pyc files. I tried option -B with python and --no-cache-dir with pip but this does not prevent creation of these files/folders. Is anything else required for this to work?

Output:
(foo) [user@centos75 test]$ python -V Python 3.6.3 (foo) [user@centos75 test]$ which python /opt/test/foo/bin/python (foo) [user@centos75 test]$ ll /opt/test/foo/bin/python lrwxrwxrwx. 1 user user 39 Oct 3 11:45 /opt/test/foo/bin/python -> /opt/rh/rh-python36/root/usr/bin/python (foo) [user@centos75 test]$ find foo -name *.pyc | grep idna (foo) [user@centos75 test]$ python -I -B -m pip install idna --disable-pip-version-check --no-cache-dir Collecting idna Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB) 100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 61kB 2.2MB/s Installing collected packages: idna Successfully installed idna-2.7 (foo) [user@centos75 test]$ find foo -name *.pyc | grep idna foo/lib/python3.6/site-packages/idna/__pycache__/__init__.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/codec.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/compat.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/core.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/idnadata.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/intranges.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/package_data.cpython-36.pyc foo/lib/python3.6/site-packages/idna/__pycache__/uts46data.cpython-36.pyc (foo) [user@centos75 test]$
Reply
#2
pip (i believe) uses gc. You can read about it here: https://docs.python.org/3.7/library/gc.html#module-gc
there are arguments that you can include to modify behavior, but now you're messing with things you really shouldn't touch and I wouldn't go there.
I rarely look at site-packages. Perhaps use something like bleachbit, but again, you better know exactly what you are doing.

My suggestion: don't look at site packages, if you want to know what's installed with pip, use
pip list
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Errors when trying to disable tkinter checkbutton rrick_88 7 2,838 Feb-17-2022, 10:30 PM
Last Post: deanhystad
  unable to list files in a directory christober 2 2,039 Sep-18-2019, 11:45 PM
Last Post: wavic
  an easy way to disable exception handling Skaperen 6 5,423 Jun-02-2019, 10:38 PM
Last Post: Gribouillis
  disable a block of code Skaperen 5 13,228 Aug-20-2018, 07:55 AM
Last Post: Skaperen
  gnureadline: disable temporarily? klaymen 1 2,452 May-08-2018, 11:16 AM
Last Post: Larz60+
  files creation question, any help plz ? Qubayel 10 7,239 Apr-12-2017, 02:34 PM
Last Post: wavic
  Unable to open files without file extension pstarrett 3 7,243 Dec-25-2016, 09:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020