Shebangs in conda managed environments
Asked Answered
C

1

14

I am trying to write a program in Hy and run it per the instructions on the Quickstart page in the documentation.

So I installed Hy using pip from the GitHub repo per the docs, then added executable permissions to the file with chmod +x myfile.hy.

To manage my Python environments, I use Anaconda's conda, rather than virtualenv. Hence the shebang #! /usr/bin/env hy does not work for me, since the conda envs live in a different directory. From conda info --envs I see that their directories are

myenv     * /home/myname/.conda/envs/myenv 
root        /home/myname/anaconda3

Now attempting to run the script with #! /home/myname/.conda/envs/myenv hy bash throws a bad interpreter: Permission denied error.

Where should shebangs point in this case?

Cady answered 13/12, 2016 at 22:47 Comment(5)
I don't understand why this was downvoted?Cady
I agree it's a bit harsh, you shouldn't be blamed to ask questions specially when you showed your investigation.Elviaelvie
I propose closing this as a duplicate of How do I activate a conda env in a subshell?. While this one is older (and IMHO more clearly stated), the answers on the other are more thorough and cover a range of alternatives.Scallop
I know that at the time I asked this question I didn't know what a subshell was -- I'd argue that my framing while less refined might have better SEO for absolute beginners! I'm not totally sure what the SO philosophy is around this though -- using the appropriate terminology is probably better for accessibility overall and so probably should trump beginner-accessibilityCady
@Cady I'm only suggesting you close it so the other answer is prominently linked at the top. Your answer would still be discoverable via search. I think it helps to have lots of different ways to state the question, but have a central location of common solutions.Scallop
L
10

#!/usr/bin/env hy will actually work with Conda. You just need to say source activate myenv before running the script.

Laresa answered 14/12, 2016 at 4:39 Comment(1)
Thanks for your response. My env was activated, but I think I made assumptions without trying it. Appreciate itCady

© 2022 - 2024 — McMap. All rights reserved.