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

Python unresolved import issue #1137

Closed
DonJayamanne opened this issue May 28, 2019 · 8 comments · Fixed by #1183
Closed

Python unresolved import issue #1137

DonJayamanne opened this issue May 28, 2019 · 8 comments · Fixed by #1183
Assignees
Labels
editable-installs pip editable installs / setup.py develop
Milestone

Comments

@DonJayamanne
Copy link

@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

@rdrey
Copy link

rdrey commented May 29, 2019

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

@chudytom
Copy link

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.

@jakebailey
Copy link
Member

jakebailey commented May 29, 2019

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)

@chudytom
Copy link

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.

@jakebailey jakebailey added the editable-installs pip editable installs / setup.py develop label May 29, 2019
@rdrey
Copy link

rdrey commented May 30, 2019

Yeah, our package is editable, too.

@jakebailey
Copy link
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.

@rdrey

image

@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).

@jakebailey
Copy link
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.

@jakebailey jakebailey self-assigned this Jun 7, 2019
@jakebailey jakebailey added this to the June 2019.1 milestone Jun 7, 2019
@chudytom
Copy link

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editable-installs pip editable installs / setup.py develop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants