org-babel python环境设置

时间:2019-01-01 03:43:51

标签: python emacs org-mode org-babel

我尝试按照此处的最佳答案设置python虚拟环境: https://emacs.stackexchange.com/questions/24267/using-org-babel-to-enable-virtualenv/38047 我尝试使用两种方法激活虚拟环境:source $PYENV/bin/activatepyvenv-workon $PYENV。我希望看到which pythonwhich pip的输出返回此虚拟环境,但是它使用计算机的主要python安装。但是,到$VIRTUAL_ENV的路径是正确的。同样,最终代码块也未按预期使用虚拟环境。有什么想法我想念的吗?

    #+BEGIN_SRC bash :dir ~/ :results drawer   
pwd   
python3 -m venv py3_venv 
    #+END_SRC

    #+RESULTS: 
:RESULTS: 
/home/jj 
:END:

    #+BEGIN_SRC bash :dir ~/ :results raw drawer 
source py3_venv/bin/activate
    #+END_SRC

    #+RESULTS: 
:RESULTS: 
:END:

    https://emacs.stackexchange.com/questions/24267/using-org-babel-to-enable-virtualenv/38047
    #+BEGIN_SRC elisp :session venv-py3 :results raw drawer 
(pyvenv-workon "py3_venv")
    #+END_SRC

    #+RESULTS: 
:RESULTS: nil 
:END:

    #+BEGIN_SRC sh :session venv-py3 
echo $VIRTUAL_ENV 
echo $PYTHONPATH 
which python 
which pip
    #+END_SRC

    #+RESULTS: 
| /home/jj/.virtualenvs/py3_venv 
| 
|                                
| 
| /home/jj/anaconda3/bin/python  
| 
| /home/jj/anaconda3/bin/pip     |

    #+BEGIN_SRC python :results output :session venv-py3 
import sys \
print('\n'.join(sys.path))
    #+END_SRC

        #+RESULTS: 
: /home/jj/anaconda3/lib/python37.zip 
: /home/jj/anaconda3/lib/python3.7 
: /home/jj/anaconda3/lib/python3.7/lib-dynload 
: /home/jj/anaconda3/lib/python3.7/site-packages

0 个答案:

没有答案