org-babel python environment setup

Viewed 2461

I've tried to setup a python virtual environment following the top answer here: https://emacs.stackexchange.com/questions/24267/using-org-babel-to-enable-virtualenv/38047 I tried activating the virtual environment using two methods: source $PYENV/bin/activate and pyvenv-workon $PYENV. I expect to see the output of which python and which pip refer back to this virtual environment, but it uses the computer's primary python installation. The path to $VIRTUAL_ENV is correct, however. Similarly, the final code block does not use the virtual environment as expected either. Any ideas what I'm missing?

    #+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 Answers
Related