Best way to activate my conda environment for a python script on a windows PC

I've made a python script for multiple users and I want to be able to run it by just double clicking the script.

I also have made a conda env for this script and it seems I am unable to activate the environment within my python script (?).

I thought I could write a script which will activate my conda env and then run my python script in command prompt but I'm completely lost and can't find out how to even activate my conda env in command prompt.

Am I heading in the right direction with this - is the best way to activate a conda env and run a python script within one executable script via command prompt?

Sorry if this is a really obvious and/or stupid question, I am very new to all of this!

1 answer

  • answered 2022-05-06 13:21 merv

    Not a Windows user, but conda activate is for interactive shell sessions. The conda run command is for programmatic execution within an environment. So, you would have a script with a line like:

    conda run -n my_env python your_script.py
    

    or possibly

    conda run -p /path/to/my_env python your_script.py
    

    if trying to share the environment across users.

    If the script requires interaction, you may need to add flags (like --live-stream). See conda run --help.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum