Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipenv-activate doesn't load the virtual environment for all other commands #23

Closed
billwanjohi opened this issue Apr 5, 2018 · 6 comments

Comments

@billwanjohi
Copy link

I'm running spacemacs on the syl20bnr/spacemacs@0fa3658 of the develop branch. When I run the pipenv-shell function, it properly launches a shell in the appropriate environment, which I can verify by running pip freeze and viewing installed libraries.

When I run pipenv-activate, it doesn't seem like much of anything happens. I do get some output to two buffers:

  • *Pipenv*

/home/bill/.local/share/virtualenvs/{valid-path-to-my-venv}
Process Pipenv finished

  • *Messages*

Finished pipenv --venv

My virtual environment's packages are not available to emacs, and running pip freeze from the editor confirms this. Dropping down to the pyvenv functions does work.

I'd provide more information, but this about the extent of my emacs-lisp debugging experience.

@pwalsh
Copy link
Owner

pwalsh commented Apr 7, 2018

Hi @billwanjohi

pipenv-activate does two things always:

  1. sets python-shell-virtualenv-root to that of your Pipenv-managed virtualenv, based on your current location.
  2. Puts executables from your virtualenv on your exec-path

Based on your pasted output, (1) is definitely happening. You can inspect the exec-path variable to confirm (2).

What does it mean that your "virtual environment's packages are not available to emacs"? What are you trying to do that does not work as you expect?

About pip freeze: it would only work as you seem to be expecting if you have pip installed in the specific virtual env you have activated, in a buffer you open after activating. If you want to be sure that Emacs is aware of the activation, try pipenv-graph, or, run pipenv graph inside the shell you can spawn with pipenv-shell.

@billwanjohi
Copy link
Author

tldr: I can't run tests.

I originally couldn't use much of anything from the pipenv-el-activated env, but testing this only from fresh emacs sessions (and potentially some unrelated spring-cleaning on the rest of my emacs config) shrank my problem set.

Things that work after pipenv-activate

  • pipenv-graph posts the correct graph to the *Pipenv* buffer
  • spacemacs/python-execute-file properly imports libraries
  • spacemacs/python-start-or-switch-repl launches a repl that can import all of my virtual environment's installed libraries

Things that don't work

  • shell command followed by pip freeze runs, but returns my system installed packages, not my virtual environment. This is more of a diagnostic than a problem for me.
  • pytest-module fails on "command not found: py.test"

These things work when I instead used pyvenv-workon to activate my virtual environment.

@pwalsh
Copy link
Owner

pwalsh commented Apr 29, 2018

@billwanjohi ok I'll check it out. We may integrate with pyvenv which seems like it would address this, but first I want to reproduce myself.

@pwalsh pwalsh self-assigned this Apr 29, 2018
@pwalsh pwalsh removed their assignment Apr 29, 2018
@pwalsh pwalsh added this to the Current milestone Apr 29, 2018
@billwanjohi billwanjohi changed the title pipenv-activate doesn't seem to do anything pipenv-activate doesn't load the virtual environmenment for all other commands May 30, 2018
@billwanjohi billwanjohi changed the title pipenv-activate doesn't load the virtual environmenment for all other commands pipenv-activate doesn't load the virtual environment for all other commands May 30, 2018
@garyo
Copy link

garyo commented Nov 12, 2018

I'm not sure if this is the same issue or not, but pipenv doesn't seem to do (setenv "PATH" <venv>); it only sets exec-path. This means that anything executed by a subshell from emacs doesn't get the proper python. I'm using Emacs 25.3.1 on MacOSX, with python 3.6.5 in my venv. But when I start a compile with M-x compile the python run by my build step is system python, which is 2.7.

@pwalsh
Copy link
Owner

pwalsh commented Dec 6, 2018

#45

@pwalsh
Copy link
Owner

pwalsh commented Mar 4, 2019

Should be sorted with #48

@pwalsh pwalsh closed this as completed Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants