2025年10月13日 星期一

清理 Pythonanywhere 磁碟

雖然 Pythonanywhere 無法做為 LINE Bot 的後端伺服器, 但也不失為一個好用的線上免費 Python 測試學習與測試環境 (基礎教學工具). 我的 Pythonanywhere 帳戶已註冊很多年了, 儀錶板顯示 512MB 的硬碟空間居然被用掉 426 MB, 但之前我好像只做過一些 Flask 測試啊! 

先用下列指令檢查那些怪獸吃掉硬碟 :

du -h ~/ | sort -h | tail -20   

02:10 ~ $ du -h ~/ | sort -h | tail -20  
22M     /home/tony1966/.local/lib/python3.10/site-packages/numpy/_core
22M     /home/tony1966/.local/lib/python3.10/site-packages/pandas/_libs
27M     /home/tony1966/.local/lib/python3.10/site-packages/numpy.libs
29M     /home/tony1966/.local/lib/python3.10/site-packages/pandas/tests
41M     /home/tony1966/.cache/pip/http/8/8
41M     /home/tony1966/.cache/pip/http/8/8/a
41M     /home/tony1966/.cache/pip/http/8/8/a/9
41M     /home/tony1966/.cache/pip/http/8/8/a/9/4
41M     /home/tony1966/.local/lib/python3.10/site-packages/numpy
57M     /home/tony1966/.cache/pip/http/8
65M     /home/tony1966/.local/lib/python3.10/site-packages/pandas
89M     /home/tony1966/.cache
89M     /home/tony1966/.cache/pip
89M     /home/tony1966/.cache/pip/http
139M    /home/tony1966/.local/lib/python3.10/site-packages/pyarrow
324M    /home/tony1966/.local/lib
324M    /home/tony1966/.local/lib/python3.10
324M    /home/tony1966/.local/lib/python3.10/site-packages
337M    /home/tony1966/.local
426M    /home/tony1966/

原來之前可能手動安裝了 Numpy, Pandas, 與 pyarrow 等套件 (python3.10/site-packages 底下都是自行安裝的套件), 光是很少用到的 pyarrow 就吃掉 139 MB! 其次是 Pythonanywhere 預設就已提供 Pandas 等全套資料科學與機器學習套件, 根本毋須自行安裝, 所以先用下列指令移除所有這些套件以及 pip cache 與其它暫存 : 

rm -rf ~/.local/lib/python3.10/site-packages/*   
rm -rf ~/.cache/pip  
rm -rf ~/.local/lib/python3.10/__pycache__/

02:14 ~ $ rm -rf ~/.cache/pip   
02:15 ~ $ rm -rf ~/.local/lib/python3.10/site-packages/* 
02:16 ~ $ rm -rf ~/.local/lib/python3.10/__pycache__/  

再次檢查檔案占用情形 : 
    
02:17 ~ $ du -h ~/ | sort -h | tail -20     
8.0K    /home/tony1966/.ipython/profile_default/startup
8.0K    /home/tony1966/.local/etc/jupyter/nbconfig/notebook.d
12K     /home/tony1966/.ipython/profile_default
12K     /home/tony1966/.local/etc/jupyter/nbconfig
12K     /home/tony1966/.local/lib/python3.10/site-packages
16K     /home/tony1966/.ipython
16K     /home/tony1966/.local/bin
16K     /home/tony1966/.local/etc/jupyter
16K     /home/tony1966/.local/lib/python3.10
20K     /home/tony1966/.local/etc
20K     /home/tony1966/.local/lib
52K     /home/tony1966/.virtualenvs
116K    /home/tony1966/.cache/python-entrypoints
120K    /home/tony1966/.cache
14M     /home/tony1966/.local
14M     /home/tony1966/.local/share
14M     /home/tony1966/.local/share/jupyter
14M     /home/tony1966/.local/share/jupyter/nbextensions
14M     /home/tony1966/.local/share/jupyter/nbextensions/pydeck
15M     /home/tony1966/

哈哈! 這番清理下來只用掉 14MB, 還有近 500MB 可用! 




清理完試試看能否匯入資料科學與機器學習套件 : 

02:18 ~ $ python   
Python 3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd   
>>> import matplotlib.pyplot as plt   
Matplotlib is building the font cache; this may take a moment.
>>> import numpy as np  
>>> import sklearn   
>>> import tensorflow as tf    
2025-10-13 02:44:07.189467: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'li
bcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2025-10-13 02:44:07.189498: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not hav
e a GPU set up on your machine.
>>> import torch  
>>> torch.__version__   
'1.11.0+cpu'
>>> exit()  

果然這些都已內建, 毋須自行安裝. 

沒有留言 :