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

Import could not be resolved #3452

Closed
moi90 opened this issue Oct 9, 2022 · 4 comments
Closed

Import could not be resolved #3452

moi90 opened this issue Oct 9, 2022 · 4 comments
Labels
pep 660 Issues related to PEP 660 import hooks

Comments

@moi90
Copy link

moi90 commented Oct 9, 2022

Environment data

  • Language Server version: 2022.10.10
  • OS and version: Ubuntu 22.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10 (mambaforge)
  • python.analysis.indexing: false
  • python.analysis.typeCheckingMode: basic

Code Snippet

from experitur import Experiment, Trial

Expected behavior

Module is parsed correctly.

Actual behavior

Pylance shows an error: Import "experitur" could not be resolved

python executes the file normally.

Additional info

experitur is editable installed from a local git clone (pip install -e .). The weird thing is that other editable modules just have a venv/lib/python3.10/site-packages/__editable__.XXX.pth file which contains just the location. experitur, however, has two files (__editable___experitur_1_1_0_178_g937611e_dirty_finder.py and __editable__.experitur-1.1.0+178.g937611e.dirty.pth) and the .pth file seems to be actually a Python file. This seems to be the only difference between the working and non-working editable installs.

Putting the package root into python.analysis.extraPaths helps.

The only noteworthy entry in the Python Language Server log is:

[Info  - 8:58:34 PM] (490198) [BG(1)] Long operation: analyzing: /home/guest/sischr001/LOKI-Pipeline/experiments/zoomie2.py (2286ms)

(zoomie2.py is the file containing the import statement.)

@erictraut
Copy link
Contributor

Please refer to this documentation in the troubleshooting section.

@moi90
Copy link
Author

moi90 commented Oct 10, 2022

Thanks, I had success using the following command:

pip install -e . --config-settings editable_mode=compat

However, there is a warning:

The compat mode is transitional and will be removed in future versions of setuptools, it exists only to help during the migration period. Also note that support for this mode is limited: it is safe to assume that the compat mode is offered “as is”, and improvements are unlikely to be implemented. Users are encouraged to try out the new editable installation techniques and make the necessary adaptations.

So static analysis tools, like Pylance, need to adapt to these new-style editable installs, i.e. dynamic .pth files.

@debonte
Copy link
Contributor

debonte commented Oct 10, 2022

So static analysis tools, like Pylance, need to adapt to these new-style editable installs, i.e. dynamic .pth files.

Unfortunately PEP 660 was approved without discussion with the Python typing community. We cannot run import hooks. But there has been discussion about alternative ways to solve this problem. See this typing-sig thread. If a solution is found, agreed upon by typing-sig, and standardized, Pylance will consider supporting it.

Note that the strict mode in setuptools will not be removed any time soon. Also, setuptools plans to maintain support for "SETUPTOOLS_ENABLE_FEATURES="legacy-editable" for as long as pip allows legacy installs."

@judej judej closed this as completed Oct 10, 2022
@moi90
Copy link
Author

moi90 commented Oct 11, 2022

Thanks for the explanation and the references. You're doing good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pep 660 Issues related to PEP 660 import hooks
Projects
None yet
Development

No branches or pull requests

4 participants