# Error when running a python script

**URL:** <https://root-forum.cern.ch/t/error-when-running-a-python-script/35102>\
**Category:** Newbie\
**Created:** [July 10, 2019, 4:22pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102 "2019-07-10T16:22:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kayshla98](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kayshla98/32/19362_2.png) [@Kayshla98](https://root-forum.cern.ch/u/Kayshla98)\
**Post date:** [July 10, 2019, 4:22pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/1 "2019-07-10T16:22:36Z")

</div>

Hey,

When I try to run a script the following error occurs:  
“ImportError: /work/astropa/sw/veritas/root-cern/build/lib/libPyROOT.so: undefined symbol: PyUnicodeUCS2\_FromString”

Ubuntu 16.04  
Python version 3.6.3  
Root version 6.10  
This is my .bash\_profile:

source /work/astropa/sw/veritas/root-cern/build/bin/thisroot.sh

export PATH=$ROOTSYS/bin:$PYTHONDIR/bin:$PATH

export LD\_LIBRARY\_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD\_LIBRARY\_PATH

export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH

\*I don’t have permission from ROOT. Therefore, I can’t install or change stuff in it.

Would appreciate any help,  
Kayshla

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 10, 2019, 4:27pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/2 "2019-07-10T16:27:14Z")

</div>

Hi,  
welcome to the ROOT forum!

This looks like a python version mismatch between your ROOT installation and the python you are using to run scripts. Can you try running the script with `python2` instead of `python` or `python3`?

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Kayshla98](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kayshla98/32/19362_2.png) [@Kayshla98](https://root-forum.cern.ch/u/Kayshla98)\
**Post date:** [July 10, 2019, 4:45pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/3 "2019-07-10T16:45:18Z")

</div>

I am getting the same error with Python2 and the others as well.  
This would be the complete output when I run the script (if it helps):  
“File “Anderson.py”, line 2, in   
import ROOT  
File “/work/astropa/sw/veritas/root-cern/build/lib/ROOT.py”, line 24, in   
import cppyy  
File “/work/astropa/sw/veritas/root-cern/build/lib/cppyy.py”, line 61, in   
import libPyROOT as \_backend  
ImportError: /work/astropa/sw/veritas/root-cern/build/lib/libPyROOT.so: undefined symbol: PyUnicodeUCS2\_FromString”

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 10, 2019, 4:54pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/4 "2019-07-10T16:54:24Z")

</div>

Uhm are you sure your ROOT installation is meant for your python environment? Are you using the system’s python or did you get python e.g via conda?

Calling in the python experts: @etejedor and @swunsch in case they have seen this before

---

<div class="post-metadata">

**Author:** ![Kayshla98](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kayshla98/32/19362_2.png) [@Kayshla98](https://root-forum.cern.ch/u/Kayshla98)\
**Post date:** [July 10, 2019, 7:31pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/5 "2019-07-10T19:31:11Z")

</div>

Yes, I doubled checked that it was the right environment. And I am using the system’s Python.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [July 11, 2019, 7:56am UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/6 "2019-07-11T07:56:50Z")

</div>

The error you see seems to be related to this issue:

[https://bugs.python.org/issue8654](https://bugs.python.org/issue8654)

Long story short, your Python installation is compiled with 4-byte unicode characters (UCS4) but ROOT was built against a Python installation with 2-byte unicode characters (UCS2). That is why your Python installation does not provide `PyUnicodeUCS2_FromString`.

I see two possible solutions:

- You build ROOT against the UCS4 Python you have in your system (or ask someone that has permissions to do it).
- You install a Python that has UCS2, so that ROOT will find the symbol. It seems the flag is `--enable-unicode=ucs2`.

---

<div class="post-metadata">

**Author:** ![Kayshla98](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kayshla98/32/19362_2.png) [@Kayshla98](https://root-forum.cern.ch/u/Kayshla98)\
**Post date:** [July 12, 2019, 7:26pm UTC](https://root-forum.cern.ch/t/error-when-running-a-python-script/35102/7 "2019-07-12T19:26:11Z")

</div>

Thank you! I appreciate it.
