How to setup Syntastic as python3 checker instead of python2 - vim

In MacVim, I save following code as test.py
print "Hello world! python2"
, which is apparently wrong with python3, but
after I run :w to save the file, there is no error message for it,
Following is a part of ~/.vimrc, which is all about Syntastic:
" Syntastic
"" Recommended settings
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
"" Display checker-name for that error-message
let g:syntastic_aggregate_errors = 1
"" I use the brew to install flake8
let g:syntastic_python_checkers=['flake8', 'python3']
How to make Syntastic detect this type of error as I run test.py in Terminal:
NingGW:Desktop ninggw$ python3 test.py
File "test.py", line 1
print "Hello world! python2"
^
SyntaxError: Missing parentheses in call to 'print'
Following is what :SyntasticInfo said:
Syntastic version: 3.8.0-10 (Vim 800, Darwin, GUI)
Info for filetype: python
Global mode: active
Filetype python is active
The current file will be checked automatically
Available checkers: flake8 python
Currently enabled checker: flake8
Press ENTER or type command to continue

flake8 is a Python package. It uses Python's built-in facilities to parse code, so it accepts syntax for the Python version that it belongs to.
How to install it for your python3 installation depends on how that installation itself was installed - unless you're fine with using pip.

From the FAQ:
4.11. Q. How can I check scripts written for different versions of Python?
A. Install a Python version manager such as virtualenv or pyenv, activate the environment for the relevant version of Python, and install in it the checkers you want to use. Set g:syntastic_python_checkers accordingly in your vimrc, and run Vim from the virtual environment.
If you're starting Vim from a desktop manager rather than from a terminal you might need to write wrapper scripts around your checkers, to activate the virtual environment before running the actual checks. Then you'll need to point the relevant g:syntastic_python_<checker>_exec variables to the wrapper scripts.

Related

How to correctly enable pylint with ALE in Vim?

