Skip to content

VS Code: Auto env activation fails due to faulty usage of "conda activate" and "conda run" #412

Closed

Description

@Zaubeerer

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

Install VS Code: https://code.visualstudio.com/download

pixi init, pixi add python=3.10 pytest a simplistic pixi project such as:

[project]
name = "simplistic_project"
version = "0.1.0"
description = "Add a short description here"
authors = ["zaubeerer"]
channels = ["conda-forge", "pytorch", "nvidia"]
platforms = ["linux-64"]

[tasks]

[dependencies]
python = "3.10.*"
pytest

Create a simplistic test_nothing.py:

def test_pass():
   pass

Manually select the pixi python executable as Python interpreter as described in #166 (comment), if it does not work automatically (see #411).

Refresh test discovery in the Testing Extension, which should fail with an error.

Issue description

As described in #411 and discussed on Discord Server, even after manual selection of the pixi python executable as Python interpreter, the tests are not discovered.

The reason for the malfunction is that VS Code attempts to activate the environment via conda activate ..., thus leading to an error as follows:

Error: Command failed: conda run -p {project_path}/.pixi/env
(...)
DirectoryNotACondaEnvironmentError: The target directory exists, but it is not a conda environment.

Expected behavior

VS Code should activate the pixi environment without using conda for:

  • creation of internal terminals
  • pytest test discovery in the Testing Extension

Further Information

IDE Information

I encountered this error on Microsoft WSL, using the following VS Code version:

Version: 1.83.1 (user setup)
Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
Date: 2023-10-10T23:48:05.904Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.23570

Activity

  1. added
    bug
    on Oct 25, 2023
  2. Zaubeerer commented on Oct 25, 2023

    @Zaubeerer
    Author

    @pavelzw, did you already find a solution for this error?

  3. Zaubeerer commented on Oct 25, 2023

    @Zaubeerer
    Author

    From a VS Code user perspective, I would say that fixing this issue is a must-have, while #411 and #166 are nice-to-have.

    I will watch this issue and reconsider using pixi, when there is a workaround or solution for this.

  4. ruben-arts commented on Oct 26, 2023

    @ruben-arts
    Contributor

    Hello @Zaubeerer, unfortunately am I unable to recreate your issue. For me I only had to do the things @pavelzw points out in #166 Which you clearly found as well. The conda run part is new to me. So I have a few questions:

    • Would it be possible you have some kind of conda extension for vscode installed?
    • Do you have a conda base environment active?
    • Which version of vs-code do you use?
      I hope we can figure it out!
  5. Zaubeerer commented on Oct 26, 2023

    @Zaubeerer
    Author

    That is great news!

    Thanks for following up so quickly 🙏

    Will check for those options again later today and let you know.

  6. Zaubeerer commented on Oct 27, 2023

    @Zaubeerer
    Author

    I removed all conda, mamba, micromamba and miniconda and now it works :)

    Hence, for now I am no longer blocked.

    However, I suggest to keep this issue open, because conda and pixi should be installable in parallel in my opinion.

    I will check, whether I can reinstall conda, mamba, etc. without reintroducing the error.

  7. Zaubeerer commented on Oct 29, 2023

    @Zaubeerer
    Author

    Installation of micromamba seemed not to introduce the buggy behavior I experienced before.

    I suggest to observe it for a while.

    At this point, it would seem to me that compatibility with micromamba would be sufficient

  8. Zaubeerer commented on Oct 29, 2023

    @Zaubeerer
    Author

    @ruben-arts, shall we somehow document this?

    Happy to contribute a small PR if you think that makes sense :)

  9. changed the title [-]VS Code: Automatic environment activation fails due to faulty usage of "conda activate"[/-] [+]VS Code: Auto env activation fails due to faulty usage of "conda activate" and "conda run"[/+] on Oct 29, 2023
  10. ruben-arts commented on Oct 29, 2023

    @ruben-arts
    Contributor

    We always love contributions, though I'm not sure what would be the proper place for this.

    I changed the title of this issue so it's easier to search for. Do you think that would be enough for now?

  11. Zaubeerer commented on Oct 30, 2023

    @Zaubeerer
    Author

    Yeah, I would probably have found it given the VS Code in the name. :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions