【CentOS8】に【Python】のライブラリを追加して実行する方法

CentOS8にPythonのライブラリを追加して実行する方法

Gitでリポジトリの情報確認

$ git remote -v
origin  https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/chart_analytics (fetch)
origin  https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/chart_analytics (push)

 

Pythonプログラムの実行

$ python3 chart_05.py
Traceback (most recent call last):
  File "chart_05.py", line 2, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

pandasが入ってないのでインストールします。  

pipインストール

$ pip
bash: pip: command not found

その前にpipが入ってないのでインストールします。

$ yum -y install pip
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 1:21:34 ago on Fri Apr  2 06:00:12 2021.
No match for argument: pip
Error: Unable to find a match: pip
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

 

pandasインストール

$ pip3 install pandas
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead.
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/c3/e2/00cacecafbab071c787019f00ad84ca3185952f6bb9bca9550ed83870d4d/pandas-1.1.5-cp36-cp36m-manylinux1_x86_64.whl (9.5MB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 9.5MB 213kB/s
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.6/site-packages (from pandas)
Collecting numpy>=1.15.4 (from pandas)
  Downloading https://files.pythonhosted.org/packages/45/b2/6c7545bb7a38754d63048c7696804a0d947328125d81bf12beaa692c3ae3/numpy-1.19.5-cp36-cp36m-manylinux1_x86_64.whl (13.4MB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 13.4MB 149kB/s
Collecting pytz>=2017.2 (from pandas)
  Downloading https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 512kB 3.4MB/s
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/site-packages (from python-dateutil>=2.7.3->pandas)
Installing collected packages: numpy, pytz, pandas
Successfully installed numpy-1.19.5 pandas-1.1.5 pytz-2021.1

 

Pythonプログラムの再度実行

$ python3 chart_05.py
Traceback (most recent call last):
  File "chart_05.py", line 3, in <module>
    import matplotlib as mpl
ModuleNotFoundError: No module named 'matplotlib'

matplotlibが入ってないのでインストールします。  

matplotlibインストール

$ pip3 install matplotlib
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead.
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/09/03/b7b30fa81cb687d1178e085d0f01111ceaea3bf81f9330c937fb6f6c8ca0/matplotlib-3.3.4-cp36-cp36m-manylinux1_x86_64.whl (11.5MB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 11.5MB 178kB/s
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl (67kB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 71kB 10.9MB/s
Collecting cycler>=0.10 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/a7/1b/cbd8ae738719b5f41592a12057ef5442e2ed5f5cb5451f8fc7e9f8875a1a/kiwisolver-1.3.1-cp36-cp36m-manylinux1_x86_64.whl (1.1MB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 1.1MB 1.6MB/s
Requirement already satisfied: numpy>=1.15 in /usr/local/lib64/python3.6/site-packages (from matplotlib)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/site-packages (from matplotlib)
Collecting pillow>=6.2.0 (from matplotlib)
  Downloading https://files.pythonhosted.org/packages/89/d2/942af29f8494a1a3f4bc4f483d520f7c02ccae677f5f50cf76c6b3d827d8/Pillow-8.2.0-cp36-cp36m-manylinux1_x86_64.whl (3.0MB)
    100% |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 3.0MB 668kB/s
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from cycler>=0.10->matplotlib)
Installing collected packages: pyparsing, cycler, kiwisolver, pillow, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-3.3.4 pillow-8.2.0 pyparsing-2.4.7

 

Pythonプログラムの再々実行

$ python3 chart_05.py
Traceback (most recent call last):
  File "chart_05.py", line 6, in <module>
    import mpl_finance as mpf
ModuleNotFoundError: No module named 'mpl_finance'

mpl_financeが入ってないのでインストールします。  

mpl_financeインストール

$ pip3 install mpl_finance
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead.
Collecting mpl_finance
  Downloading https://files.pythonhosted.org/packages/9d/de/8169ea4403d6cb8322e74cc48b6834d1dfbed81931d17f1f26b2140160d8/mpl_finance-0.10.1-py3-none-any.whl
Requirement already satisfied: matplotlib in /usr/local/lib64/python3.6/site-packages (from mpl_finance)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib64/python3.6/site-packages (from matplotlib->mpl_finance)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.6/site-packages (from matplotlib->mpl_finance)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib64/python3.6/site-packages (from matplotlib->mpl_finance)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/site-packages (from matplotlib->mpl_finance)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/site-packages (from matplotlib->mpl_finance)
Requirement already satisfied: numpy>=1.15 in /usr/local/lib64/python3.6/site-packages (from matplotlib->mpl_finance)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/site-packages (from python-dateutil>=2.1->matplotlib->mpl_finance)
Installing collected packages: mpl-finance
Successfully installed mpl-finance-0.10.1

 

Pythonプログラムの再々々実行

$ python3 chart_05.py
/usr/local/lib/python3.6/site-packages/mpl_finance.py:22: DeprecationWarning:

  =================================================================

   WARNING: mpl_finance is deprecated:

    Please use mplfinance instead (no hyphen, no underscore).

    To install: pip install --upgrade mplfinance

   For more information, see: https://pypi.org/project/mplfinance/

  =================================================================

  category=DeprecationWarning)
Traceback (most recent call last):
  File "chart_05.py", line 73, in <module>
    cf = myf.get_config()
  File "/var/www/tmp/chart_analytics/lib/my_function.py", line 547, in get_config
    with open(conf_file, 'r') as config:
FileNotFoundError: [Errno 2] No such file or directory: '../../../source/repos/chart_gallery/stock_data/nikkei_225.csv'

パスの実行エラーは出ますが、ライブラリの不足は解消しました。