Skip to main content

Run a subprocess in a different conda environment.

Project description

conda subprocess

Run a subprocess in a different conda environment.

Example

Create a new conda environment - in this example a conda environment for Python 3.12:

conda create -n py312 python=3.12 

Open a python shell in your base environment where conda_subprocess is installed and execute python --version in the py312 environment:

from conda_subprocess import check_output
check_output("python --version", prefix_name="py312")
>>> b'Python 3.12.1\n'

Alternatively, the environment can be specified with the absolute path:

from conda_subprocess import check_output
check_output("python --version", prefix_path="/Users/janssen/mambaforge/envs/py312")
>>> b'Python 3.12.1\n'

As expected the process for the arguments for the subprocess call can also be defined as list:

from conda_subprocess import check_output
check_output(["python", "--version"], prefix_path="/Users/janssen/mambaforge/envs/py312")
>>> b'Python 3.12.1\n'

In addition to the check_output() function also the check_call() function is implemented:

from conda_subprocess import check_call
check_call("python --version", prefix_name="py312")
>>> Python 3.12.1
>>> 0

As well as the call() function:

from conda_subprocess import call
call("python --version", prefix_name="py312")
>>> Python 3.12.1
>>> 0

And the run() function:

from conda_subprocess import run
run("python --version", prefix_name="py312")
>>> Python 3.12.1
>>> CompletedProcess(args=['/bin/bash', '/var/folders/9p/rztyv06d0xv4h26cyv8nrw3m0000gq/T/tmpm8b8i0r3'], returncode=0)

As the CompletedProcess arguments illustrate conda_subprocess is internally writing the commands to a temporary file for execution, to guarantee the conda environment is correctly activated.

For interactive communication conda_subprocess implements the Popen interface:

from subprocess import PIPE
from conda_subprocess import Popen
process = Popen(["python", "--version"], stdout=PIPE, prefix_name="py312")
process.communicate()
>>> (b'Python 3.12.1\n', None)

Remarks

  • The shell parameter and the env parameter are not supported in Popen() and all derived methods.
  • The pipesize parameter and the process_group parameter were removed for compatibility with python 3.9.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conda_subprocess-0.0.3.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

conda_subprocess-0.0.3-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file conda_subprocess-0.0.3.tar.gz.

File metadata

  • Download URL: conda_subprocess-0.0.3.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for conda_subprocess-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4df5fa27a727696e69a5e8349f73f90e5be440891dd28be1cd3cb6e9c62ce23a
MD5 87940a3762a76992d2eaccdab25797a5
BLAKE2b-256 1efe5b2a0e92ed8324f3752867a88fb1dbc2c20fcdeab7bdac3c31d3670e8390

See more details on using hashes here.

File details

Details for the file conda_subprocess-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for conda_subprocess-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 751f4feabdf6ab48727a2c9bb2873f37ddfb175a595e9603e8e21e939abccf99
MD5 4a3d55da6695c997eeaf45868acea231
BLAKE2b-256 9c269a1c48f2ebc5c94f850ba1528a999133356e272c62389df125723bfae11f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page