diff --git a/apis/python/node/README.md b/apis/python/node/README.md index 408cd83c..5909eebe 100644 --- a/apis/python/node/README.md +++ b/apis/python/node/README.md @@ -4,9 +4,9 @@ This crate corresponds to the Node API for Dora. To build the Python module for development: -````bash -python3 -m venv .env +```bash +python -m venv .env source .env/bin/activate pip install maturin maturin develop -```` +``` diff --git a/binaries/cli/src/template/python/dataflow-template.yml b/binaries/cli/src/template/python/dataflow-template.yml index 3e7ed02c..2bebbc6f 100644 --- a/binaries/cli/src/template/python/dataflow-template.yml +++ b/binaries/cli/src/template/python/dataflow-template.yml @@ -16,7 +16,7 @@ nodes: - id: custom-node_1 custom: - source: python3 + source: python args: ./node_1/node_1.py inputs: tick: dora/timer/secs/1 diff --git a/examples/python-dataflow/run.rs b/examples/python-dataflow/run.rs index e33100b8..49721eb4 100644 --- a/examples/python-dataflow/run.rs +++ b/examples/python-dataflow/run.rs @@ -1,3 +1,4 @@ +use dora_core::get_python_path; use eyre::{ContextCompat, WrapErr}; use std::path::Path; use tracing_subscriber::{ @@ -14,9 +15,20 @@ async fn main() -> eyre::Result<()> { std::env::set_current_dir(root.join(file!()).parent().unwrap()) .wrap_err("failed to set working dir")?; - run(&["python3", "-m", "venv", "../.env"], None) - .await - .context("failed to create venv")?; + run( + &[ + get_python_path() + .context("Could not get python binary")? + .to_str() + .context("Could not convert python path to string")?, + "-m", + "venv", + "../.env", + ], + None, + ) + .await + .context("failed to create venv")?; let venv = &root.join("examples").join(".env"); std::env::set_var( "VIRTUAL_ENV", diff --git a/examples/python-operator-dataflow/run.rs b/examples/python-operator-dataflow/run.rs index e33100b8..49721eb4 100644 --- a/examples/python-operator-dataflow/run.rs +++ b/examples/python-operator-dataflow/run.rs @@ -1,3 +1,4 @@ +use dora_core::get_python_path; use eyre::{ContextCompat, WrapErr}; use std::path::Path; use tracing_subscriber::{ @@ -14,9 +15,20 @@ async fn main() -> eyre::Result<()> { std::env::set_current_dir(root.join(file!()).parent().unwrap()) .wrap_err("failed to set working dir")?; - run(&["python3", "-m", "venv", "../.env"], None) - .await - .context("failed to create venv")?; + run( + &[ + get_python_path() + .context("Could not get python binary")? + .to_str() + .context("Could not convert python path to string")?, + "-m", + "venv", + "../.env", + ], + None, + ) + .await + .context("failed to create venv")?; let venv = &root.join("examples").join(".env"); std::env::set_var( "VIRTUAL_ENV", diff --git a/examples/python-ros2-dataflow/run.rs b/examples/python-ros2-dataflow/run.rs index e531b8b2..a4ce5e91 100644 --- a/examples/python-ros2-dataflow/run.rs +++ b/examples/python-ros2-dataflow/run.rs @@ -14,9 +14,20 @@ async fn main() -> eyre::Result<()> { std::env::set_current_dir(root.join(file!()).parent().unwrap()) .wrap_err("failed to set working dir")?; - run(&["python3", "-m", "venv", "../.env"], None) - .await - .context("failed to create venv")?; + run( + &[ + get_python_path() + .context("Could not get python binary")? + .to_str() + .context("Could not convert python path to string")?, + "-m", + "venv", + "../.env", + ], + None, + ) + .await + .context("failed to create venv")?; let venv = &root.join("examples").join(".env"); std::env::set_var( "VIRTUAL_ENV", diff --git a/libraries/core/src/descriptor/validate.rs b/libraries/core/src/descriptor/validate.rs index 6b0c599b..93063de9 100644 --- a/libraries/core/src/descriptor/validate.rs +++ b/libraries/core/src/descriptor/validate.rs @@ -2,6 +2,7 @@ use crate::{ adjust_shared_library_path, config::{DataId, Input, InputMapping, OperatorId, UserInputMapping}, descriptor::{self, source_is_url, CoreNodeKind, OperatorSource}, + get_python_path, }; use eyre::{bail, eyre, Context}; @@ -152,7 +153,7 @@ fn check_python_runtime() -> eyre::Result<()> { // Check if python dora-rs is installed and match cli version let reinstall_command = format!("Please reinstall it with: `pip install dora-rs=={VERSION} --force`"); - let mut command = Command::new("python3"); + let mut command = Command::new(get_python_path().context("Could not get python binary")?); command.args([ "-c", &format!( diff --git a/libraries/core/src/lib.rs b/libraries/core/src/lib.rs index 786f5d80..9b6d81b8 100644 --- a/libraries/core/src/lib.rs +++ b/libraries/core/src/lib.rs @@ -1,4 +1,4 @@ -use eyre::{bail, eyre}; +use eyre::{bail, eyre, Context}; use std::{ env::consts::{DLL_PREFIX, DLL_SUFFIX}, path::Path, @@ -30,3 +30,15 @@ pub fn adjust_shared_library_path(path: &Path) -> Result Result { + let python = match which::which("python3") { + Ok(python) => python, + Err(_) => which::which("python") + .context("failed to find `python` or `python3` in dora-daemon path. Make sure that python is available for the daemon.")?, + }; + Ok(python) +}