# Coloring Python Syntax Inside a Label automatically. (pygments package)

**URL:** <https://forum.inductiveautomation.com/t/coloring-python-syntax-inside-a-label-automatically-pygments-package/23202>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [March 10, 2019, 7:42pm UTC](https://forum.inductiveautomation.com/t/coloring-python-syntax-inside-a-label-automatically-pygments-package/23202 "2019-03-10T19:42:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MicroVAX\_II](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/microvax_ii/32/7319_2.png) [@MicroVAX\_II](https://forum.inductiveautomation.com/u/MicroVAX_II)\
**Post date:** [March 10, 2019, 7:42pm UTC](https://forum.inductiveautomation.com/t/coloring-python-syntax-inside-a-label-automatically-pygments-package/23202/1 "2019-03-10T19:42:42Z")

</div>

Hi,

For training purposes, we would like to color python syntax inside a label. The [pygments python package](http://pygments.org/) would work the best for me.

What are some best methods to import this package into ignition? (Linux and Windows)

 ![pygments%20test](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c0fced5c19ec4edf1297be5c4f346e3300136796.png)

Below is an example on how to use the pygments package.

```auto
# Import packages!
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

# Lets get our python lexer.
lexer = get_lexer_by_name("python", stripall=True)
# Lets setup our Html Formatter.
formatter = HtmlFormatter(linenos=False, noclasses=True, nobackground=True)

# We can read code from any source (file or query...ect.).
code = 'print \'this is a test\''
# Format the python code for HTML
result = highlight(code, lexer, formatter)
# Copy and paste into Ignition Label
print('<HTML>'+result+'</HTML>')

```

RESULT (Can be copied and pasted into an ignition object to color syntax)

```auto
<HTML><div class="highlight"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">&#39;this is a test&#39;</span>
</pre></div>
</HTML>

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 10, 2019, 8:02pm UTC](https://forum.inductiveautomation.com/t/coloring-python-syntax-inside-a-label-automatically-pygments-package/23202/2 "2019-03-10T20:02:47Z")

</div>

After a brief look in its source, I didn’t see any obvious gotchas. Try placing its code in your ignition install’s pylib folder and restart the service. Then try to import it in a console. If it uses anything specfic to python 2.7, you’ll have to wait for Ignition v8.

---

<div class="post-metadata">

**Author:** ![MicroVAX\_II](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/microvax_ii/32/7319_2.png) [@MicroVAX\_II](https://forum.inductiveautomation.com/u/MicroVAX_II)\
**Post date:** [March 10, 2019, 8:36pm UTC](https://forum.inductiveautomation.com/t/coloring-python-syntax-inside-a-label-automatically-pygments-package/23202/3 "2019-03-10T20:36:23Z")

</div>

> [@pturmel](#):
>
> pylib

Thanks for the help! The windows directory is easy to find but I want to make sure it is pointing at /var/lib/ignition/user-lib/pylib. Like these two directories are equal?

(windows)  
C:\Program Files\Inductive Automation\Ignition\user-lib\pylib  
(linux)  
/var/lib/ignition/user-lib/pylib

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 11, 2019, 1:49am UTC](https://forum.inductiveautomation.com/t/coloring-python-syntax-inside-a-label-automatically-pygments-package/23202/4 "2019-03-11T01:49:32Z")

</div>

Yes, that’s the right location in either case. (It can be different on linux, too, if someone does a manual install from the zip file.)
