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

.pth files seem to be ignored in the venv site-packages directory #1520

Closed
ipkiss42 opened this issue Feb 21, 2021 · 9 comments
Closed

.pth files seem to be ignored in the venv site-packages directory #1520

ipkiss42 opened this issue Feb 21, 2021 · 9 comments
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request

Comments

@ipkiss42
Copy link

Describe the bug
.pth files seem to be ignored in the venv site-packages directory

To Reproduce
In <venv>/lib/pythonX.Y/site-packages, run the following commands:

mkdir bar
touch bar/__init__.py
echo bar > bar.pth

Then simply use import bar in a python file and run pyright

Expected behavior

No error

Screenshots or Code

$ pyright --verbose
Loading configuration file at /tmp/pyright2/root/pyrightconfig.json
Assuming Python version 3.8
Assuming Python platform Linux
No include entries specified; assuming /tmp/pyright2/root
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding .git
venv python3.8 subdirectory not found in venv path /tmp/pyright2.
stubPath /tmp/pyright2/root/typings is not a valid directory.
Searching for source files
Found 1 source file
Could not import 'bar' in file '/tmp/pyright2/root/src/foo/__init__.py'
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/tmp/node_modules/pyright/dist/typeshed-fallback/stdlib'
  Typeshed path not found
  Looking in stubPath '/tmp/pyright2/root/typings'
  Attempting to resolve using root path '/tmp/pyright2/root/typings'
  Looking in root directory of execution environment '/tmp/pyright2/root/src'
  Attempting to resolve using root path '/tmp/pyright2/root/src'
  Looking in python search path '/tmp/python-3.8/lib/python3.8'
  Attempting to resolve using root path '/tmp/python-3.8/lib/python3.8'
  Attempting to resolve using root path '/tmp/python-3.8/lib/python3.8'
  Looking in python search path '/tmp/python-3.8/lib/python3.8/lib-dynload'
  Attempting to resolve using root path '/tmp/python-3.8/lib/python3.8/lib-dynload'
  Attempting to resolve using root path '/tmp/python-3.8/lib/python3.8/lib-dynload'
  Looking in python search path '/tmp/python-3.8/lib/python3.8/site-packages'
  Attempting to resolve using root path '/tmp/python-3.8/lib/python3.8/site-packages'
  Attempting to resolve using root path '/tmp/python-3.8/lib/python3.8/site-packages'
  Looking for typeshed path
  Looking for typeshed stubs path
  Typeshed path not found
/tmp/pyright2/root/src/foo/__init__.py
  1:8 - error: Import "bar" could not be resolved (reportMissingImports)
1 error, 0 warnings, 0 infos
Completed in 0.525sec

VS Code extension or command-line

$ pyright --version
pyright 1.1.109

Additional context
My undersanding from https://docs.python.org/3/library/site.html is that the .pth file should be processed.

@jakebailey
Copy link
Member

jakebailey commented Feb 21, 2021

See also microsoft/pylance-release#78 microsoft/pylance-release#78 (comment)

Editable installs / pth files work, so long as the they add is outside the workspace.

@erictraut
Copy link
Collaborator

More importantly, refer to #1473

@jakebailey
Copy link
Member

Ah, yes, they appear to be using the venv setting, which does not use python calls to get search paths. I bet it'd work via normal interpreter paths.

@ipkiss42
Copy link
Author

Thanks for the quick responses and the pointers!

You are right, I was using a venv (outside of the workspace). After removing it and hacking $PATH to point to the same Python instance, the error disappeared.

Unfortunately, I don't think I can use the same workaround as in #1473 (select the interpreter "globally") because I have to use different venvs for different execution environments.

@erictraut erictraut added addressed in next version Issue is fixed and will appear in next published version and removed needs decision labels Feb 23, 2021
@erictraut
Copy link
Collaborator

I've added support for ".pth" files, so this will work in the next release.

@erictraut
Copy link
Collaborator

This is addressed in Pyright 1.1.114, which I just published. It will also be in the next release of Pylance.

@ipkiss42
Copy link
Author

Awesome, thank you!

@ipkiss42
Copy link
Author

ipkiss42 commented Mar 3, 2021

Sorry for not trying it out earlier, but I still have the same issue with Pyright 1.1.117 (using a venv pointing outside the workspace).

Was that use case supposed to be fixed by the changes in version 1.1.14?

@erictraut
Copy link
Collaborator

If you think that the ".pth" file support isn't working in your case, please file a new bug with logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants