NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set python2.7 as the default interpreter instead of python3.5 in Linux RT Communications 3.1ython2.7

I need to use python2.7 as the default python interpreter for building an application in NI Linux RT Comms. but the default python version is set as 3.5. How do I change it? Any suggestions? Thanks in advance

0 Kudos
Message 1 of 2
(1,959 Views)

Hi Anshumanms,

 

python on NI Linux Real-Time will (in general) work the same as on any other Linux system. The "python" command will be linked to a specific version of python and changing that can impact other system utilities, but other versions of python can live side-by-side and be called explicitly. It's generally a very bad idea to change the default python on a Linux OS.

 

For example, our systems have many utilities that depend on python 3.5 so the "python" command is linked to that. However, you can still install python2.7 and invoke it explicitly using "python2.7" or a similar command. If you want a specific script to run with a different version of python, I'd recommend looking at using shebangs. E.g., looking at putting the following line at the top of your python scripts:

#! /usr/bin/python2.7

When running a script directly (instead of calling "python <script name>"), it will use the python listed there. Note that this won't cover all use cases and does have some drawbacks that I would recommend researching. 

 

Overall, the two things I would recommend you take away:

  • It's generally a very bad idea to change the default python.
  • Linux RT is still just Linux. Most of the discussions and documents online about how to handle this type of situation still apply. 
Charlie J.
National Instruments
0 Kudos
Message 2 of 2
(1,918 Views)