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

Problem with Python environment #188

Closed
andy47 opened this issue Jul 18, 2016 · 20 comments
Closed

Problem with Python environment #188

andy47 opened this issue Jul 18, 2016 · 20 comments

Comments

@andy47
Copy link

andy47 commented Jul 18, 2016

I've just installed Emacs and then the Spacemacs configuration. When I enable the python layer and open a .py file in the editor I am seeing this error message;

File "", line 4, in
File "build/bdist.macosx-10.11-intel/egg/anaconda_mode.py", line 18, in
File "build/bdist.macosx-10.11-intel/egg/service_factory/init.py", line 14, in
File "build/bdist.macosx-10.11-intel/egg/service_factory/factory.py", line 14, in
File "build/bdist.macosx-10.11-intel/egg/service_factory/providers/basehttp.py", line 18, in
ImportError: No module named BaseHTTPServer

I have a couple of different python versions installed on my machine and a number of python virtualenvs. I'm guessing that I have Emacs pointing at a broken virtualenv or incorrect Python version. Can anyone help me figure out how to find the broken component/link?

@proofit404
Copy link
Contributor

Hi. Can you provide following information

M-: (pythonic-executable) RET

@andy47
Copy link
Author

andy47 commented Jul 22, 2016

"python" then a window pops up with the error messages above.

@proofit404
Copy link
Contributor

(executable-find (pythonic-executable))

@danielwuz
Copy link

I have exactly the same problem on OS EI Capitan with the system default python(i.e. /usr/bin/python). I don't know why but I was able to work around this issue with

$ brew install python
$ pip install ipython

Then (executable-find (pythonic-executable)) shows me /usr/local/bin/ipython

@proofit404
Copy link
Contributor

Does apple provide http server library with its python?

@andy47
Copy link
Author

andy47 commented Jul 24, 2016

@proofit404 - /usr/bin/python
When I try this I don't see any errors;

