2

I have been stuck on this problem for a while now and I have tried different solutions online but still cannot get it resolved. I already tried these out:

How to run a python script with its environment from another script with another environment?

How to use path of current conda environment's python as shebang for a script?

How do I activate a conda env in a subshell?

I have a script1.py which uses conda environment my_env1 and calls with CLI to another script script2.py that requires my_env2 (also conda environment). script2.py is called from script1.py which is activated with my_env1. script1.py works fine when I activate my_env2, but does not work when I run it with my_env1.

In my script2.py, I have used following 2 Shebangs separately (but none of them seem to work):

#!C:/Users/<user_name>/.conda/envs conda run -n my_env2 python
#!C:/Users/<user_name>/.conda/envs/my_env2 python

In conda environments, my_env2 and my_env1, there is no bin folder, so I tried using conda install --name <env_name> python; still doesn't solve it. Any help on this would be much appreciated. Thanks.

Muaali
  • 21
  • 2
  • I tried this hack also: `C:/Users//.conda/envs/my_env2/python script1.py`, but still no progress. – Muaali Jan 14 '20 at 14:32
  • https://en.wikipedia.org/wiki/Shebang_(Unix). https://stackoverflow.com/questions/52008516/how-do-i-set-default-app-for-a-file-extension-to-an-exe-on-windows-10-after/52009412#52009412. – CristiFati Jan 14 '20 at 14:35
  • How are you calling `script2` from `script1`? Are they sharing objects? If not, maybe you could do a custom shell calling python from `my_env2 ` . You can check this on [link](https://docs.python.org/3/library/cmd.html) – Ivan Jan 14 '20 at 14:38
  • @Ivan script1 uses CLI like `subprocess.check_call(['python', path/to/script2.py])`. They are not sharing any objects. – Muaali Jan 14 '20 at 14:54
  • Right now I can't check this in my PC, but can you try something like this? `subprocess.check_call(['C:/ProgramData/Anaconda3/envs/my_env2/python', path/to/script2.py]) ` – Ivan Jan 14 '20 at 15:09
  • @Ivan there is no environment under `C:\ProgramData\Anaconda3\envs`; path is found though. All environments are under 'C:/Users//.conda/envs'. And as I put on the first comment, I already tried that out. – Muaali Jan 14 '20 at 15:32

0 Answers0