Jess
Jess

Reputation: 13

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!

What I've tried so far:

I have now added conda and python to my path (thank you @Nesha25, I didn't need admin!). I then tried to run my script in the command prompt with: conda run -n Ngon_env python C:\Users\jlp\Desktop\Local_BLAST_scripts\Neisseria\ngon_script.py --live-stream But I get the following error which seems to occur after it tried to use the input function in my python script: EOFError: EOF when reading a line.

I then tried conda run -n Ngon_env --live-stream python C:\Users\jlp\Desktop\Local_BLAST_scripts\Neisseria\ngon_script.py and it doesn't seem to do anything and just gets stuck.

The conda run --no-capture-output flag worked instead, hooray!

Upvotes: 1

Views: 5913

Answers (1)

merv
merv

Reputation: 76750

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 and/or --no-capture-output). See conda run --help.

Upvotes: 3

Related Questions