• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Getting Started With Python On IBM i

    June 10, 2019 Stephanie Rabbani

    Python is one of my favorite open-source languages. I’ve used it to build web applications, utilities, and diverse tools such as a web server monitor and an automated application testing suite. In this article, I’ll show you how to install Python on IBM i and create your first program.

    Why Python? For several reasons.

    • You can use Python to do some cool processing on your system. Graphical application development, games, data analysis, and web development are all Python’s strengths.
    • Coding in Python is easy, relatively speaking. The syntax is easy to learn, dropping the formal verbosity found in traditional coding languages.
    • It’s a deeper well for new talent. This means it’s more welcoming to beginners, as indicated by Python’s consistent rank as one of the fastest growing languages.
    • Python unlocks new ways to optimize and streamline workflow and operations, evolving IBM i so it keeps its throne over the next few decades. Open source is the foundation of the cloud computing world; it’s why IBM has embraced open source technologies in its Power roadmap. Modern languages will influence and evolve how your company interacts with its data.

    The Basics Of Python

    Python uses very simple syntax:

    • It uses spacing instead of brackets to denote code blocks, such as if statements and loops.
    • It’s case-sensitive.

    There’s no need to explicitly declare variables. Variables are declared when you assign a value. Values are assigned to variables using a single equal sign (=).

    habs = 24
    

    Python is case-sensitive, so Habs is not the same as habs. Comments are preceded with a hash mark (#) and can follow on the same line of code.

    habs = 24	#number of Stanley cups won by Montreal
    

    Or . . .

    habs = 24
    #number of Stanley cups won by Montreal
    if habs < 25:
    print("they’ve been golfing since 1994")
    if habs > 24:
    print("I'll be old or dead before this is true, so you'll likely never see this message")
    

    Your first Python program can include a built-in Python server.

    run(host='0.0.0.0', port=8228, debug=True, reloader=True)
    

    Setting Up Python On IBM i

    Getting started with Python on IBM i is dead simple. Just follow two simple steps.

    Step 1: Download and install YUM, an open source package manager.

    IBM delivers open source software via YUM, so it’s where you’ll find Python 3 and other open source goodies.

    Download YUM here: https://www-01.ibm.com/support/docview.wss?uid=nas8N1022619. Your system must be at IBM i 7.2 or later.

    Important Note: The most secure, stable way is to run YUM and Python is in SSH. IBM i’s Business Architect of open source technologies, Jesse Gorzinski, explains the fundamentals of shells in this blog post, including how to choose and set your shell.

    It’s also possible to install via QP2TERM().

    Step 2: Install the Python package with YUM

    • From Access Client Solutions, IBM’s free GUI for managing your IBM i:
      • Go to the IBM i Tools menu Open Source Package Management.
        • At this point, a list of currently installed Open Source packages will be displayed. If Python3 isn’t there, click the “Available Packages” tab.
        • If you skipped the first step, clicking Open Source Package Management in the Tools menu will present a message asking if you’d like to install YUM.

     

    • From the Command line it’s as simple as typing:
    yum install python3
    

    Now you can download python packages by pip3 install.

    Python programs are typically .py extensions.

    Optional Step

    If you want to avoid having to specify the full path to Python every time you run it, add /QOpenSys/pkgs/bin to your path.

    You can use this shell command to change the path:

    PATH=/QOpenSys/pkgs/bin:$PATH
    export PATH
    

    Your First Python program

    1. From the 5250 command line, run the Edit File (EDTF) command to open the IFS editor.
    EDTF STMF('/home/steph/hello.py')
    

    From the blank EDTF screen, press F15=Services to go to EDTF Options, where you should change the CCSID of hello.py to 1208 (Unicode), a Python-friendly encoding, as shown below:

    1. On the first line, type the following:
    print("hello world")
    

    Press F3 to save and exit.

    1. CALL QP2TERM or ssh to access PASE, and key the following command to run the Python program.
    python3 /home/steph/hello.py

    An IBM Champion and senior consultant for Seiden Group, Stephanie has developed web applications on the IBM i for over 15 years. Her expertise encompasses PHP, Python, DB2, SQL, RPG, Git, WebSmart, IBM i integration techniques and more. She develops a broad range of applications—shopping carts, ordering, warehousing, dashboards, mobile/responsive applications, Salesforce integration, and more—for small to Fortune 500 companies.

    
    

    RELATED STORIES

    Club-Seiden Python for IBM i Examples

    IBM i Open Source

    IBM i Access Client Solutions

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, FHG, Four Hundred Guru, IBM i, Power Systems, Python, Yum

    Sponsored by
    UCG Technologies

    CYBER-ATTACKS ON THE RISE. PROTECT WITH THE TRIPLE PLAY.

    COVID-19 has not only caused a global pandemic, but has sparked a “cyber pandemic” as well.

    “Cybersecurity experts predict that in 2021, there will be a cyber-attack incident every 11 seconds. This is nearly twice what it was in 2019 (every 19 seconds), and four times the rate five years ago (every 40 seconds in 2016). It is expected that cybercrime will cost the global economy $6.1 trillion annually, making it the third-largest economy in the world, right behind those of the United States and China.”1

    Protecting an organization’s data is not a single-faceted approach, and companies need to do everything they can to both proactively prevent an attempted attack and reactively respond to a successful attack.

    UCG Technologies’ VAULT400 subscription defends IBM i and Intel systems against cyber-attacks through comprehensive protection with the Triple Play Protection – Cloud Backup, DRaaS, & Enterprise Cybersecurity Training.

    Cyber-attacks become more sophisticated every day. The dramatic rise of the remote workforce has accelerated this trend as cyber criminals aggressively target company employees with online social engineering attacks. It is crucial that employees have proper training on what NOT to click on. Cyber threats and social engineering are constantly evolving and UCG’s Enterprise Cybersecurity Training (powered by KnowBe4) is designed to educate employees on the current cutting-edge cyber-attacks and how to reduce and eliminate them.

    A company is only as strong as its weakest link and prevention is just part of the story. Organizations need to have a quick response and actionable plan to implement should their data become compromised. This is the role of cloud backup and disaster-recovery-as-a-service (DRaaS).

    Data is a company’s most valuable asset. UCG’s VAULT400 Cloud Backup provides 256-bit encrypted backups to two (2) remote locations for safe retrieval should a cyber-attack occur. This is a necessary component of any protection strategy. Whether a single click on a malicious link brings down the Windows environment or an infected SQL server feeds the IBM i, once the data is compromised, there is no going back unless you have your data readily available.

    Recovery is not a trivial task, especially when you factor in the time sensitive nature of restoring from an active attack. This leads to the third play of the Triple Play Protection – DRaaS.  Companies have myriad concerns once an attack is realized and a managed service disaster recovery allows employees to keep focus on running the business in a crisis state.

    The combination of training employees with secure backup and disaster recovery offers companies the best chance at avoiding financial disruption in an age of stronger, more frequent cyber-attacks.

    Reach out to UCG Technologies to discuss your company’s security needs and develop a data protection plan that fits you best.

    ucgtechnologies.com/triple-play

     800.211.8798 | info@ucgtechnologies.com

     

    1. https://theconversation.com/cyberattacks-are-on-the-rise-amid-work-from-home-how-to-protect-your-business-151268

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Server Buying Cools, But It’s Cool – Don’t Panic It’s Getting Cloud-i In Here

    6 thoughts on “Guru: Getting Started With Python On IBM i”

    • Mike Krebs says:
      June 10, 2019 at 10:09 am

      The steps 2 and 3 in “your first python program” appear to need lowercase (print instead of Print and python3 instead of Python3). And the EDTF command created the file in CCSID 37 which apparently python3 does not understand directly. In EDTF, I used Services (F15) to change the file CCSID to 1208 (UTF-8) and then I was able to run the program.

      Reply
      • alanseiden says:
        June 19, 2020 at 12:23 pm

        Thanks, Mike! The article has been updated as you suggested, including setting CCSID=1208.

        Reply
    • Mark Soulje says:
      June 10, 2019 at 1:41 pm

      thank you for the article. used this as my excuse to try the Python waters again. don’t know if it’s helpful to anyone else. had to use python3 instead of Python3 and changed the line of code from Print to print to get it to work.

      Reply
      • se yarbrough says:
        January 10, 2020 at 9:32 am

        Great read..thanks for the article..

        Reply
      • alanseiden says:
        June 19, 2020 at 12:24 pm

        Mark, you’re right. Those “P”s have been made lowercase now.

        Reply
    • john says:
      September 25, 2020 at 6:51 am

      What an half baked article is this ?

      yum install python3

      Now you can download python packages by pip3 install.,.. what does this step says.. where to download python3 packages, and where does it go /

      Reply

    Leave a Reply Cancel reply

TFH Volume: 29 Issue: 35

This Issue Sponsored By

  • New Generation Software
  • RPG & DB2 Summit
  • Profound Logic Software
  • ARCAD Software
  • WorksRight Software
  • OCEAN User Group

Table of Contents

  • IBM i Roadmap Promises A Long Ride, Few Bumps
  • It’s Getting Cloud-i In Here
  • Guru: Getting Started With Python On IBM i
  • Server Buying Cools, But It’s Cool – Don’t Panic
  • The Transition To RHEL 8 Begins On Power Systems
  • Situation Wanted: DBCS Conversion Expert For Apps Sold Into Japan

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Why Open Source Is Critical for Digital Transformation
  • mrc Refreshes IBM i Low-Code Dev Tool
  • Unit Testing Automation Hits Shift Left Instead of Ctrl-Alt-Delete Cash
  • Four Hundred Monitor, March 3
  • IBM i PTF Guide, Volume 23, Number 9
  • Doing The Texas Two Step From Power9 To Power10
  • PHP’s Legacy Problem
  • Guru: For IBM i Newcomers, An Access Client Solutions Primer
  • IBM i 7.1 Extended Out To 2024 And Up To The IBM Cloud
  • Some Practical Advice On That HMC-Power9 Impedance Mismatch

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2021 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.