Hello. I am writing in python 3.4 and flask my own small service with engineering calculations. It took the use of a third-party application GMSH, which starts through pygmsh through the subprocess.

cmd = [gmsh_executable, '-3', filename, '-o', outname] if optimize: cmd += ['-optimize'] out = subprocess.check_output(cmd, stderr=subprocess.STDOUT) 

Given that the web server is working through the www-data user from the virtual environment, I get the error "PermissionError: [Errno 13] Permission denied" when the subprocess calls python 3.4 from the global root-accessible environment.

Tell me, please, how can I run a subprocess through a virtual environment, without going to root? With python for now, unfortunately.

  • show full traceback. What is gmsh_executable ? (if it is a Python script, then show it first line (shebang #! ) What does global environment mean? How does it differ from non-global environment? - jfs
  • It all depends on whether it is possible to pass directly to python in gmsh. See what sys.executable under virtualenv. - Vasily Ryabov

1 answer 1

Try adding the path to Python to virtualenv in the PATH environment variable. Something like this:

 import os env = os.environ.copy() if 'PATH' in env: env['PATH'] = 'Путь до virtualenv/bin:' + env['PATH'] else: env['PATH'] = 'Путь до virtualenv/bin:' cmd = [gmsh_executable, '-3', filename, '-o', outname] if optimize: cmd += ['-optimize'] out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) 

It is possible that in this way it will also be necessary to change the PYTHONPATH and PYTHONHOME environment variables.