I would like to create a process which runs PyPy. I tried the following and it works:
import os
os.chdir('<path-to-pypy-download>/bin/')
os.execl('pypy', 'pypy', '-c', 'print "Hi!"')
However, when I remove the chdir
as:
import os
os.execl('<path-to-pypy-download>/bin/pypy', 'pypy', '-c', 'print "Hi!"')
I get:
debug: WARNING: Library path not found, using compiled-in sys.path.
debug: WARNING: 'sys.prefix' will not be set.
debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
debug: WARNING: It is ok to create a symlink to it from somewhere else.
debug: OperationError:
debug: operror-type: ImportError
debug: operror-value: No module named os
Please, does anyone know how to spawn a PyPy process without changing the working directory?
This may not be correct (in which case I'll delete it), but I'm pretty sure that all you need to do is:
In other words, pass the full path for
arg0
as well aspath
.Why? Well, when PyPy starts up, it's got to be using (the RPython/compiled-to-C equivalent of)
sys.argv[0]
to find the path to a custom stdlib. What else could it use? Which is of course just copied from thechar *argv[]
argument passed to the interpreter'smain
function. When you let the OS launch a program for you, it will put the full path in there. But when you explicitly set it withexecl
, it will just copy whatever you gave it.It's actually a bit more complicated than this—it does a
readlink
(to allow symlinks) and anabspath
(to allow itself to be run by relative path—as in your first example). But the basic idea is the same.As a side note, you might want to consider using a fully-installed PyPy instead of a run-out-of-build-tree PyPy, in which case its
sys.prefix
will be set up properly so it won't need this.