2

I'm trying to figure out how to get yapf to use my current conda environment when resolving imports. Basically, I just see a ton of the following errors:

physics.py|6 col 1 error| [import-error] Unable to import 'torch' 
physics.py|8 col 1 error| [import-error] Unable to import 'torch.autograd'

For autoformatting, my .vimrc currently just contains:

autocmd FileType python AutoFormatBuffer yapf

and yapf has been installed using pathogen. If using yapf is too much of a burden, is there some other autoformatter that works seamlessly with conda?

1 Answer 1

1

In general, vim still doesn't handle anaconda environments nicely. I don't know if you open vim from the terminal, after you activate the environment, or not, so it's hard to tell what's going on, but I will tell you what I do:

I use Neovim, and open it from the terminal after activating my environment. Inside init.vim (==.vimrc) I use the variable $CONDA_PREFIX to get to the environment directory. My pylint for example is set up like this:

let PYLINT = $CONDA_PREFIX
let PYLINT .= '/bin/pylint'

And I use PYLINT as the executable path for Neomake to run it on each save:

let g:neomake_python_mypylint_maker = {
    \ 'args': [
    \ '--output-format', 'text',
    \ '--reports', 'no',
    \ '--msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg}"',
    \ '--rcfile=/home/abeka/workspace/pylint.cfg'
    \ ],
    \ 'errorformat':
    \ '%A%f:%l:%c:%t: %m,' .
    \ '%A%f:%l: %m,' .
    \ '%A%f:(%l): %m,' .
    \ '%-Z%p^%.%#,' .
    \ '%-G%.%#',
    \ 'exe': PYLINT,
    \ 'postprocess': function('neomake#makers#ft#python#PylintEntryProcess'),
\ }

autocmd! BufWritePost ~/workspace/*/*.py Neomake mypylint

I hope this gives you enough data to tweak your settings accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.