I have just happily configured emacs with autocompletion via jedi and syntax check via flycheck and virtualenvs created within bootstrap. It all seems to work.
I'd like to add the ability to use flycheck-pylint (to get errors in import) but I'm not able to make it work. Even if I change the virtualenv by hand (M-x: pyvenv-activate RET path-to-my-venv) I still see lots of import errors that come from a wrong virtualenv used.
My current initialization code:
(require 'pyvenv)
(add-hook 'after-init-hook #'global-flycheck-mode)
(defun set-flake8-executable ()
(pyvenv-activate (get-current-buffer-venv))
(flycheck-set-checker-executable (quote python-flake8)
(get-current-buffer-flake8)))
where "get-current-buffer-venv" and "get-current-buffer-flake8" are functions that implement my specific setup and are working correctly.
How can I change the interpreter used?
Thanks to an answer from Lunaryorn on github i realized there is also a flycheck-set-pylint-executable. Now all is working correctly whith the following configuration:
(defun set-flychecker-executables ()
"Configure virtualenv for flake8 and lint."
(when (get-current-buffer-flake8)
(flycheck-set-checker-executable (quote python-flake8)
(get-current-buffer-flake8)))
(when (get-current-buffer-pylint)
(flycheck-set-checker-executable (quote python-pylint)
(get-current-buffer-pylint))))
(add-hook 'flycheck-before-syntax-check-hook
#'set-flychecker-executables 'local)
Poking at the problem today, I found another solution (which works with current version of flycheck, as of Jun 2020).
Just create .dir-locals.el with appropriate settings for given project. Like:
((python-mode
(flycheck-python-flake8-executable . "/home/marcin/.virtualenvs/adgv/bin/python")
(flycheck-python-pylint-executable . "/home/marcin/.virtualenvs/adgv/bin/python")))
(creating the file with M-x add-dir-local-variable works too, but remember to add double quotes around the command)
Related
When I use a plugin that requires python, it can't find it and barfs.
The places that seem to being searched are:
Using -version I see both:
+python/dyn
+python3/dyn
However :echo has("python3") returns 0.
I'm not sure if this is compile time config, or runtime-configurable via .vimrc.
I'm not a python developer, and the few times I've ventured into that world were in the middle of the python2/python3 mess that turned me off completely. I've played around enough to have configured pyenv it seems, and get
╰─$ which python
/Users/benlieb/.pyenv/shims/python
╰─$ python --version
Python 3.10.3
Can anyone help shed light on what to do to get python3 findable/usable in my vim?
Update:
Following #romainl's suggestion below I set in my .vimrc
set pythonthreedll=/Users/benlieb/.pyenv/shims/python
But getting the following error:
+python/dyn and +python3/dyn are described here: :help python-dynamic.
By default, :help 'pythonthreedll' points to:
/opt/homebrew/Frameworks/Python.framework/Versions/3.10/Python
because MacVim is built against that version. The message in your screenshot says that there is nothing at that path. In order to have a working Python 3 interface, you can either:
install Python 3.10 via homebrew,
or point pythonthreedll to a valid path.
For example, I don't use Homebrew so the default value is useless to me, but I use MacPorts so this is my pythonthreedll:
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
After some time, I found the following works, thought it was not a fun path of discovery.
let &pythonthreedll = trim(system("pyenv which python"))
I have discovered an issue with python-mode in emacs. I generally c++ develop and seldom do python.
I have recently discovered this issue:
I emacs –Q
I open a python file
It contains:
import re as myre
Var = [
%
The % represents the cursor location. Then, at that location I try to tab and get this error:
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
python-indent-context()
python-indent--calculate-indentation()
python-indent-calculate-indentation(nil)
python-indent-line(nil)
python-indent-line-function()
indent-for-tab-command(nil)
call-interactively(indent-for-tab-command nil nil)
command-execute(indent-for-tab-command)
I have not developed in python for a month or so but I cannot remember this being an issue.
I am using emacs 24.5.1 windows 7 64, python 2.7.3 and – of course - -Q so no configuration.
Now, I try to apply python-mode 6.2.1 by running this
Emacs –Q
In scratch
(setq load-path (append load-path (list "~/.emacs.d/python-mode.el-6.2.1")))
(require 'python-mode)
I open up a python file (the same as above) then I CAN indent. This is all well and good, so if I load python-mode 6.2.1 el file in my NORMAL configuration this solve the issue, BUT now with the new 6.2.1 I do not get the same theme coloring as before (it is now bland and variable are just the same colour as other text, rather than standing out. Also which-function-mode seems to be broke (again) and developing in python is sluggish (when you open a large file) - I remember python-mode and which-function-mode not being friendly with each other in 24.3, but it was solved with STOCK el 24.5
For me, unfortunately, 6.2.1 solves one issue but creates others - INCLUDING regressions.
If, instead, I can just have the patch that solves the indentation issue, that would be great.
Thank you.
python-mode.el's py-variable-name-face inherits default face. Use M-x customize-face RET ...
Please file bugs reports at
https://gitlab.com/python-mode-devs/python-mode/issues
or
https://bugs.launchpad.net/python-mode
I'm using Emacs 24.4.1 on OSX (installed with Homebrew), with the built in python.el, and Python 3 (also installed with Homebrew), along with IPython 2.3.0. I have this in my .emacs:
(setq
python-shell-interpreter "/usr/local/bin/ipython3"
python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
python-shell-completion-setup-code
"from IPython.core.completerlib import module_completion"
python-shell-completion-module-string-code
"';'.join(module_completion('''%s'''))\n"
python-shell-completion-string-code
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
Everything works correctly when I invoke M-x run-python, except one thing: the <tab>-completion of module names doesn't work in the REPL (it says "No match" in the *Messages* buffer). I'm pretty sure it was working with Emacs 24.3, which I upgraded very recently, but I'm not 100% sure. Anyone has an idea what might cause this, or how I could try to debug it?
You might like to try and remove most of your settings above, since Emacs-24.4 should support IPython pretty much out of the box.
I want to use pep8 as my makeprg in order to check and fix my code compliance to PEP8 (Style guide for python code).
I used the command :set makeprg=pep8\ --repeat\ %, and when I do :make it works, the error list is populated and I can use :cn, :cp and :copen to navigate and see the error list in the QuickFix window.
But as soon as I change something in my python source file the errorlist becomes empty, the QuickFix window loses its content and I cannot navigate the list anymore.
I suspect that this is caused by PyFlakes, a Vim extension that highlights Python errors on-the-fly.
How can I fix it?
pyflakes has an option that should solve your problem, just put this in your ~/.vimrc :
let g:pyflakes_use_quickfix = 0
This actually stops pyflakes from using (and breaking) the quickfix window, that is good enough for me.
See this vim extension
The only thing I can get python omnicomplete to work with are system modules. I get nothing for help with modules in my site-packages or modules that I'm currently working on.
Once I generated ctags for one of my site-packages, it started working for that package -- so I'm guessing that the omnicomplete function depends on ctags for non-sys modules.
EDIT: Not true at all.
Here's the problem -- poor testing on my part -- omnicomplete WAS working for parts of my project, just not most of it.
The issue was that I'm working on a django project, and in order to import django.db, you need to have an environment variable set. Since I couldn't import django.db, any class that inherited from django.db, or any module that imported a class that inherited from django.db wouldn't complete.
I get completion for my own modules in my PYTHONPATH or site-packages. I'm not sure what version of the pythoncomplete.vim script you're using, but you may want to make sure it's the latest.
EDIT: Here's some examples of what I'm seeing on my system...
This file (mymodule.py), I puth in a directory in PYTHONPATH, and then in site-packages. Both times I was able to get the screenshot below.
myvar = 'test'
def myfunction(foo='test'):
pass
class MyClass(object):
pass
Just ran across this on Python reddit tonight: PySmell. Looks like what you're looking for.
PySmell is a python IDE completion helper.
It tries to statically analyze Python source code, without executing it, and generates information about a project’s structure that IDE tools can use.
While it's important to note that you must properly set your PYTHONPATH environmental variable, per the the previous answer, there is a notable bug in Vim which prevents omnicompletion from working when an import fails. As of Vim 7.2.79, this bug hasn't been fixed.
Trouble-shooting tip: verify that the module you are trying to omni-complete can be imported by VIM. I had some syntactically correct Python that VIM didn't like:
:python import {module-name}
Traceback (most recent call last):
File "<string>", line 1, in ?
File "modulename/__init__.py", line 9
class empty_paranthesis():
^
SyntaxError: invalid syntax
Case-in-point, removing the parenthesis from my class definition allowed VIM to import the module, and subsequently OmniComplete on that module started to work.
I think your after the pydiction script. It lets you add your own stuff and site-packages to omni complete.
While your at it, add the following to your python.vim file...
set iskeyword+=.
This will let you auto-complete package functions e.g. if you enter...
os.path.
and then [CTRL][N], you'll get a list of the functions for os.path.