org-babel python environment setup












0















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









share|improve this question























  • Have you tried setting org-babel-python-command to the desired python executable in your .emacs file?

    – unutbu
    Jan 1 at 4:08











  • venv is a builtin implementation of virtualenv and the user guide for virtualenv states, "If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv" (my emphasis). So merely setting org-babel-python-command is enough to essentially activate that venv. (See the caveat in the above link.)

    – unutbu
    Jan 1 at 4:27











  • This did the trick. Thank you!

    – debby
    Jan 14 at 6:04
















0















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









share|improve this question























  • Have you tried setting org-babel-python-command to the desired python executable in your .emacs file?

    – unutbu
    Jan 1 at 4:08











  • venv is a builtin implementation of virtualenv and the user guide for virtualenv states, "If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv" (my emphasis). So merely setting org-babel-python-command is enough to essentially activate that venv. (See the caveat in the above link.)

    – unutbu
    Jan 1 at 4:27











  • This did the trick. Thank you!

    – debby
    Jan 14 at 6:04














0












0








0


1






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









share|improve this question














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






python emacs org-mode org-babel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 3:43









debbydebby

134




134













  • Have you tried setting org-babel-python-command to the desired python executable in your .emacs file?

    – unutbu
    Jan 1 at 4:08











  • venv is a builtin implementation of virtualenv and the user guide for virtualenv states, "If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv" (my emphasis). So merely setting org-babel-python-command is enough to essentially activate that venv. (See the caveat in the above link.)

    – unutbu
    Jan 1 at 4:27











  • This did the trick. Thank you!

    – debby
    Jan 14 at 6:04



















  • Have you tried setting org-babel-python-command to the desired python executable in your .emacs file?

    – unutbu
    Jan 1 at 4:08











  • venv is a builtin implementation of virtualenv and the user guide for virtualenv states, "If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv" (my emphasis). So merely setting org-babel-python-command is enough to essentially activate that venv. (See the caveat in the above link.)

    – unutbu
    Jan 1 at 4:27











  • This did the trick. Thank you!

    – debby
    Jan 14 at 6:04

















Have you tried setting org-babel-python-command to the desired python executable in your .emacs file?

– unutbu
Jan 1 at 4:08





Have you tried setting org-babel-python-command to the desired python executable in your .emacs file?

– unutbu
Jan 1 at 4:08













venv is a builtin implementation of virtualenv and the user guide for virtualenv states, "If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv" (my emphasis). So merely setting org-babel-python-command is enough to essentially activate that venv. (See the caveat in the above link.)

– unutbu
Jan 1 at 4:27





venv is a builtin implementation of virtualenv and the user guide for virtualenv states, "If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv" (my emphasis). So merely setting org-babel-python-command is enough to essentially activate that venv. (See the caveat in the above link.)

– unutbu
Jan 1 at 4:27













This did the trick. Thank you!

– debby
Jan 14 at 6:04





This did the trick. Thank you!

– debby
Jan 14 at 6:04












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992886%2forg-babel-python-environment-setup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992886%2forg-babel-python-environment-setup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas