Search code examples
pythonvisual-studio-codecondaintellisensepyscipopt

VSCode autocomplete / hints not working for PySCIPopt (installed in conda env)


The problem:

VSCode is not showing me hints or autocomplete options for methods of objects from the pyscipopt library.

Minimal working example: To test that pysciopt is correctly installed, I wrote and ran following code:

from pyscipopt import Model
m = Model("test")
m.addVar()
m.printStatistics()

VSCode let me autocomplete "pyscipopt" and "Model" on the first line, as well as "Model" on the second line. However, it gave me no hints on 3rd and 4th line.

I ran the file via the "run python file" icon in upper right of the VSCode window, and it produced following output in the terminal:

SCIP Status        : problem creation / modification
Total Time         :       0.00
  reading          :       0.00
Original Problem   :
  Problem name     : test
  Variables        : 1 (0 binary, 0 integer, 0 implicit integer, 1 continuous)
  Constraints      : 0 initial, 0 maximal
  Objective        : minimize, 0 non-zeros (abs.min = 1e+20, abs.max = -1e+20)

Therefore, pyscipopt seems to be correctly installed and accessible to my python interpreter.

Extra details

I'm on windows 10.

I began by installing the miniforge anaconda env. manager. Then I created a new environment named SCIPopt, activated it, and then I installed the library by typing

conda install --channel conda-forge pyscipopt

I restarted VSCode and set "Python 3.12.2 ('SCIPopt') ~\miniforge-pypy3\envs\SCIPopt\python.exe" as my python interpreter. Before I had done that, running the minimal working example resulted in an error (no module named pyscipopt).

I also tried adding a settings.json file to my workspace with following contents:

{
    "python.pythonPath": "C:\\Users\\{my user name}\\miniforge-pypy3\\envs\\SCIPopt"
}

but that did not help.

When I mouse over the 'addVar()' method in the example, VSCode shows me the following hint: "(function) addVar : Any". Similarly with the other method I call.

When I right-click the "Model()" bit of code or one of the methods and select 'go to definition', I get a message saying 'no definition found for...'.

I also tried launching VSCode from the miniforge prompt with the SCIPopt environment activated, but that didn't help either.


Solution

  • We could found that model is belong to scip.pxd file.

    enter image description here

    enter image description here

    But currently Pylance does not support Cython. So it's not a bug, it's just that this feature is not currently supported, and the same is true for .pyd files.

    You could read these two issue on github for more details:

    Pylance could support Cython

    getting information from pyd files

    If you want, you could create a feature request for comments and upvotes in github discussions.