Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make script callable within SCT conda env without having to activate it everytime #4

Open
jcohenadad opened this issue Sep 4, 2024 · 4 comments

Comments

@jcohenadad
Copy link
Member

jcohenadad commented Sep 4, 2024

instead of having to activate SCT's conda (as described here):

cd $SCT_DIR
source ./python/etc/profile.d/conda.sh
conda activate venv_sct

it would be nicer if the script could include a launcher. @mguaypaq @joshuacwnewton do you have suggestions on how to do this?

@mguaypaq
Copy link
Member

mguaypaq commented Sep 4, 2024

Maybe I'm missing some context, but I don't see any reason why the SCT conda environment needs to be activated here. The script doesn't import anything from spinalcordtoolbox, or from dcm2niix. It looks like it only runs dcm2niix through os.system(), which should work fine as long as the dcm2niix script/executable is on the $PATH.

The script does import pandas, nibabel, so those packages should be pip-installed inside some python virtual environment. But it doesn't need to be specifically the SCT environment.

@joshuacwnewton
Copy link
Member

joshuacwnewton commented Sep 4, 2024

👍 to what Mathieu is saying.

In other words, instead of recommending to install dcm2niix inside the SCT environment, the installation instructions could be updated so that dcm2niix is installed through some other method (that still exposes the command via the $PATH).

However, if it turns out that installing dcm2niix inside the SCT environment truly is the easiest way to install it, then of course we could just create a simple softlink inside of $SCT_DIR/bin as a way of exposing the executable on the $PATH. I've done that with other conda/pip-based software (e.g. fsleyes) to avoid having to activate the venv every time. It's a simple one-liner we could add to the existing instructions.

ln -s "$SCT_DIR"/python/envs/venv_sct/bin/dcm2niix "$SCT_DIR"/bin/dcm2niix

@valosekj
Copy link
Member

valosekj commented Sep 4, 2024

Thank you for your opinions! 👍🏻

The script does import pandas, nibabel, so those packages should be pip-installed inside some python virtual environment. But it doesn't need to be specifically the SCT environment.

Ideally, the pipeline should be as straightforward as possible (because it'll be used by users without a computer science background). So instead of installing pandas, nibabel into "some python virtual environment", I was thinking about reusing the SCT conda env.

In other words, instead of recommending to install dcm2niix inside the SCT environment, the installation instructions could be updated so that dcm2niix is installed through some other method (that still exposes the command via the $PATH).

I'll explore this option.

@valosekj
Copy link
Member

Eventually I call the file_loader.py script from the process_data.sh bash script on L132.
Running the python script from the bash script allowed me to activate the conda env in the background using these lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants