2022年7月19日 星期二

樹莓派執行 Pandas 出現 "Original error was: libf77blas.so.3"

晚上在佈署比特幣與乙太幣爬蟲程式到樹莓派時, 手動執行卻出現如下錯誤 : 

pi@raspberrypi:~ $ python3 btc_eth_prices_line_notify.py    
Traceback (most recent call last):
  File "btc_eth_prices_line_notify.py", line 2, in <module>
    import pandas as pd
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py", line 17, in <module>
    "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "/usr/bin/python3"
  * The NumPy version is: "1.20.3"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory    

乍看似乎是在 import pandas 時出現錯誤, 但實際上是載入 Numpy 中的 C 程式時有問題, 因為 Pandas 是以 Numpy 為基礎的. 進入 IDLE 介面匯入 numpy 果然出現與上面相同的錯誤訊息, 匯入 pandas 也是一樣. 

以 "Original error was: libf77blas.so.3" 搜尋, 在下面這篇文章找到解決辦法 :

 
原來只要用下列指令安裝 libatlas-base-dev 即可 : 

sudo apt-get install libatlas-base-dev

pi@raspberrypi:~ $ sudo apt-get install libatlas-base-dev    
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
下列的額外套件將被安裝:
  libatlas3-base
建議套件:
  libatlas-doc liblapack-doc
下列【新】套件將會被安裝:
  libatlas-base-dev libatlas3-base
升級 0 個,新安裝 2 個,移除 0 個,有 0 個未被升級。
需要下載 5,365 kB 的套件檔。
此操作完成之後,會多佔用 32.1 MB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] Y
下載:1 http://mirror.ossplanet.net/raspbian/raspbian buster/main armhf libatlas3-base armhf 3.10.3-8+rpi1 [2,399 kB]
下載:2 http://mirror.ossplanet.net/raspbian/raspbian buster/main armhf libatlas-base-dev armhf 3.10.3-8+rpi1 [2,966 kB]
取得 5,365 kB 用了 6s (902 kB/s)
選取了原先未選的套件 libatlas3-base:armhf。
(讀取資料庫 ... 目前共安裝了 168524 個檔案和目錄。)
正在準備解包 .../libatlas3-base_3.10.3-8+rpi1_armhf.deb……
Unpacking libatlas3-base:armhf (3.10.3-8+rpi1) ...
選取了原先未選的套件 libatlas-base-dev:armhf。
正在準備解包 .../libatlas-base-dev_3.10.3-8+rpi1_armhf.deb……
Unpacking libatlas-base-dev:armhf (3.10.3-8+rpi1) ...
設定 libatlas3-base:armhf (3.10.3-8+rpi1) ...
update-alternatives: 在自動模式下以 /usr/lib/arm-linux-gnueabihf/atlas/libblas.so.3 來提供 /usr/lib/arm-linux-gnueabihf/libblas.so.3 (libblas.so.3-arm-linux-gnueabihf)
update-alternatives: 在自動模式下以 /usr/lib/arm-linux-gnueabihf/atlas/liblapack.so.3 來提供 /usr/lib/arm-linux-gnueabihf/liblapack.so.3 (liblapack.so.3-arm-linux-gnueabihf)
設定 libatlas-base-dev:armhf (3.10.3-8+rpi1) ...
update-alternatives: 在自動模式下以 /usr/lib/arm-linux-gnueabihf/atlas/libblas.so 來提供 /usr/lib/arm-linux-gnueabihf/libblas.so (libblas.so-arm-linux-gnueabihf)
update-alternatives: 在自動模式下以 /usr/lib/arm-linux-gnueabihf/atlas/liblapack.so 來提供 /usr/lib/arm-linux-gnueabihf/liblapack.so (liblapack.so-arm-linux-gnueabihf)
執行 libc-bin (2.28-10+rpi1) 的觸發程式……

經過這樣處理後就能順利匯入 Numpy 與 Pamdas 了 :

pi@raspberrypi:~ $ python3    
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np    
>>> np.__version__    
'1.20.3'
>>> import pandas as pd   
>>> pd.__version__    
'1.2.4'

但再次執行爬蟲程式還是失敗, 因為爬蟲程式裡面用到了中文字型 "微軟正黑體", 而樹莓派預設並未支援此字型 : 

pi@raspberrypi:~ $ python3 btc_eth_prices_line_notify.py    
Unable to init server: Could not connect: Connection refused
Unable to init server: 無法連接:Connection refused

(btc_eth_prices_line_notify.py:10639): Gdk-CRITICAL **: 20:43:38.213: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

(btc_eth_prices_line_notify.py:10639): Gdk-CRITICAL **: 20:43:38.228: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
/usr/lib/python3/dist-packages/matplotlib/font_manager.py:1241: UserWarning: findfont: Font family ['Microsoft JhengHei'] not found. Falling back to DejaVu Sans.
  (prop.get_family(), self.defaultFamily[fontext]))

但我參考之前的文章要做字型設定時卻發現 matplotlib 似乎版本太舊, 找不到預期之字型資料夾, 所以乾脆用 pip3 install matplotlib -U 指令將 Matplotlib 版本升級到最新, 然後就可以依照之前的文章上傳並設定微軟正黑體 : 


Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib  
>>> matplotlib.__version__    
'3.5.2'   

這樣就可以順利在樹莓派用 Matplotlib 繪製含有中文的圖形了.

沒有留言 :