Is there a command line flag for installing PYTHONHOME?

I am trying to run python on a system that does not allow me to set environment variables. Is there a command line flag for python that will install PYTHONHOME? I looked here: http://docs.python.org/release/2.3.5/inst/search-path.html but did not see anything.

So hopefully something like this:

python -magical_path_flag /my/python/install test.py

EDIT

Thanks for all the answers. I am embarrassed to say that I actually meant PYTHONHOME, not PYTHONPATH. (This is what I deserve to ask a question at 1:30 in the morning.) I edited my quesiton.

Here is some more information. I am trying to run python on Android. I can run python -V without problems, but if I try to execute the script, I get:

I/ControlActivity(18340): Could not find platform independent libraries <prefix>
I/ControlActivity(18340): Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]

Unfortunately, when using ProcessBuilder and changing environment variables on Android, it says that they do not change and throw an exception. I can pass all the command line flags that I want, so I was hoping I could set PYTHONHOME that way.

I tried to create a shell script shell that exports PYTHONHOME and then calls python, but that didn't work. (Received the same error as before.)

Thank,

Gabe

+3
source share
3 answers

You can simply install it in your script - sys.paththis is a regular, mutable list. Sort of:

import sys
sys.path.append("/path/to/libraries")

gotta do the trick

+5
source

In UNIXy shells, you can set the environment variable only for the duration of one command by adding a command with setting the environment variable:

$ PYTHONPATH=/my/python/install python test.py
+2

If none of the other answers suits you, you can write a script wrapper that temporarily sets the environment variable and then runs another script. For instance:

python mywrapper.py -magical_path_flag /my/python/install test.py
0
source

Source: https://habr.com/ru/post/1782884/


All Articles