[Day#1b PyATS Series] Step-by-Step: Install pyATS in PyCharm (Ubuntu) [Python for Network Engineer]

[Day#1b PyATS Series] Step-by-Step: Install pyATS in PyCharm (Ubuntu) [Python for Network Engineer]

If you’re exploring Python for Network Engineers, mastering tools like pyATS is a game-changer for automating network testing and validation. This guide walks you through setting up pyATS in PyCharm on Ubuntu, step by step, so you can build robust network automation workflows with confidence. Whether you’re a beginner in network automation or a seasoned engineer transitioning to Python, this tutorial will help you streamline device testing, configuration validation, and multi-vendor network operations using Cisco’s pyATS framework.


Prerequisites

  1. Python 3.8–3.11 installed (check with python3 --version)
  2. PyCharm installed
  3. pip and venv installed:
sudo apt update
sudo apt install python3-pip python3-venv

Step 1: Create a Virtual Environment

  1. Open a terminal.
  2. Create a venv for your PyCharm project:
sudo su
mkdir ~/pyats_project
cd ~/pyats_project

apt install python3.10-venv
python3 -m venv venv
  1. Activate it:
source venv/bin/activate
  1. Upgrade pip:
pip install --upgrade pip

Step 2: Install pyATS (full version)

Install pyATS and Genie:

pip install pyats[full]

Verify:

pyats version check

Expected output:

pyATS 23.x
Genie 23.x

Step 3: Set Interpreter in PyCharm

  1. Open PyCharm → File → New Project → Python
  2. Select:
    “Existing Interpreter”
    Point to:
    ~/pyats_project/venv/bin/python
    or
    ~/pyats_project/
  3. Click Create from Existing Sources > New Window

Alternatively, on your Pycharm (Ubuntu) > File > Settings > Project Interpreter > Click “+” > Install “pyATS” as shown below:


Step 4: Create pyATS Test Files

testbed.yml

testbed:
name: my_testbed
devices:
R01:
os: iosxe
type: router
connections:
defaults:
class: unicon.Unicon
cli:
protocol: ssh
ip: 192.168.1.1
credentials:
default:
username: admin
password: cisco

ping_test.py

from pyats.topology import loader
import os

# Load testbed
testbed = loader.load('testbed.yml')

# Clean up old known_hosts entries
for dev in testbed.devices.values():
    ip = dev.connections['cli']['ip']
    os.system(f'ssh-keygen -f "~/.ssh/known_hosts" -R "{ip}"')

# Proceed with connection
device = testbed.devices['R01']
device.connect()

# Ping test
result = device.ping('8.8.8.8')
print("Ping result:", result)

device.disconnect()

Explanation:

StepDescription
1Loads the testbed.yml file which defines the devices and their access info.
2Iterates over all devices in the testbed, extracts the SSH IP, and removes any stale/changed SSH keys using ssh-keygen.
3Connects to R01 using Unicon/pyATS.
4Runs a ping test from the device to a public IP (8.8.8.8).
5Cleanly disconnects the session.

Step 5: Run the Script

  • Right-click ping_test.py → Run
  • Or open PyCharm terminal and activate venv:
source venv/bin/activate
python ping_test.py

Bonus: Run pyATS CLI

In PyCharm terminal:

pyats learn interface --testbed-file testbed.yml

FAQs

1. What are the prerequisites for installing pyATS in PyCharm on Ubuntu?

You need Python 3.6 or higher, a stable internet connection, and an updated Ubuntu system. PyCharm (Community or Professional) should be installed. It’s also recommended to have pip and virtualenv installed before starting.


2. Do I need a virtual environment for pyATS installation?

Yes, creating a virtual environment isolates your pyATS installation and prevents conflicts with other Python packages. In PyCharm, you can easily set up a virtual environment during project creation.


3. How do I install pyATS via PyCharm’s terminal?

Open the terminal inside PyCharm and run:

pip install pyats[full]

This installs the full pyATS suite, including Genie parsers, job libraries, and topology utilities.


4. How can I verify if pyATS is installed correctly?

After installation, run:

pyats version check

You should see version information confirming successful installation.


5. What additional packages are recommended with pyATS?

You might want to install genie, unicon, and pyats.contrib to enhance functionality. These support device connections, parsing outputs, and vendor-agnostic testing.


6. Does pyATS work only on Cisco devices?

No. While developed by Cisco, pyATS supports multi-vendor automation. You can use it with Arista, Palo Alto, Fortinet, Juniper, and others via Genie and custom parsers.


7. How do I configure PyCharm to use the pyATS virtual environment?

Navigate to Settings → Project Interpreter in PyCharm and select the virtual environment where pyATS is installed. This ensures all scripts run with the correct interpreter.


8. Can I use pyATS scripts in a CI/CD pipeline after installing in PyCharm?

Yes. Once you develop and test scripts locally in PyCharm, you can integrate them into Jenkins, GitHub Actions, or other CI/CD tools for automated network testing.


YouTube Link

Watch the Complete Python for Network Engineer: Step-by-Step: Install pyATS in PyCharm (Ubuntu) [Python for Network Engineer] Lab Demo & Explanation on our channel:

Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Master Python Network Automation, Ansible, REST API & Cisco DevNet
Why Robot Framework for Network Automation?

Join Our Training

Learning how to build pyATS testscripts is just the beginning. To become proficient in Python for Network Engineer automation, you need structured guidance and real-world practice.

Trainer Sagar Dhawan offers a 3-month instructor-led training covering Python, Ansible, API integrations, and Cisco DevNet skills. This program is designed for network engineers who want to master automation tools and advance their careers.

Join the training here and take your first step towards becoming a network automation expert.

Enroll Now & Future‑Proof Your Career
Emailinfo@networkjourney.com
WhatsApp / Call: +91 97395 21088


Dhawan Sagar

Hi all,
Good to see you here.
I'm your Trainer for CCIE, CCNP, CCNA, Firewall batches and many more courses coming up!
Stay tuned for latest updates!
Keep me posted over Whatsapp/Email about your experience learning from us.
Thanks for being part of - "Network Journey - A journey towards packet-life!!!"