microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 766 forks source link

Autocomplete unavailable on some module #2520

Closed CZJLe9tt closed 2 years ago

CZJLe9tt commented 2 years ago

Environment data

Expected behaviour

I use from gurobipy import * to import a module named Gurobi(a math programming solver), but Pylance doesn't identify its functions and hence Autocomplete doesn't work.

When I switch python language server to Jedi, the problem disappeared. If it occurs because of lack of support for some modules?

Actual behaviour

Several warnings at the module's functions, such as: "Model" is not defined "GRB" is not defined

judej commented 2 years ago

Thanks for the report, unfortunately, this is not enough data for us to debug.

Would you please add the information in the report as described in the troubleshooting guide?

CZJLe9tt commented 2 years ago

My "settings.json" about python

    "python.analysis.extraPaths": [
        "/Users/x/miniconda3/lib/python3.7/site-packages",
        "/Users/x/miniconda3/pkgs"
    ],
    "python.analysis.logLevel": "Trace"

Code example

from gurobipy import *

try:
    m = Model()

    x = m.addVar(vtype=GRB.BINARY, name='x')
    y = m.addVar(vtype=GRB.BINARY, name='y')
    z = m.addVar(vtype=GRB.BINARY, name='z')

    m.setObjective(x+y+2*z, GRB.MAXIMIZE)

    m.addConstr(x+y >= 1, 'c1')

    m.optimize()

    for v in m.getVars():
        print(v.varName, v.x)

    print(m.objVal)

except GurobiError as e:
    print('Error code' + str(e.errno) + ':' + str(e))

except AttributeError:
    print('Encountered an attribute error')

Environment

Python version: 3.7.9 Virtual environment: Miniconda Files attached: environment_requirements.zip

Log

log.txt

heejaechang commented 2 years ago

@build960o that is because the package has compiled module that we currently don't support due to various reasons. Jedi can handle it since it loads that compiled module and inspects it which we currently avoid since we don't want to run random modules on users machine.

but we do ship with a script that let you generate stubs from compiled module if you want to. if you look at your pylance extension folder, there should be scrape_module.py (ex, ms-python.vscode-pylance-2022.4.1\dist\scripts\scrape_module.py),

you can manually run that script to generate stub file, that you can put inside of typing folder so we can pick it up.

thank you

heejaechang commented 2 years ago

I am closing it as "by design"