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 Resolution issue #3793
Comments
I'm not able to repro the problem as reported. I wonder if you have a corrupted Python install or a pip cache? After the failure, have you looked in the It looks like you're using Python 3.7. Do you happen to have any other version installed? If so, perhaps you can try your repro steps using a different interpreter version, like |
Thanks for getting back to me! Yeah, there is a I've switched to python 3.8.13 by using pyenv and tried the steps again, but no luck. |
When you say "no luck", do you mean that you can't repro the problem with 3.8.13? Or you're still seeing the error? |
Still the same error with 3.8.13. Pyright won't check site-packages under .venv. |
Sorry, but I don't have any good ideas here. I'm not able to repro the problem, and I don't have any good theories other than that there is something corrupt on your system. Do you have another computer or virtual machine where you could try to repro? Perhaps you can explore the If you open the project with VS Code (with Pylance or Pyright installed), do you see the same error in the IDE? If so, when you right-click on the error and choose "Go To Definition", where does it take you? |
I just tried on another laptop(MacBook) with python 3.9.7(installed via pyenv), and I'm having the same error as well. It doesn't check the I'm not using VS Code, but I can give it a try later! If I directly call python and try to import the library, it works fine in the python console. I wonder if there is any cases that pyright will ignore the folders when looking for site-packages? Thanks again for looking into this. I'll keep trying different methods to see if I can figure out a pattern. |
Are you sure that you're activating the local venv before running pyright? When pyright runs, it shell executes |
I'm pretty sure that I've activated my venv before running pyright. I tried to print out the sys.path from python3, and here is the output:
Looks like python3 is able to find site-packages in |
It looks like there's a discrepancy here. In the log from your earlier post, your search paths were configured to point to I think this is strong evidence that when you were running pyright earlier you hadn't activated your local venv, and that would explain the diagnostic output. |
The reason why those paths are different is that they were running from different laptop, and the earliest log is from I've go through my testing steps again, and here is the full output, hope that this can explain what I'm facing right now:
From the above logs, you can see that both |
Thanks for the additional information. Unfortunately, I'm still not able to repro it. We have extensive verbose logging in place when an import resolution fails completely, but we don't have similar logging in place for when the import resolution succeeds in finding a type stub but fails to find the corresponding source file. I've added additional verbose logging, and this will be included in the next release of pyright. That should help us with additional clues about why you're seeing this problem. |
The additional logging is included in pyright 1.1.266, which I just published. Please repro with the |
Thanks for your help again! Here is the new output:
|
If you look in the directory |
Nope, I didn't install |
The Here's the full script that pyright executes to extract the import os, os.path, sys
normalize = lambda p: os.path.normcase(os.path.normpath(p))
cwd = normalize(os.getcwd())
orig_sys_path = [p for p in sys.path if p != ""]
sys.path[:] = [p for p in sys.path if p != "" and normalize(p) != cwd]
import sys, json
json.dump(dict(path=orig_sys_path, prefix=sys.prefix), sys.stdout) Please paste this code into temp source file, then switch to the root directory of your project, and execute the script using |
Yeah the script print out
|
Very strange. And you're sure you activated this venv prior to running the script? I'm looking through the pyright code to see if I can come up with any other theories that might explain what you're seeing. The code first attempts to execute the script using You're the only person who has reported this issue. If this were a bug in pyright, I would have expected to have seen this issue reported before. That leads me to hypothesize that it's something specific to your system or the way it's configured. |
Sorry for the late reply. I was busy at work today. I just run the script with Yeah I agree that it might be something wrong on my machine, but I've tried a lot of different methods, and even switch laptop, but still can't get any ideas on why it is not working. I'm using |
I tried using |
Pyright is using node's OK, it's good to know this is an issue with I don't think there's anything pyright can do differently here, so I think you'll need to either switch to a compatible shell or find some workaround for zsh. |
I use
I expect a high percentage of Thanks for all your work, much appreciated! |
Got it. Thanks for the clarification. |
Thanks again @erictraut! I will figure out what's run on my |
Hi there,
I use the exact same way to create python venv in every projects. In some projects pyright is able to find those site-packages under venv folder, but some projects just doesn't work.
I did some experiments to see if I can find any pattern that why it works occasionally. Here is the steps I take:
From the logs, looks like pyright cannot find the venv packages.
However, I tried to source the venv from the other projects that has installed requests package as well:
pyright works perfectly with venv.
The only pattern I found is that every old venv I created before works fine, and every newly created venv doesn't work. I've been struggling in this for days.
Any ideas or suggestions are very appreciate!!!
The text was updated successfully, but these errors were encountered: