Search code examples
pythonbashanacondashebanghy

Shebangs in conda managed environments


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?


Solution

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