Skip to content

Python lsp not resolving packages in venv #2050

Closed

Description

@jscheel

For the last two releases the python lsp is not properly picking up packages in my venv.

Functionally, this manifests in errors like Error [15:6] Import "dotenv" could not be resolved showing up in certain tool calls. This was not a problem on earlier releases.

Just grabbed 0.5.6, as I saw that it had a fix for a bug around this (#1994), but the issue persists.

Happy to provide any debugging necessary!

Activity

  1. changed the title [-]Python lsp not detecting packages in venv[/-] [+]Python lsp not resolving packages in venv[/+] on Aug 18, 2025
  2. rekram1-node commented on Aug 18, 2025

    @rekram1-node
    Collaborator

    hmm I am gonna look into this and try to replicate

  3. self-assigned this
    on Aug 18, 2025
  4. rekram1-node commented on Aug 18, 2025

    @rekram1-node
    Collaborator

    I am assuming this is default behavior right? this isn't due to a custom lsp config

    are you using uv?

  5. jscheel commented on Aug 18, 2025

    @jscheel
    ContributorAuthor

    afaik I don't have any special lsp config. I am definitely using uv though.

  6. rekram1-node commented on Aug 18, 2025

    @rekram1-node
    Collaborator

    cool, I will try to replicate

    Edit: Managed to replicate

  7. rekram1-node commented on Aug 18, 2025

    @rekram1-node
    Collaborator

    Ik the issue! @jscheel I will make a more elegant solution but for the time being if you set:

    title="pyrightconfig.json"

    {
      "venvPath": ".",
      "venv": ".venv"
    }

    at the root of your project it should be fixed

  8. rekram1-node commented on Aug 18, 2025

    @rekram1-node
    Collaborator

    I will get a patch out for this later tonight most likely, will be in one of the next releases

  9. jscheel commented on Aug 18, 2025

    @jscheel
    ContributorAuthor

    @rekram1-node just stepped away from my computer, but I'll give it a try shortly. Thank you!

  10. rekram1-node commented on Aug 18, 2025

    @rekram1-node
    Collaborator

    if it doesnt just lmk the patch needs to be sophisticated anyway cause not everyone has it in .venv

  11. jscheel commented on Aug 19, 2025

    @jscheel
    ContributorAuthor

    @rekram1-node seems to fix it for me 👍 Thanks!

  12. rekram1-node commented on Aug 31, 2025

    @rekram1-node
    Collaborator

    should be fixed in next release, I got busy and got to this much later than I wanted to

  13. drorata commented on Oct 18, 2025

    @drorata

    I am a new user of opencode, and I get the following error/warning:

    Error [2:8] Import "typer" could not be resolved
    

    and co. I am using version 0.15.7 and the virtual environment is .venv/. What am I missing? It seems like opencode fails to find/see the virtual environment.

  14. rekram1-node commented on Oct 18, 2025

    @rekram1-node
    Collaborator

    @drorata does that config thing I mentioned above fix it?

    If not you can disable the python lsp for now put the following in your opencode.json:

    {
    “pyright”: {
    disabled: true

    }}

    pardon my horrible json im typing on phone haha so just make that valid json and itll work^^

  15. drorata commented on Oct 19, 2025

    @drorata

    I tried to place either of the following in opencode.json:

    {
        "venvPath": ".",
        "venv": ".venv"
    }

    and

    {
        "pyright": {
            "disabled": true
        }
    }

    In both cases I got the following error:

    Error: Config file at /Users/foo/bar/opencode.json is invalid
    ↳ Unrecognized keys: "venvPath", "venv"
    
  16. rekram1-node commented on Oct 19, 2025

    @rekram1-node
    Collaborator

    @drorata in opencode.json:

    {
      "lsp": {
        “pyright”: {
           "disabled": true
        }
      }
    }
    

    The other reply was about pyrightconfig.json:

    #2050 (comment)

  17. drorata commented on Oct 20, 2025

    @drorata

    I'm sorry for the noise -

    I didn't change anything, but now it seems to be OK even without the config. I'm still getting a little confused here though... It seems like opencode fails to identify the right environment and I get the following error:

    Shell Check the help output to confirm the --debug flag is added
    
    $ cd /Users/foo/bar && python main.py --help
    Traceback (most recent call last):
      File "/Users/drorata/dev/humaintain/vimeo_manage/main.py", line 3, in <module>
        import typer
    ModuleNotFoundError: No module named 'typer'
    

    It should have tried something like:

    source .venv/bin/activate && python main.py --help
    

    because I'm using venv.

  18. rekram1-node commented on Oct 20, 2025

    @rekram1-node
    Collaborator

    hmm ill look into that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions