Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python.analysis.extraPaths feature still is not working #793

Closed
Alexander770 opened this issue Dec 31, 2020 · 12 comments
Closed

python.analysis.extraPaths feature still is not working #793

Alexander770 opened this issue Dec 31, 2020 · 12 comments
Labels
waiting for user response Requires more information from user

Comments

@Alexander770
Copy link

Environment data

  • Language Server version: latest
  • OS and version: windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9

Expected behaviour

Allows to import additional\custom modules and classes

Actual behaviour

Although the editor does not show/highlight any command the actual ModuleNotFoundError is issued during runtime

Logs

ModuleNotFoundError: No module named 'algo'

Code Snippet / Additional information

# module
.workspace/lib/algo/transform.py
import sys

class myclass:
    def __init__(self, x):
        self.x = x

    def mysum(self):
        print(self.x)

# executable
.workspace/src/test.py
from algo.transform import myclass
a = myclass(5)
@judej
Copy link
Contributor

judej commented Jan 4, 2021

Could you please send us your logs that show the exact version and also send us your settings.json so that we can see what the extrapaths is set to?

thanks

@judej judej added the waiting for user response Requires more information from user label Jan 4, 2021
@github-actions github-actions bot removed the triage label Jan 4, 2021
@adam-azarchs
Copy link

I am also seeing this. My settings.json has

{
    "python.analysis.extraPaths": [
        "${workspaceFolder}/lib/python"
    ]
}

Logs show

[Info  - 6:44:20 PM] Pylance language server 2020.12.2 (pyright 6feebac9) starting
[Info  - 6:44:20 PM] Server root directory: /home/adam.azarchs/.vscode-server/extensions/ms-python.vscode-pylance-2020.12.2/dist
[Error - 7:02:34 PM] stubPath /home/adam.azarchs/***/typings is not a valid directory.
[Info  - 7:30:41 PM] No configuration file found.
[Info  - 7:30:41 PM] Setting pythonPath for service "***": "/mnt/home/adam.azarchs/miniconda3/bin/python"
Search paths found for configured python interpreter:
  /home/adam.azarchs/miniconda3/lib/python3.7
  /home/adam.azarchs/miniconda3/lib/python3.7/lib-dynload
  /home/adam.azarchs/.local/lib/python3.7/site-packages
  /home/adam.azarchs/miniconda3/lib/python3.7/site-packages

@jakebailey
Copy link
Member

There's an unfortunate issue at the moment with the logs, where the extraPaths aren't printed due to them being provided to the analyzer differently; unfortunately that means they don't show up there.

@adam-azarchs I'm not sure your issue is related; this original issue is saying that "Pylance says my code is okay, but it crashes at runtime". Is that what you are experiencing?

@adam-azarchs
Copy link

It turns out my issue was due to pylance not expanding ${workspaceRoot}. So, never mind.

@jakebailey
Copy link
Member

Ah, workspaceRoot is one that isn't supported yet. #548 covers that, we support ${workspaceFolder} (not sure what the difference is yet; this support isn't complete.)

@jakebailey
Copy link
Member

@Alexander770 It's been a bit since you filed this without any updates; I'll close this for now. If you have more info about your config and your logs, we can reopen this to take a look.

@kerim371
Copy link

I'm experiencing the same problem. I'm expecting to see list of functions/variables when importing custom library but I can only see No suggestions.
I've tried setting python.analysis.extraPaths to full path/relative path but nothing helps. I've set this to both user settings and workspace setting without success (unlike this issue)

My workspace settings:

{
  "python.pythonPath": "C:\\Users\\tasik\\.julia\\conda\\3\\python.exe",
  "python.analysis.extraPaths": [
    "C:\\apps\\MyHighFive\\HFGt\\build-MSVC2019-Release\\Debug"
]
}

Few lines of user settings:

    "python.languageServer": "Pylance",
    "python.analysis.completeFunctionParens": true,
    "python.analysis.extraPaths": [
        "C:\\apps\\MyHighFive\\HFGt\\build-MSVC2019-Release\\Debug"
    ]

Windows 10, Pylance 2021.2.3, Python 3.8.5

@erictraut
Copy link
Contributor

extraPaths should always be specified relative to your workspace root directory. Is the custom library installed in your selected Python environment (I.e. the code is in site-packages), or is the code for this library within your workspace (in a subdirectory)? If it's the former, then Pylance should be finding it automatically. If it's the latter, then you should add a relative path to your extraPaths setting to point to it.

@Alexander770
Copy link
Author

Alexander770 commented Feb 21, 2021 via email

@kerim371
Copy link

@erictraut thank you for response.
My module is in workspace' subfolder. It is not in site-packages.
I just tried to set:

    "python.analysis.extraPaths": [
        "build-MSVC2019-Release\\Debug"
    ]

but didn't help. My module (.pyd binary) is in C:\\apps\\MyHighFive\\HFGt\\build-MSVC2019-Release\\Debug

@Alexander770 yes, but it is slower, I prefer vs code

@erictraut
Copy link
Contributor

Ah, then the problem has nothing to do with import resolution or extraPaths. Pylance is resolving the import to your ".pyd" file. However, Pylance does not attempt to extract any type information out of a binary file. Doing so would require loading and executing that file, which would be unsafe from a security standpoint. If you want Pylance to reason about the types in that library (including the names of functions, classes, etc.), you will need a Python type stub file (.pyi) for the library. Please contact the author of the library to see if a stub file is available. Increasingly, library authors are providing type information.

@kerim371
Copy link

@erictraut thank you for the information.
I will google what .pyi is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

6 participants