2015 年, IBM 通过发布了特许程序 5733-OPS 和打补丁的方式来支持包括 Python 开发语言在内的开源包,在此之上 IBM i 的客户和 ISV 开发了很多基于 Python 语言的应用程序。为了更方便、更灵活地支持 Python 用户, IBM i 已将 5733-OPS 迁移到 RPMs 方式安装,即用 RPM 安装方式代替了原来传统安装特许程序的方式,这种方式更加接近于开源的世界。
下面将介绍如何在 AS/400 上配置 Python 执行环境。
因为 Python 要在 IBM i 的 PASE 环境下运行,所以需要在安装 Python 之前安装 5770SS1 option 33 and 5733SC1 。
之后来安装 Python 语言包。
第一步 : 安装
通过 ACS (Access Client Solutions)中"Tools" ->"Open Source Package Management" 安装Python 相关的 Open Source 包。
点击“ Install ”进行安装,之后会弹出一个黑色对话框,回答“ Y ”确认安装,继续安装。
当然也可以用 yun install 命令进行安装。
例如:
Package | How to install |
ibm_db | yum install python3-ibm_db |
NumPy | yum install python3-numpy |
SciPy | yum install python3-scipy |
SciKit-Learn | yum install python3-sckikit-learn |
psutil | yum install python3-psutil |
pandas | pip3 install cython pandas |
这里以IBM i python常用python3 、 python3-pip 、 python3-ibm_db 、 python3-itoolkit 包为例进行说明,安装好以后在“ Installed package ”标签项内查看到了这四个包的安装状态,确认它们已被安装成功。
Python3 IBM i Collaboration for Python
Python3-pip PIP is Python installer program
Python3-ibm-db Db2 FOR i connector - allow native access to Db2 for i
Python3-itoolkit Tookit for IBM I - allow access to system resources through program calls
,Cl commands, shell commands and more
临时调整路径方法
在 AS/400 命令行输入 call qp2term 进入 pase 界面,执行下面的两条语句。
PATH = /QOpenSys/pkgs/bin: $PATH
export PATH
检查 Python 的版本
python3 --version
第三步:测试一个小程序
在 AS/400 命令行上输入命令,编辑一个简单的 python 程序。
EDTF STMF('/test/hello.py')
由于 AS/400 的主机代码页采用 EBCDIC 码,不支持 Python ,所以要在程序前面加入 #coding=utf-8 ,将主机代码页强制转换为 utf-8 ,否则执行时会报
“ SyntaxError: Non-UTF-8 code starting with '\x83' in file /test/hello1.py on ine 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ fo details ”错误。
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞2
添加新评论0 条评论