I want to set PYTHONPATH and python interpreter according to projects I am working on. I am working both on projects involving python 2.0, and ones involving python 3.0.

There is the concept of workspaces in coc, but I don't really understand it. What happens is that it asks me for interpreter every time I open the same file. (It asks in menu and after I pick a suitable choise it is OK)

So, how should I do it? i.e. is there a configuration file for a project(where is it located, what to write) ? can it identify the use of print "asdas" vs print("asdaa") and thus determine the python version? How do you handle this problem?

  • An outside-of-vim solution would be to use virtual environments.
    – D. Ben Knoble
    Aug 10, 2019 at 18:26
  • Your question as it stands is probably too broad... Can you please include what you have tried and why it didn't work as you expected? What kind of Python projects are you working on, are you writing Python modules or web apps? Are you already using some kind of virtual environment manager for Python, and if so, which? What are the details of your environment (OS, Python version, NeoVim version, other relevant information)?
    – filbranden
    Aug 11, 2019 at 3:25
  • When you say "it asks me for the interpreter every time I open the same file", how does it ask you for that information, with a prompt? Or a menu? Does answering a specific option result in a successful setup, are you just trying to make that choice permanent? Or make it permanent for a specific project?
    – filbranden
    Aug 11, 2019 at 3:27
  • I tried to be more specific. I didn't try anything yet, though I am thinking of writing some code in which it could determine the version by hints(/list maybe). It just seems like a too common situation. I want to make the choice permanent for a certain file/workspace.
    – eyal karni
    Aug 13, 2019 at 15:02
  • 1

1 Answer 1


Well, I don't know if it suffices.

run :CocConfig and set there

"python.envFile" : "/Users/username/.config/coc/env"

the file looks like PYTHONPATH= string

Plus I have this code:

nmap <leader>s3  :call coc#config('python', {'jediEnabled': v:false, 'pythonPath': '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3'})<CR>:CocRestart<CR>
nmap <leader>s2  :call coc#config('python', {'jediEnabled': v:false, 'pythonPath': '/Library/Frameworks/Python.framework/Versions/2.7/bin/python'})<CR>:CocRestart<CR>

Notice that interestingly, this setting overrides the choice of an interpreter in setinterpreter command.

One can think about replacing the content of the env file when changing environments. Haven't done so yet.

Your Answer

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

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