Now that yum can be used, IBM i can easily create various open source execution environments, not limited to Python. Please refer to the article here (Using yum with IBM i) for the procedure to install yum in advance.
Python2 is installed with yum when it is installed, so from here on, we will set up the environment for Python3.
You can use the ACS GUI or the SSH CLI to install Python3.
Start ACS and open Open Source Package Management from the Tools menu. Specify the System to install Python3 and USRPRF and click [OK] to proceed. You can see a list of available packages on the Available packages tab. It seems that Python3 packages are being added from time to time. First, I selected two packages ** python3 ** and ** python3-pip ** and pressed the [install] button. A separate window will open and the ** yum install ** command will be executed. You can see that another package with a dependency is also selected at the same time. Run the installation with ** y **. Confirm that the installation is complete. You can easily introduce Python with the ACS GUI. If you have other required packages, you can install them by the same procedure.
Not only can you use the ACS GUI, but you can of course operate with the SSH client CLI as you would with Linux. Connect to ibmi with an SSH terminal.
$ ssh user@ibmi
Use bash.
$ bash
Check python3 related packages.
bash-4.4$ yum list | grep python3
python3.ppc64 3.6.9-1 @ibm
python3-pip.noarch 9.0.1-2 @ibm
python3-setuptools.noarch 36.0.1-2 @ibm
python3-wheel.noarch 0.29.0-2 @ibm
python3-Pillow.ppc64 5.0.0-4 ibm
python3-asn1crypto.noarch 0.24.0-0 ibm
python3-bcrypt.ppc64 3.1.4-5 ibm
python3-cffi.ppc64 1.11.5-2 ibm
python3-cryptography.ppc64 2.2.2-4 ibm
python3-dateutil.noarch 2.7.5-0 ibm
python3-devel.ppc64 3.6.9-1 ibm
python3-ibm_db.ppc64 2.0.5.9-0 ibm
python3-idna.noarch 2.8-0 ibm
python3-itoolkit.ppc64 1.6.1-0 ibm
python3-lxml.ppc64 4.2.1-3 ibm
python3-numpy.ppc64 1.15.4-0 ibm
python3-pandas.ppc64 0.22.0-4 ibm
python3-psutil.ppc64 5.5.1-0 ibm
python3-pycparser.ppc64 2.19-1 ibm
python3-pynacl.ppc64 1.2.1-3 ibm
python3-pytz.noarch 2018.5-2 ibm
python3-pyzmq.ppc64 17.1.2-0 ibm
python3-rpm.ppc64 4.13.0.1-17 ibm
python3-scikit-learn.ppc64 0.19.1-6 ibm
python3-scipy.ppc64 1.1.0-0 ibm
python3-six.noarch 1.10.0-0 ibm
python3-tkinter.ppc64 3.6.9-1 ibm
Let's introduce additional numpy and pandas.
bash-4.4$ yum install python3-numpy python3-pandas
Setting up Install Process
(Omission)
===================================================================================================================
Package Arch Version Repository Size
===================================================================================================================
Installing:
python3-numpy ppc64 1.15.4-0 ibm 6.3 M
python3-pandas ppc64 0.22.0-4 ibm 20 M
Installing for dependencies:
libblas3 ppc64 3.8.0-0 ibm 173 k
libcblas3 ppc64 3.8.0-0 ibm 49 k
libgcc-aix fat 6.3.0-24 ibm 472 k
libgfortran3 ppc64 6.3.0-24 ibm 1.0 M
liblapack3 ppc64 3.8.0-0 ibm 3.4 M
Transaction Summary
===================================================================================================================
Install 7 Packages
Total download size: 31 M
Installed size: 147 M
Is this ok [y/N]: y
(Omission)
Installed:
python3-numpy.ppc64 0:1.15.4-0 python3-pandas.ppc64 0:0.22.0-4
Dependency Installed:
libblas3.ppc64 0:3.8.0-0 libcblas3.ppc64 0:3.8.0-0 libgcc-aix.fat 0:6.3.0-24 libgfortran3.ppc64 0:6.3.0-24
liblapack3.ppc64 0:3.8.0-0
Complete!
I could easily add it with the yum command. With an SSH client, you can manage an open source environment with the yum command without being aware that it is IBM i.
Try launching Python 3 with the ssh client.
bash-4.4$ python3
Python 3.6.9 (default, Oct 31 2019, 11:30:53)
[GCC 6.3.0] on aix7
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/QOpenSys/pkgs/lib/python3.6/site-packages/pandas/__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['pytz', 'dateutil']
When I imported ** pandas **, I got an error saying that ** pytz ** and ** dateutil ** are missing. Since it is Python, I will consider adding it with pip, but in IBM i, it may be provided as a yum package, so check yum first.
>>> exit()
bash-4.4$ yum list | grep python3
(Omission)
python3-dateutil.noarch 2.7.5-0 ibm
(Omission)
python3-pytz.noarch 2018.5-2 ibm
Both were in yum, so install with yum.
bash-4.4$ yum install python3-dateutil python3-pytz
Start Python3 again and try importing pandas.
bash-4.4$ python3
Python 3.6.9 (default, Oct 31 2019, 11:30:53)
[GCC 6.3.0] on aix7
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pandas as pd
>>> data = pd.Series([1.0, 2.4, 5.3, 7], index=['a', 'b', 'c', 'd'])
>>> data
a 1.0
b 2.4
c 5.3
d 7.0
dtype: float64
>>> exit()
You now have a Python 3 execution environment on IBM i.
With IBM i, you can easily prepare your Python environment. Since it supports yum, it can basically be managed by CLI, but it seems to be IBM i that ACS also provides a GUI interface. You can run Python on a PC, but if you set up IBM i as a Python environment, it will be easier to handle IBM i data, and it will be easier for team development.
In the method of this article, the execution environment of Python3 is created in the root environment, but if you use chroot, you can virtualize the environment like a container, so you can choose the combination of packages according to your purpose and clean the root environment. You can also take advantage of open source while preserving it.
Next time, I would like to run jupyter notebook after creating a virtual environment using chroot.
Recommended Posts