I want to set up python linting in Vim using the ALE Vim-package. So far it works well in Atom using the Atom-Plugin, but in Vim it somehow is not working. I installed
pylint using pip3,
Vim 8.1 and
ALE using the Vundle Plugin-Manager.
In my .vimrc I set the
let g:ale_linters={
'python': ['pylint'],
.....+other languages....
}
option. Additionally I read the ALE docs and also tried setting the following:
let g:ale_python_executable='python3'
let g:ale_python_pylint_use_global=1
ALE gets installed correctly and works for Javascript, but for Python, there is just nothing happening.
In case of incorrect code (missing ")") like:
print("Hi"
nothing is marked as error.
It would be great if someone knows how to set this up and can provide some help! Thanks.
I was able to get this working, with the following steps:
install pylint
python3 -m pip install pylint
At least for my setup there was a warning:
Installing collected packages: pylint
WARNING: The scripts epylint, pylint, pyreverse and symilar are
installed in '/home/vagrant/.local/bin' which is not on PATH.
so then:
Add pylint to $PATH
export PATH="$HOME/.local/bin:$PATH"
(this can be added to ~/.profile to be configured persistently)
At you should be able to run pylint manually:
$ cat syntaxerr.py
print("hi
$ pylint syntaxerr.py
************* Module syntaxerr
syntaxerr.py:1:10: E0001: EOL while scanning string literal (, line 1) (syntax-error)
Install ALE
git clone https://github.com/dense-analysis/ale.git ~/.vim/pack/git-plugins/start/ale
At this point the syntax check is working as long as syntax is enabled:
$ cat .vimrc
syntax on
If you'd like to configure g:ale_linters, note that you must escape the newline to create a multi-line dictionary:
let g:ale_linters={
\ 'python': ['pylint'],
\}
Finally, to see how ALE is currently configured, you can always run the following command:
:ALEInfo

Vim could not load libpython3.7m.a with python3 from Anaconda

I'm trying to use Anaconda python3.7 + vim 8.1 + jedi-vim on Rocks 7.0 (Manzanita) but I get an error saying that libpython3.7m.a cannot be loaded and I can't find a solution.
First things first. I have to compile vim by myself because the vim installed by default has only +python and I have to use python3.
I cloned the git and, following several other suggestions found online I configure vim with
./configure --enable-cscope --enable-multibyte --enable-python3interp=dynamic --with-features=huge --with-python-config-dir=/home/mazzi/miniconda3/lib/python3.7/config-3.7m-x86_64-linux-gnu --with-tlib=ncurses --enable-fail-if-missing --prefix=/home/mazzi/.local
The prefix is due to the fact that I don't have root access and its output of can be found here. Please note that during the whole procedure I had to stay inside a conda environment, otherwise the configuration would fail saying that no python3 was found.
I then make, with this output, and make install with this other output.
I check vim version and everything seems ok.
Finally, I start vim normally (/home/mazzi/.local/bin is on the PATH, before the system paths, and the vim command points to ~/.local/bin/vim) and type :py3 pass but I get the following error:
E370: Could not load library libpython3.7m.a
E263: Sorry, this command is disabled, the Python library could not be loaded.
What can I do?
Additional info
Some of my sources:
https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source (without sudo and just to be clear I did not try YouCompleteMe due to some issues in the past that forced me to go to jedi-vim)
https://gist.github.com/hxhc/778d7c3a3ad491dedf3675a47275a979
Compiling vim 8.0 with Python 3 support resulting in SIGABRT
https://github.com/Valloric/YouCompleteMe/issues/2855#issuecomment-352181535

running Python commands on Atom

So I'm a new intern at a company and they gave me practically a blank computer. I needed to install some programs from their Git to run python and the only available python editors are Idle and Atom. I personally prefer atom, so I installed with the package "script" that should run python scripts. However I can't run python 3.4 and I get this error
" 'python' is not recognized as an internal or external command,
operable program or batch file."
Which I get since on cmd typing 'python' does not launch the python only typing 'py'. Since I am an intern I have no control over the Environmental variables so I can't change py command to python. How can I change atom script package to use "py" command instead of "python".
I solved it by going inscript 3.17.3 code:
script --> lib --> grammars --> python.coffee
In there I changed "command: 'python'" to "command: 'py'" for lines 3 and 7.
This should work for whatever command your windows batch uses to run python.

Flymake config error while opening python file but correctly setup flake

When I'm opening a python file in emacs I get the following error message:
Flymake: Configuration error has occured while running (flake8 >..../xyz_flymake.py). Flymake will be switched OFF.
But on the other hand it seems I've configured all the modules needed for elpy to work properly:
Elpy Configuration
Virtualenv........: None
RPC Python........: 3.5.3 (/usr/bin/python3.5)
Interactive Python: /usr/bin/python3.5 (/usr/bin/python3.5)
Emacs.............: 24.5.1
Elpy..............: 1.10.0
Jedi..............: 0.10.2
Rope..............: 0.10.5
Importmagic.......: 0.1.7
Autopep8..........: 0.1.7
Syntax checker....: flake8 (/usr/local/bin/flake8)
You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.
The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH.
Options
`Raised' text indicates buttons; type RET or click mouse-1 on a button
to invoke its action. Invoke [+] to expand a group, and [-] to
collapse an expanded group. Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.
How can I resolve this issue?
It is unclear what the configuration error is. It's possible that you're running into one of many issues.
You seem to want to use Python 3.5, but there's no clear indicator of what version of Python Flake8 is running on. It could be that elpy is detecting a mismatch and refusing to use Flake8 when it won't provide you any useful information. (Flake8 must be installed on the same version of Python that the code is intended to run on.)
Elpy seems insistent that you use a virtualenv or that you add ~/.local/bin/ to your PATH. I would advise doing both.
You can create a virtualenv by doing virtualenv ~/.elpy-venv and activate it with source ~/.elpy-venv/bin/activate.
You can edit your Shell's configuration file (e.g., ~/.bashrc, ~/.bash_profile, ~/.zshrc, etc.) to do export PATH="$PATH:~/.local/bin".

Configuring vim-airline: Bad math expression

I'm brand new to Vim and just trying to get setup with vim-airline. I'm using Pathogen to install and have followed the instructions provided. vim-airline is successfully cloned in ~/.vim/bundle/vim-airline.
When I try to add the required let g:airline_powerline_fonts = 1 instruction to my ~/.vimrc file I get the following error from the console when trying to source it:
bad math expression: ':' without '?'
I'm running vim 8.0.134 on macOS Sierra with zsh and oh-my-zsh.
Any ideas why this error is being thrown and how I can get around it?
It looks like you tried to run $ source ~/.vimrc in the shell?
I think you want to reload your vimrc file from within vim:
:source ~/.vimrc
Maybe you confused this with running $ source ~/.zshrc from the shell.

Resources