$ /usr/bin/python
Python 2.7.10 (default ...
>>> import BaseHTTPServer
>>>

@andy47
Copy link
Author

andy47 commented Jul 24, 2016

Is there a way to indicate which python version/installation to use? I have system Python and more up to date versions installed using MacPorts, not to mention quite a few virtualenvs.

@andy47
Copy link
Author

andy47 commented Jul 24, 2016

Definitely some confusion when starting Emacs. If I activate a virtualenv on the command line and then open Emacs.app in Emacs the pythonic-executable is showing as from the virtualenv and I don't get any error messages when opening a python file.

@proofit404
Copy link
Contributor

I think you need to try exec-path-from-shell package. Also there is a python-shell-interpreter and python-shell-virtualenv-path variables to point to your python installation. Use pythonic-activate command to enable it easily. As a benefit anaconda-mode will search for completions in packages installed inside virtual environment. For example you will get completions for line from django import sh<tab>

@pfmaggi
Copy link

pfmaggi commented Aug 19, 2016

I got the same issue with emacs 24.5 on OSX El Capitan starting from a prelude setup, with python3 installed via brew. In this case python 3.5.2 is linked to the python3 command installed under /usr/local/bin.
At the end, following this issue, I saw that M-: (pythonic-executable) RET was still pointing to the original python 2 executable, returning python (no surprise here, as I didn't told emacs about my nice python 3 setup...).
To fix it, I'd to set a couple of custom values:

(custom-set-variables
    '(python-shell-exec-path (quote ("python3")))
   '(python-shell-interpreter "python3")
)

and delete the anaconda-mode folder under the prelude directory (prelude recreate it when you restart emacs).

This solved the issue for me.

@proofit404
Copy link
Contributor

You set exec path in the wrong way. I suggest you to remove it. Using interpreter with BaseHTTPServer installed is the right choice and you did it in the third line.

@pfmaggi
Copy link

pfmaggi commented Aug 19, 2016

Thanks, I'm new around here and still learning :-P
I've now modified my setup to have just:

(custom-set-variables
  '(python-shell-interpreter "python3")
)

and it works correctly.

@smizell
Copy link

smizell commented Aug 20, 2016

I believe I've tried everything here, but I still have this same issue. I have even tried to use pyenv and use a different version of Python. When using 3.5, I get:

ImportError: No module named 'six.moves.BaseHTTPServer'; 'six.moves' is not a package

And when I run (executable-find (pythonic-executable)) I get the pyenv path.

Are there any other tricks to make this work? Happy to provide any info needed. Thanks!

@jacktasia
Copy link

@smizell FWIW: I got the same error when trying to move over to python. I fixed it by adding (setq python-shell-interpreter "python3") to my config. Stopping emacs and then rm -rf ~/emacs.d/anaconda-mode then starting emacs back up and installing anaconda-mode again, which for my config just automatically happens when it sees the package doesn't exist anymore.

@smizell
Copy link

smizell commented Aug 24, 2016

@jacktasia thanks for the response. I just tried what you have here and did not have success. I am use Spacemacs. I set python-shell-interpreter, deleted anaconda-mode, and resynced my configuration. It reinstalled the mode, but I still get the Python3 related error.

@proofit404
Copy link
Contributor

@smizell Sorry for late response.

Open your favourite shell, activate pyenv version you want to use within Emacs and do following bash commands:

$ cd ~/.emacs.d/anaconda-mode/0.1.2

$ python -i
>>> import site
>>> site.addsitedir('.')
>>> from six.moves.BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
>>>

$ python -i
>>> from http.server import BaseHTTPRequestHandler, HTTPServer
>>>

Does they behave different?

@smizell
Copy link

smizell commented Aug 25, 2016

@proofit404 For the first command:

ImportError: No module named six.moves.BaseHTTPServer

For the second:

ImportError: No module named http.server

Note, this was all using Python 2.7. When I switched to 3.5.2, the second import worked for me.

@proofit404
Copy link
Contributor

@smizell I've released new anaconda-mode version 0.1.3. It doesn't use six library, so it should solve your import problem. Please wait for melpa build and update your emacs package. Any other actions should be done automatically by Emacs package.

I wait for your feedback in any case. Let me know if it solve your problem, if it not or if it introduce the new one.

@smizell
Copy link

smizell commented Aug 26, 2016

I just loaded up the python layer for Spacemacs. It looks like the newest anaconda-mode version is there. However, when I open a Python file, I get a large wall of text for an error.

eldoc error: (file-error Searching for program no such file or directory bind: Key with name 'down' does not have any mappingbind: Key with name 'up' does not have any mappingbind: Key with name 'right' does not have any mappingbind: Key with name 'left' does not have any mappingbind: Key with name 'dc' does not have any mappingbind: Key with name 'backspace' does not have any mappingbind: Key with name 'ppage' does not have any mappingbind: Key with name 'npage' does not have any mappingbind: Key with name 'f1' does not have any mappingbind: Key with name 'btab' does not have any mappingbind: Key with name 'down' does not have any mappingbind: Key with name 'up' does not have any mappingbind: Key with name 'right' does not have any mappingbind: Key with name 'left' does not have any mappingbind: Key with name 'dc' does not have any mappingbind: Key with name 'backspace' does not have any mappingbind: Key with name 'ppage' does not have any mappingbind: Key with name 'npage' does not have any mappingbind: Key with name 'f1' does not have any mappingbind: Key with name 'btab' does not have any mappingbind: Key with name 'right' does not have any mappingbind: Key with name 'left' does not have any mappingbind: Key with name 'down' does not have any mappingbind: Key with name 'up' does not have any mappingbind: Key with name 'dc' does not have any mappingbind: Key with name 'backspace' does not have any mappingbind: Key with name 'right' does not have any mappingbind: Key with name 'left' does not have any mapping/Users/username/.pyenv/versions/3.5.2/bin/python)

Just as a note, I'm on Spacemacs, so this may affect debugging here. I'm also a newcomer to this wonderful world of emacs.

Edit: thanks for the help :)

@smizell
Copy link

smizell commented Aug 29, 2016

@proofit404 I have tracked down the issue above and fixed it. It was related to some issues with Spacemacs and using Fish as the shell. I moved back to Bash and restarted my computer (Emacs still used Fish—must have been cached) and was able to get anaconda-mode working.

Everything is working great. I was able to remove (python-shell-interpreter "python3") from my confg file and used pyvenv.el to handle my Python version. I confirmed that everything is working in Python 2 and 3.

I'm wondering if my original issue was related to Fish. Either, it's working for me now with no special configuration other than using pyvenv.el.

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants