How do I activate a conda env in a subshell?

后端 未结 3 653
不知归路
不知归路 2020-12-03 18:35

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:



        
3条回答
  •  暖寄归人
    2020-12-03 18:50

    In your script, change...

    #!/usr/bin/python
    

    ...to:

    #!/usr/bin/env python
    

    The python used by an activated conda environment is ${CONDA_PREFIX}/bin/python and not /usr/bin/python

    Notice the difference?

    (root) ~/condaexpts$ which python
    /home/ubuntu/condaexpts/m3/bin/python
    
    (root) ~/condaexpts$ /usr/bin/env python
    Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    
    (root) ~/condaexpts$ source deactivate
    
    ~/condaexpts$ which python
    /usr/bin/python
    
    ~/condaexpts$ /usr/bin/env python
    Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    

提交回复
热议问题