I've written a python program. And if I have a shebang like this one:
#!/usr/bin/python
and I make the file executable with:
$ chmod 755 program.py
I can run the program like so:
$ ./program.py
Here is the issue. I use the conda virtual environments. When I run the program like above, the system creates a subshell that does not recognize the active environment:
(my_env) $ ./program.py
ImportError: No module named pymongo
If I do it this way, however...
(my_env) $ python program.py
# blah blah... runs great
How do I specify the right environment for use in the subshell? Is it possible? I'd like to save my fingers the effort of typing the six character string that is python
.
Another post, Shebangs in conda managed environments, briefly touches on this but does not provide the right answer. Instead of activating the environment in the subshell, it just says, go ahead and ignore the shebang... just use the $ python program.py
syntax.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…