spacemacs
spacemacs copied to clipboard
spacemacs/python-execute-file still uses default interpreter after switching python environments
Description :octocat:
spacemacs/python-execute-file still uses default interpreter after changing env with pyenv.
Reproduction guide :beetle:
- Start Emacs
- Create a python file with the following code, printing path to interpreter:
import sys
print sys.executable
- Switch python environment with SPC-m-V-a
- Run the script with SPC-m-c-c
Observed behaviour: :eyes: :broken_heart: The script prints the path to the default python interpreter(first found in PATH). BTW, SPC-e-v shows that python-pycompile checker actually has correct path to the interpreter, it's just spacemacs/python-execute-file that doesn't know anything about it. Also, SPC-m-' starts REPL in correct env.
Expected behaviour: :heart: :smile: It is expected that the script will be executed with the interpreter from the env chosen, not the first interpreter found in PATH.
System Info :computer:
- OS: darwin
- Emacs: 25.1.1
- Spacemacs: 0.200.7
- Spacemacs branch: master (rev. c2774bc)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: ivy
- Layers:
(javascript ivy emacs-lisp dash git markdown osx python themes-megapack ess syntax-checking)
- System configuration features: NOTIFY ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
Same issue with conda.el package for emacs, instead of pyenv.
Having this same issue of not changing python interpreter.
Are you sure that you are using pyenv and not pyvenv. The command SPC m V a
is for pyvenv. Because it works with pyenv for me.
Could it be related to the system itself? I get the same result on fedora. And I am indeed using pyenv.
In the terminal I get access to Python 3, which is what I want to use, but in emacs it defaults to version 2.7, which is not even the default on my system.
I have a hunch that a bunch of other stuff is also broken :(
Edit: I also get a different set of packages available. I can check this with the command import site; print(site.getsitepackages())
@cpaulik you are correct, it's pyvenv
@sp3ctum not sure, I'm on macOS
Same problem as the OP here (OS X, Spacemacs [email protected]). Spacemacs ignores the Python version set via pyvenv (SPC-m-V-w, pyvenv-workon) and just uses system's default.
In my case my venv is a Conda environment:
> /Users/frodera/miniconda3/envs/python37/bin/python --version
Python 3.7.0
After setting the env via SPC-m-V-w
, emacs reports that the path of that env is the first one listed in Spacemacs' PATH
and it even lists it in the status bar. However, when running a python script via SPC-m-c-c
it reverts to system's default (2.7). See attached image.
getenv "PATH" -> /Users/frodera/miniconda3/envs/python37/bin:/usr/local/opt/coreutils/...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
same issue here with conda layer, please not close it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
active
Is there any variable I can set to hardcode the python version it runs as a workaround?
@dgealow maybe python-shell-interpreter
Actually, I found the problem. In layers/+lang/python/packages.el, the function spacemacs/python-execute-file
contains the line (compile-command (format "python %s" (file-name-nondirectory
, which essentially means that it will always run whatever the default version of python is regardless of any spacemacs variables or loaded environment. It looks like there's a more robust fix in the works in the latest development branch (haven't tested it yet) but as a workaround I just found the file in my ~/.emacs.d/
directory. I changed that line to ...format "python3 %s"
... since my default Python 3 installation is what I want 99% of the time. You might be able to precision-edit the line to read the python-shell-interpreter variable but I didn't feel like trying anything fancy. I'd recommend trying the dev version to anyone else looking for a solution.
Closing now. Please always use develop branch.
This issue also happen in develop, If I remember correctly
Issue appears to probably be solved, at least for the use case of "I just want python 3". If no virtual environment is active, then it will use python-shell-interpreter
to run the script--default ipython
, overrideable with (setq-default python-shell-interpreter "python2")
(or whatever python version you want) in dotspacemacs/user-config
.
However, I can't verify that it works properly with virtual environments, because of a bug introduced into ipython just 3 days ago. Will report back as soon as that gets fixed!
Alright, downgraded my ipython to test this out. It seems that if you have ipython installed in your virtual environment, it will use that version of ipython. However, if you don't, then it will use the system default ipython rather than the virual environment's python.
We shouldn't support python 2.
So the issue should be considered fixed if it works as expected under python 3, with and without virtual environment.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!