Python-language-server: Error on importing time

Created on 9 Mar 2019  路  29Comments  路  Source: microsoft/python-language-server

import time

This fails in the latest version of Language server

Screen Shot 2019-03-09 at 12 27 26 PM

Starting Microsoft Python language server.
[Info  - 10:59:43 AM] GetCurrentSearchPaths /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/bin/python 
[Info  - 10:59:43 AM] SearchPaths:
[Info  - 10:59:43 AM]     /private/var/folders/22/0kj01mp12l3dsd1vw9vhfs6c0000gn/T/gpd33mwx.z0b
[Info  - 10:59:43 AM]     /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7
[Info  - 10:59:43 AM]     /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/lib-dynload
[Info  - 10:59:43 AM]     /Users/donjayamanne/.pyenv/versions/3.7.0/lib/python3.7
[Info  - 10:59:43 AM]     /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/site-packages
[Info  - 10:59:43 AM]     /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python37.zip;/Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7;/Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/lib-dynload;/Users/donjayamanne/.pyenv/versions/3.7.0/lib/python3.7;/Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/site-packages;
[Info  - 10:59:43 AM]     /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/bin
[Info  - 10:59:47 AM] Microsoft Python Language Server version 0.2.16.0
[Info  - 10:59:47 AM] Initializing for /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/bin/python
[Info  - 12:20:37 PM] Reloading modules... 
[Info  - 12:20:40 PM] done.
[Info  - 12:20:40 PM] Analysis restarted.
bug imports P1

Most helpful comment

This needs to be reopened. I see this problem today - #1430

Version: 1.37.0 (user setup)
Commit: 036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8
Date: 2019-08-08T02:33:50.993Z
Electron: 4.2.7
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

All 29 comments

On my machine, it works fine:

image

Do you have any exceptions?

I think the /Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python37.zip;/Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7;/Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/lib-dynload;/Users/donjayamanne/.pyenv/versions/3.7.0/lib/python3.7;/Users/donjayamanne/.local/share/virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/site-packages;
i.e. unseparated paths are the problem. Old code separated paths itself. Basically part of https://github.com/Microsoft/python-language-server/issues/720

Absolutely no exceptions, reloaded VSC and started working again... Note while this failed everything else worked with the language server..

Most probably #700 then

I think I know whats wrong.
Came across this a number of times yesterday and today.
Today, import sys had the exact same problem.
Unfortunately the problem went away before I could grab any screenshots.

I think the problem is, the problems are listed before the module resolution completes.
Came across problems with import time, import sys
I think this can be quite confusing and annoying to users when there are underlines under such imports that are used and are standard.

Identified in version Microsoft Python Language Server version 0.2.23.0

@DonJayamanne - is is just a squiggle or completion is missing too? I think the problem is, the problems are listed before the module resolution completes. - I guess completion does work but we haven't updated the diagnostics?

Happened again for os, dataclass, etc...
Didn't check intellisense, will check next time it happens.
Screen Shot 2019-03-15 at 1 19 23 PM

Just replicated for import sys

  • No intellisense
  • See below

gotodef

Here are the logs:

##########Linting Output - flake8##########
Starting Microsoft Python language server.
[Info  - 1:15:48 PM] GetCurrentSearchPaths /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/bin/python 
[Info  - 1:15:48 PM] Python search paths:
[Info  - 1:15:48 PM]     /private/var/folders/22/0kj01mp12l3dsd1vw9vhfs6c0000gn/T/thmraoix.apg
[Info  - 1:15:48 PM]     /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7
[Info  - 1:15:48 PM]     /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/lib-dynload
[Info  - 1:15:48 PM]     /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7
[Info  - 1:15:48 PM]     /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/site-packages
[Info  - 1:15:48 PM] Configuration search paths:
[Info  - 1:15:48 PM]     /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python37.zip;/Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7;/Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/lib-dynload;/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7;/Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/lib/python3.7/site-packages;
[Info  - 1:15:48 PM]     /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/bin
[Info  - 1:15:53 PM] Microsoft Python Language Server version 0.2.23.0
[Info  - 1:15:53 PM] Initializing for /Users/donjayamanne/.virtualenvs/pythonVSCode-5rU-mS3t/bin/python
[Info  - 1:18:48 PM] Reloading modules... 
[Info  - 1:18:50 PM] done.
[Info  - 1:18:50 PM] Analysis restarted.
##########Linting Output - flake8##########
##########Linting Output - flake8##########
##########Linting Output - flake8##########
##########Linting Output - flake8##########
11,4,E,E999:SyntaxError: invalid syntax
12,1,E,E402:module level import not at top of file
13,1,E,E402:module level import not at top of file
##########Linting Output - flake8##########
11,4,E,E999:SyntaxError: invalid syntax
12,1,E,E402:module level import not at top of file
13,1,E,E402:module level import not at top of file
##########Linting Output - flake8##########
##########Linting Output - flake8##########
9,4,E,E999:SyntaxError: invalid syntax
10,1,E,E402:module level import not at top of file
11,1,E,E402:module level import not at top of file
13,1,E,E402:module level import not at top of file
14,1,E,E402:module level import not at top of file
##########Linting Output - flake8##########
9,7,W,W291:trailing whitespace
9,7,E,E999:SyntaxError: invalid syntax
10,1,E,E402:module level import not at top of file
11,1,E,E402:module level import not at top of file
13,1,E,E402:module level import not at top of file
14,1,E,E402:module level import not at top of file
##########Linting Output - flake8##########
9,1,F,F811:redefinition of unused 'sys' from line 8
##########Linting Output - flake8##########
##########Linting Output - flake8##########
9,3,E,E999:SyntaxError: invalid syntax
10,1,E,E402:module level import not at top of file
11,1,E,E402:module level import not at top of file
13,1,E,E402:module level import not at top of file
14,1,E,E402:module level import not at top of file
##########Linting Output - flake8##########
10,1,E,E402:module level import not at top of file
11,1,E,E402:module level import not at top of file
13,1,E,E402:module level import not at top of file
14,1,E,E402:module level import not at top of file
##########Linting Output - flake8##########

Set you "python.analysis.logLevel": "Trace", pretty please

Left it on, next time I see it i'll post more information. Try to retrace my steps.

Managed to replicate, though not sure when it stopped working, either way, here are the logs an other info:

  • Python Env - 3.7 (using PipEnv)
  • OS - Mac
  • import sys & import time not found
  • Screenshots
    Screen Shot 2019-03-18 at 9 53 23 PM
    Screen Shot 2019-03-18 at 9 53 27 PM
  • Logs
    Could not paste contents here as the log file is too large :(
    log.txt

I haven't been experiencing this issue lately.
Hence closing it, possible some changes in the latest versions have resolved this issue.

Its back, saw this a number of times today.
Screen Shot 2019-03-27 at 10 24 41 PM

Here are the logs:
logs.log

May be related. The following test is unpredictable. Sometimes sys is unresolved, sometimes it is compiled builtin but analysis is empty.

        public async Task File() {
            const string code = @"
import sys
sys.
";
            var uri = await TestData.CreateTestSpecificFileAsync("a.py", code);
            await CreateServicesAsync(PythonVersions.LatestAvailable3X, uri.AbsolutePath);
            var rdt = Services.GetService<IRunningDocumentTable>();
            var doc = rdt.OpenDocument(uri, null, uri.AbsolutePath);

            var analysis = await doc.GetAnalysisAsync(Timeout.Infinite);
            var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion);

            var completions = cs.GetCompletions(analysis, new SourceLocation(3, 5));
            completions.Should().HaveLabels("argv", "path", "exit");
        }

See also #779

Same problem with import sys.
Screen Shot 2019-03-31 at 10 35 52 AM

[Info  - 9:05:10 PM] Reloading modules...
[Info  - 9:05:12 PM] done.
[Info  - 9:05:12 PM] Analysis restarted.

is suspicious. Looks like something is detected and changed and modules getting reloaded triggering the issue.

Yes, looks like restart of analysis is the issue.

image

@AlexanderSher - I think https://github.com/Microsoft/python-language-server/pull/871 addressed this?

Yes

871

This needs to be reopened. I see this problem today - #1430

Version: 1.37.0 (user setup)
Commit: 036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8
Date: 2019-08-08T02:33:50.993Z
Electron: 4.2.7
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

I agree this needs to be re-opened. I have the problem as well. i am on the latest version of vscode on a mac.

@MikhailArkhipov

Same problem here. Apparently happening only in python native libs (sys, traceback, pdb, logging).

Version: 1.37.1
Commit: f06011ac164ae4dc8e753a3fe7f9549844d15e35
Date: 2019-08-15T16:16:34.800Z
Electron: 4.2.7
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 18.5.0

Same problem

If it happens after "analysis restarted", see #1156.

Still failing for me on "import sys"...
Reloading the window fixes it _sometimes_. Maybe #1156?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

astrowonk picture astrowonk  路  39Comments

luabud picture luabud  路  27Comments

dmayo77 picture dmayo77  路  49Comments

CaselIT picture CaselIT  路  66Comments

gramster picture gramster  路  100Comments