0

I need to use an conda environment to execute python files (because of lack of privileges and constraints set by the server admin). So currently I do the following to activate the environment:

subprocess.check_output('source activate rgi_run', shell=True)

And then run my script using an other suprocess call using shell = True.

However I have only read "negative" things about using shell = True, especially the security reasons (e.g.: Actual meaning of 'shell=True' in subprocess). So I'm wondering if there are other options to do this, if not are there even security reasons when running this on a private in-house server?

CodeNoob
  • 1,988
  • 1
  • 11
  • 33
  • related: [Calling the "source" command from subprocess.Popen](https://stackoverflow.com/q/7040592/4279) – jfs Oct 10 '17 at 20:59
  • If you have to `source` something to set up an environment, you have to do it before you run Python. You can't run it in a subprocess and then expect it to affect the rest of the script. – that other guy Oct 10 '17 at 21:48

1 Answers1

0

There are two other options: 1 is a workaround, 2 will be the final solution available in conda 4.6.

  1. conda-wrappers Guilherme Melo created a wrappers for the python executables within a conda environment. If you set it as the python interpreter in your IDE, e.g. PyCharm, it will activate the conda environment from which it is called, and then call the python interpreter. Look here under section "Creating conda wrappers": https://pypi.org/project/exec-wrappers/

  2. conda run A long discussion on the conda github page on a standard and fast way to execute a command inside an environment led to the implementation of a new command (actually a re-invocation as it was available before): conda run

It is described in issue #7320 and will be released in conda-4.6 hopefully in October 2018!

Agile Bean
  • 6,437
  • 1
  • 45
  • 53