2026年4月17日 星期五

樹莓派學習筆記 : 消除 PATH 環境變數警告的方法

高雄家的 Pi 3 A+ 主機在三月下旬我去日本時不明原因當機 (應該是 8GB TF 卡掛了), 它負責的爬蟲停擺, 回來後一直沒時間修復, 昨晚找出一片 32GB TF 卡重新燒錄 Bulleye 後已重新上線. 但在更新套件時出現一個警告 : 

pi@pi3aplus:~ $ pip install --upgrade requests urllib3   
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.25.1)
Collecting requests
... (略)...
Installing collected packages: urllib3, charset-normalizer, requests
  WARNING: The script normalizer is installed in '/home/pi/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed charset-normalizer-3.4.7 requests-2.32.5 urllib3-2.6.3

此警告意思是套件有安裝可執行腳本 (此處為 normalizer), 但該腳本所在目錄 /home/pi/.local/bin 沒有在 PATH 裡, 所以若在終端機直接打指令 (normalizer) 時會找不到, 出現 command not found 錯誤. 如果根本不用 CLI 工具執行此套件可忽略此警告, 但以後 pip install 時仍可能出現, 為了不礙眼, 乾脆將 /home/pi/.local/bin 加入 PATH 裡一勞永逸, 做法如下 :

編輯 .bashrc : 

pi@pi3aplus:~ $ nano ~/.bashrc   

在最底下加入此目錄 : 

export PATH="$HOME/.local/bin:$PATH"




重新執行 .bashrc 即可 :

pi@pi3aplus:~ $ source ~/.bashrc   

沒有留言 :