我尝试按照此处的最佳答案设置python虚拟环境:
https://emacs.stackexchange.com/questions/24267/using-org-babel-to-enable-virtualenv/38047
我尝试使用两种方法激活虚拟环境:source $PYENV/bin/activate
和pyvenv-workon $PYENV
。我希望看到which python
和which 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