neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
574 stars 51 forks source link

Unresolved import when using MPLS #108

Open arwtyxouymz opened 4 years ago

arwtyxouymz commented 4 years ago

It may be the problem of MPLS.

Problem

I'm using Pipenv for python virtual environment. Even I set the interpreter path correctly, MPLS says

[Python unresolved-import] [W] unresolved import 'package_name'

My settings

My global coc-settings.json

"languageserver": {
        "MPLS": {
            "command": "dotnet",
            "args": [
                "exec",
                "/home/ryutaro/Tools/python-language-server/output/bin/Debug/Microsoft.Python.LanguageServer.dll"
            ],
            "filetypes": ["python"],
            "initializationOptions": {
                "interpreter": {
                    "properties": {
                        "InterpreterPath": "/usr/bin/python3.7",
                        "DatabasePath": "/home/ryutaro/Tools/python-language-server/output/",
                        "Version": "3.7"
                    }
                },
                "testEnvironment": false,
                "analysisUpdates": true,
                "traceLogging": true,
                "asyncStartup": true
            }
        },
}

and my local .vim/coc-settings.json

{
  "python.pythonPath": "/home/ryutaro/.local/share/virtualenvs/temp-PGebZnn9/bin/python"
}

Step to reproduce

1. Create virtual environment by pipenv

$ pipenv --python 3.7
$ pipenv install numpy
$ pipenv shell

2. edit python file

$ nvim sample.py

3. Set interpreter path

:CocCommand

then, select current virtualenv's interpreter path.

Even after these settings, you will see like a picture below. Screenshot from 2019-10-21 18-42-33

RVCU commented 4 years ago

Hey I think you might need to set python.envFile in your settings.

python.envFile:Absolute path to a file containing environment variable definitions., default: "${workspaceFolder}/.env"

RonanMacF commented 4 years ago

Hi, just bumping this issue as am experiencing it myself, did anyone find a fix for it?

tm-schwartz commented 4 years ago

Steps to fix:

  1. Find project root if you do not already know it :CocInfo -> Workspace root
  2. Create .env file in workspace root
  3. add PYTHONPATH="/path/to/pythonx.x/site-packages" to .env
    • for example, mine is PYTHONPATH="/home/user/default/python3.8/site-packages"
  4. add autocmd FileType python let b:coc_root_patterns = ['.git', '.env'] to your init.vim

https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders