Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Unresolved import for builtin packages after reload #1156

Closed

Description

Marc Schlaich (@schlamar) commented on Mon Jun 03 2019

Environment data

  • VS Code version: 1.34.0
  • Extension version (available under the Extensions sidebar): 2019.5
  • OS and version: Windows 7
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A

Expected behaviour

No errors for builtin packages.

Actual behaviour

Import of builtin packages like time, itertools and operator are sometimes marked as unresolved import.

Steps to reproduce:

Don't know, this happens randomly.

Logs

Starting Microsoft Python language server.
##########Linting Output - flake8##########
[Info  - 12:19:26] GetCurrentSearchPaths C:\Python27\python.exe 
[Info  - 12:19:26] Python search paths:
[Info  - 12:19:26]     c:\python27\dlls
[Info  - 12:19:26]     c:\python27\lib
[Info  - 12:19:26]     c:\python27\lib\lib-tk
[Info  - 12:19:26]     c:\python27
[Info  - 12:19:26]     c:\python27\lib\site-packages
[Info  - 12:19:26] Configuration search paths:
[Info  - 12:19:26]     ...
[Info  - 12:19:33] Microsoft Python Language Server version 0.2.87.0
[Info  - 12:19:33] Initializing for C:\Python27\python.exe

(Right now, I don't have a Console Log in case of this error. I will submit them as soon as this happens again.)

Activity

  1. thernstig commented on Jun 5, 2019

    @thernstig

    This happens to our project as well, e.g. for the sys module, but other modules work just fine. Example of our imports:

    from __future__ import (absolute_import, division, generators, nested_scopes,
                            print_function, with_statement)
    
    import os
    import re
    import subprocess
    import sys

    I am using the language server (i.e this is our setting "python.jediEnabled": false,).

    As it is quite a basic functionality to be able to get IntelliSense for builtin packages it hampers development speed by quite a bit.

  2. johnybx commented on Jun 9, 2019

    @johnybx

    Same problem with python 3.6. I do not really think that this problem is related to python version though I did not test all versions. I noticed this problem after using

    "python.autoComplete.extraPaths": [ "${workspaceFolder}/src" ],
    and using autosave with autopep8 few times (seem like some pep8 formating must occure but not sure). Simple folder structure:

    root/
        \_env
        \_src
        \_.vscode
    

    Before the problem occurs all autocomplete functions works well. After the problem sys, time and other builtin packages are unrecognized.

    Edit:
    Seem to happen always just after python log [Info - 7:16:23 PM] Reloading modules... which seem to happen always if autopep8 makes some changes to files.]

    Edit2:
    I tried to disable autopep8 and instead tried to use this macro:

            "saveAndLintFile": [
                "workbench.action.files.save",
                {"command": "runInTerminal.run", "args": {"cmd": "/usr/bin/env autopep8 -i --max-line-length 120 \"${file}\"", "match": ".*"}},
                "workbench.action.files.save"
            ]
        }
    

    using runInTerminal and macros which seem to work fine and sys does not throw unresolved import . Also language server was not reloaded which seem to be related. In trace log from language server first run analyses shows Analysis of sys(CompiledBuiltin) queued but when reload occurs no builtin are analyzed even though other packages seem to be analyzed again.

  3. jakebailey commented on Jun 10, 2019

    @jakebailey
    Member

    Interesting. The reloading is due to our file watcher detecting changes on disk to reload files (for package installation and so on, see also #1076 for the issue on improving that mechanism).

    It might be the case that when we go reload modules, some builtins are getting lost.

  4. jakebailey commented on Jun 10, 2019

    @jakebailey
    Member

    johnybx Also, we'd appreciate it if you could try the daily build, which includes a few race fixes among other things that we think could have fixed the missing builtins issues:

    "python.analysis.downloadChannel": "daily"
  5. johnybx commented on Jun 11, 2019

    @johnybx

    Jake Bailey (@jakebailey) I already tried

    "python.analysis.downloadChannel": "daily"
    

    but it did not resolve this issue.

  6. need47 commented on Jun 11, 2019

    @need47

    I have the same issue with builtin 'sys' and 'time', and I tried the daily build. It did not help. Python version is 3.7.3. So it's not limited to 2.7.

  7. pcolmer commented on Jun 12, 2019

    @pcolmer

    I'm occasionally hitting this problem. I'm currently running 1.36.0-insider. I'm developing against a folder opened inside a container.

    Version: 1.36.0-insider (user setup)
    Commit: f291714906cdcb02830b8cfe2485a3c23415b5fe
    Date: 2019-06-12T05:19:53.054Z
    Electron: 4.2.3
    Chrome: 69.0.3497.128
    Node.js: 10.11.0
    V8: 6.9.427.31-electron.0
    OS: Windows_NT x64 10.0.17763
    
    Starting Microsoft Python language server.
    ##########Linting Output - flake8##########
    Downloading https://pvsc.azureedge.net/python-language-server-stable/Python-Language-Server-linux-x64.0.2.96.nupkg... complete
    Unpacking archive... done
    [Info  - 13:08:17] Analysis cache path: /root/.cache/Microsoft/Python Language Server
    [Info  - 13:08:17] GetCurrentSearchPaths /usr/bin/python3 
    [Info  - 13:08:17] Python search paths:
    [Info  - 13:08:17]     /usr/lib/python3.6
    [Info  - 13:08:17]     /usr/lib/python3.6/lib-dynload
    [Info  - 13:08:17]     /usr/local/lib/python3.6/dist-packages
    [Info  - 13:08:17]     /usr/lib/python3/dist-packages
    [Info  - 13:08:17] Configuration search paths:
    [Info  - 13:08:17]     /usr/local/lib/ea-lib
    [Info  - 13:08:18] Microsoft Python Language Server version 0.2.96.0
    [Info  - 13:08:18] Initializing for /usr/bin/python3
    [Info  - 13:08:25] Reloading modules... 
    [Info  - 13:08:25] done.
    [Info  - 13:08:25] Analysis restarted.
    
    {
    	"resource": "/workspaces/exit-automation/bamboo.py",
    	"owner": "_generated_diagnostic_collection_name_#0",
    	"code": "unresolved-import",
    	"severity": 4,
    	"message": "unresolved import 'sys'",
    	"source": "Python",
    	"startLineNumber": 20,
    	"startColumn": 8,
    	"endLineNumber": 20,
    	"endColumn": 11
    }
    
  8. jakebailey commented on Jul 15, 2019

    @jakebailey
    Member

    Now that I've fixed the path watcher to watch the correct things, I've observed this happening for some libraries, in my case array and itertools. When the reload happens, it seems like some modules are getting lost. Needs testing.

  9. changed the title [-]Unresolved import for builtin packages (Python 2.7)[/-] [+]Unresolved import for builtin packages after reload[/+] on Jul 15, 2019
  10. jakebailey commented on Aug 7, 2019

    @jakebailey
    Member

    This might have been fixed in #1402. See also #1345.

  11. johnybx commented on Aug 15, 2019

    @johnybx

    Jake Bailey (@jakebailey) Problem still occurs - builtin packages are unresolved after reload of language server.

  12. johnybx commented on Aug 19, 2019

    @johnybx

    Alexander Sher (@AlexanderSher) Jake Bailey (@jakebailey) still occurs in Microsoft Python Language Server version 0.3.47.0.

  13. MikhailArkhipov commented on Aug 19, 2019

    @MikhailArkhipov

    Changes are not in stable feed yet. "python.analysis.downloadChannel": "daily" is 0.3.59. We do not push builds with large changes into stable immediately, so when an issue is closed, it does not mean the fix shows up in stable next day.

  14. pcolmer commented on Aug 20, 2019

    @pcolmer

    when an issue is closed, it does not mean the fix shows up in stable next day.

    That is certainly a good point to make but, as someone who does use the stable build, I get frustrated by the following:

    1. The comment in Merges from db #1446 says "may fix Unresolved import for builtin packages after reload #1156) (my emphasis on "may").

    2. There isn't any clarification from the PR/merge process as to which version of Python Language Server PR#1446 is getting merged into, so people using the stable build don't know which version to keep an eye out for.

    3. Given the "may" ... perhaps the issue ought to be left open until it is definite that Unresolved import for builtin packages after reload #1156 is fixed by that PR?

  15. 8 remaining items

  16. jakebailey commented on Aug 26, 2019

    @jakebailey
    Member

    Is it possible to do more with the Releases feature in GitHub in that respect? Presumably a build takes a specific point in time in the git history and therefore that could be tagged with the version assigned by the build?

    At the moment, the version numbers aren't "true" semver; the last number is actually just a build number we trigger manually (versions may skip or repeat commits). Improving this is something that'd be good once we're more stable.

  17. added a commit that references this issue on Aug 29, 2019
    5004050
  18. jakebailey commented on Sep 3, 2019

    @jakebailey
    Member

    We believe this to be fixed. We'd appreciate if anyone with this issue could try out the beta and see if the issue goes away.

    "python.analysis.downloadChannel": "beta"
  19. anatolyburakov commented on Sep 4, 2019

    @anatolyburakov

    Jake Bailey (@jakebailey) i am experiencing this with RemoteSSH connection. The above line doesn't appear to work (the line in the config is dimmed, as if the option does not exist), so i can't test with the beta/daily version. I am using VSCode Insiders build. How do i get the latest Python extension?

  20. jakebailey commented on Sep 4, 2019

    @jakebailey
    Member

    The option is not documented, which is why VS Code does not think it exists. If you set beta and reload, the extension should download an updated copy. Beta is currently 0.3.72.

    The language server and the extension are versioned separately; you don't need to get the latest extension in order to get the latest language server.

  21. anatolyburakov commented on Sep 5, 2019

    @anatolyburakov

    Jake Bailey (@jakebailey) i believe the issue is fixed for me, thanks! at least i haven't seen any problems so far.

  22. jonathanwall commented on Sep 13, 2019

    @jonathanwall

    We believe this to be fixed. We'd appreciate if anyone with this issue could try out the beta and see if the issue goes away.

    "python.analysis.downloadChannel": "beta"

    this fixed it for me so far

  23. jakebailey commented on Sep 13, 2019

    @jakebailey
    Member

    The fix is now out in stable, so you don't need to set this variable to get this fix (though we always like testers).

  24. noamsto commented on Oct 24, 2019

    @noamsto

    Alexander Sher (@AlexanderSher) I'm still seeing this issue with 'itertools' import under centos, is it a known problem?
    Sys info:
    OS: CentOS Linux release 7.7.1908
    Code: 1.39.2
    Python: 2.7.16 (also on 2.7.5)
    Python-language-server: 0.4.71.0
    image

  25. jakebailey commented on Oct 24, 2019

    @jakebailey
    Member

    Unless this occurs only after a reload (package install), then it's likely not related to this old issue. I'd appreciate it if you could file a new issue with your info.

  26. added 2 commits that reference this issue on Nov 1, 2019
    db59a31
    55f999c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions