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.

Python unresolved import issue #1137

Closed

Description

Tomasz Chudzik (@chudytom) commented on Sun May 26 2019

Environment data

  • VS Code version: 1.34.0
  • Extension version (available under the Extensions sidebar): 2019.4.12954
  • OS and version: Windows 10 v. 1809
  • Python version (& distribution if applicable, e.g. Anaconda): 3.5.2 64-bit without Conda
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): I guess I have no venv set up.
  • Relevant/affected Python packages and their versions: Microsoft Python Language Server v. 0.2.86

Actual behaviour

I open VSCode in a root folder where all my code exists. Part of it looks like this:

  • workspaceRootFolder
    • .vscode
    • network
      • section_network_input.py
    • timepredictionslib
      • build
      • dist
      • timepredictionslib
        • Here in subfolders are all my classes in the module
    • .env

In the 'network' folder I have some script that I run straight from PowerShell whereas in 'timepredictionslib' I have my custom module where I store all reuasuable classes.

All code runs smooth when run by the Python interpreter, however when I disabled Jedi and switched to Microsoft Python Language Server I get the 'unresolved import' error
image

I already added the '.env' file with the following content:
PYTHONPATH=timepredictionslib

and added the file as python.envFile as was advised here:
microsoft/vscode-python#3840 (comment)

Also I added python.autoComplete.extraPaths as was proposed here:
#1099

But none of these helped. Do you guys have any idea what else I need to do for the Lanugage Server to discover my library?

One more thing. When I tried to update the first import presented in the attached screen it is then discovered by the Language Server and IntelliSense but not by Pylint and the Python interpreter:
image

Steps to reproduce:

If needed I will create a smaller project with similiar configuration and push it to GutHub.

Logs

Output for Python in the Output panel
image

settings.json for Python

image

Activity

  1. rdrey commented on May 29, 2019

    @rdrey

    I was just busy creating this repo to reproduce this issue: https://github.com/rdrey/langservtest

  2. chudytom commented on May 29, 2019

    @chudytom

    I just recreated the issue based on the original project with the same exact folder structure.
    https://github.com/chudytom/LangServerError
    However my guess is, that the library is somehow installed and that's why it's discovered byt the Python interpreter but the Language Server can't find it.

  3. jakebailey commented on May 29, 2019

    @jakebailey
    Member

    Are you using editable installs for those packages during development? (i.e. pip install -e . or setup.py develop)

    There are a set of known issues with editable installs. (See the editable-install issue label)

  4. chudytom commented on May 29, 2019

    @chudytom

    Yes, I used pip install -e a long time ago. Looks like it's still under effect. Is there any way I can still use my own develop library and the Python Language Server at the same time?

    When I looked through the issues with editable-install label the only recommendation I saw is to uninstall the library, but I guess I want be able to modify the library, then.

  5. rdrey commented on May 30, 2019

    @rdrey

    Yeah, our package is editable, too.

  6. jakebailey commented on Jun 7, 2019

    @jakebailey
    Member

    I'm going through all of these cases. For both of these test repos, you can set extraPaths in order to tell us more directories to consider as import roots.

    Rainer Dreyer (@rdrey)

    image

    Tomasz Chudzik (@chudytom)

    (There is no sectionnetwork in that repo so those get squiggled.)

    image

    I'm aware that there are issues when this is mixed with editable installs, but I'm just trying to narrow down what the solution is going to be at the moment (less strict imports vs configuration for extra roots).

  7. jakebailey commented on Jun 7, 2019

    @jakebailey
    Member

    At the moment, our current recommendation is to use the extraPaths configuration to point the LS to your import roots. See the new documentation here: https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings

    A fix to editable installs was merged in #1183 (v0.3.1+), and will be available in the daily download channel shortly (and stable likely after). To switch to this for testing, you can set:

    "python.analysis.downloadChannel": "daily"

    Inferring this information automatically is more difficult than it seems, but there is likely work that can be done on that front in the future.

  8. chudytom commented on Jun 10, 2019

    @chudytom

    I updated my repository to correct files included. https://github.com/chudytom/LangServerError
    Here I'm not able to make the Language Server working with any extraPaths.

    However with the new fix #1183 (it still needs to be combined with extraPaths) everything seems to work smooth. The working version of the Language Server is 0.3.3

    The new version can be installed by setting:
    "python.analysis.downloadChannel": "daily"
    and reinstalling the Language Server this way:
    microsoft/vscode-python#3977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editable-installspip editable installs / setup.py develop

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions