How to set python path when run with rc.local?

Hi, i want to start my project when i boot my jetson.

without rc.local, python version is 3.6.9.
but with rc.local, python version is 2.7.17

so i want to set my python path(3.6.9) when i boot my jetson.
How can i set??

I don’t do much with Python, but typically you can explore like this:

  • which python
  • which python2
  • which python3
  • ls -l /usr/bin/python*

You’re most likely interested in “python3”, not the more detailed “patch level” versions. Simply name this full path when you start your application. Example if app is

However, that just says to use Python3. “PYTHON_PATH” can be used as well, and this is setting up the Python interpreter to be able to find Python modules. This has some defaults when a regular user starts a Python program, but might not be added for the system itself launching a Python program in “rc.local”. The result of missing something in PYTHON_PATH would be a module include failing to find the module.

An example of some system content which would normally be available, but might be missing from the environment early on, would be the path “/usr/lib/python3.6”. I don’t know if that is actually missing, perhaps it is there and you are missing a path to some custom module…in that case you’d add the custom module path, but I’ll just illustrate with the “/usr/lib/python3.6” content, which goes something like this for your command line:

PYTHON_PATH=$PYTHON_PATH:/usr/lib/python3.6 /usr/bin/python3

What that does is append “/usr/lib/python3.6” to whatever the current PYTHON_PATH is. If you run this and it is missing availability of a module, then just find out where that module is and append that location to your PYTHON_PATH.

I’ll make one more adjustment because the actual Python program you start from “/etc/rc.local” should always be named with a full path, and not just left to defaults, and assumes is in “/usr/local/bin” (at “/usr/local/bin/”):

PYTHON_PATH=$PYTHON_PATH:/usr/lib/python3.6 /usr/bin/python3 /usr/local/bin/

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.