Skip to content

Add better way to do editable python install in project #524

Closed

Description

@pavelzw

Problem description

Related to #175

Currently, the only way to do an editable install of a python project with pixi is to have something like

[tasks]
postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ."

in your pixi.toml.

This is not really nice since your environment is not "ready to use" after pixi install but only after pixi install && pixi run postinstall.

Activity

  1. baszalmstra commented on Nov 30, 2023

    @baszalmstra
    Contributor

    Maybe it would be nice to implement something similar to Lifecycle Scripts in yarn and npm.

  2. srilman commented on Feb 4, 2024

    @srilman

    +1 I was initially confused by the examples, since postinstall is the same name used in yarn/npm. Happy to contribute given a little advice!

  3. pavelzw commented on Feb 6, 2024

    @pavelzw
    CollaboratorAuthor

    Also being able to install wheels in some form using rip would be nice for my production use case:

    I'm currently using this workaround (with the annoyance that pip is still in my prod environment):

    [project]
    name = "my-project"
    channels = ["conda-forge"]
    platforms = ["osx-arm64", "osx-64", "linux-64", "linux-aarch64"]
    
    [dependencies]
    python = ">=3.12"
    
    [host-dependencies]
    pip = "*"
    
    [feature.test.dependencies]
    pytest = ">=6"
    [feature.test.tasks]
    test = "pytest"
    
    [feature.build.dependencies]
    python-build = "*"
    setuptools = ">=61"
    setuptools-scm = "*"
    [feature.build.tasks]
    postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ."
    build-wheel = "python -m build --no-isolation --wheel ."
    
    [feature.prod.tasks]
    postinstall-production = "pip install --no-deps --disable-pip-version-check dist/my_project-*.whl"
    
    [environments]
    default = ["test", "build"]
    build = ["build"]
    prod = ["prod"]
    FROM ubuntu:22.04 AS build
    
    RUN apt update && apt install -y curl git
    RUN curl -Ls "https://github.com/prefix-dev/pixi/releases/latest/download/pixi-$(uname -m)-unknown-linux-musl" \
        -o /usr/local/bin/pixi \
        && chmod +x /usr/local/bin/pixi
    COPY . /app
    WORKDIR /app
    RUN pixi run -e build build-wheel
    RUN pixi install -e prod
    RUN pixi run -e prod postinstall-production
    RUN pixi shell-hook -e prod > /shell-hook
    RUN echo "python -m my_project" >> /shell-hook
    
    FROM ubuntu:22.04 AS production
    
    COPY --from=build /app/.pixi/envs/prod /app/.pixi/envs/prod
    COPY --from=build /shell-hook /shell-hook
    WORKDIR /app
    ENTRYPOINT ["sh", "/shell-hook"]
  4. ruben-arts commented on Feb 6, 2024

    @ruben-arts
    Contributor

    @srilman This isn't really a simple issue, we're working hard on improving our rip library to support more features. But if you really want to help you should be following the work we're doing there!

  5. srilman commented on Feb 6, 2024

    @srilman

    @ruben-arts Thanks for the advice! Correct me if I'm wrong, but I don't see how rip is related? Assuming that pixi implements something similar to Lifecycle Scripts from npm or yarn, we could execute any arbitrary shell command, not just pip install .... So the workflow when running pixi install would be:

    • Do all the current actions of pixi install
    • If a postinstall task is defined, then run pixi run postinstall
    • Otherwise, exit
  6. ruben-arts commented on Feb 7, 2024

    @ruben-arts
    Contributor

    Ah sorry I though it was specifically a request for the pip install --no-build-isolation --no-deps --disable-pip-version-check -e . command. I also like bas' proposal for the lifecycle scripts. Feel free to give it a try.

    We changed the logic so much in the last few PR's that I'm not sure what the best strategy is but reusing as much as you can from the src/cli/run.rs is probably important to keep it simple. @baszalmstra do you have some design tips?

    For the commands I would start with only postinstall and see how we can implement this the best we can before we implement the logic in more places.

  7. Emsu commented on Feb 23, 2024

    @Emsu

    For those of us needing editable installs, is the official recommendation to wait for uv integration?

    I read this blog post and it seems like we should wait until the integration is complete and editable installs will work out of the box? https://prefix.dev/blog/uv_in_pixi

  8. baszalmstra commented on Feb 24, 2024

    @baszalmstra
    Contributor

    Short answer: yes.

    Longer answer, we are relatively close to a first version with uv integrated. This offers us all the features uv provides including editable installs.

    However, some features including editable installs require a bit more work. We have to modify the lock file and the pixi.toml to accommodate this. But we'll get there!

  9. pavelzw commented on Mar 3, 2024

    @pavelzw
    CollaboratorAuthor

    xref #879

  10. srilman commented on Mar 4, 2024

    @srilman

    Opened a PR with a MVP working. Had a couple of open questions before opening it for review that I put in the PR. If anyone could take a look, that'd be helpful!

  11. ruben-arts commented on Mar 4, 2024

    @ruben-arts
    Contributor

    I would like to close this feature in favor of #879

  12. MatusGasparik commented on Apr 2, 2024

    @MatusGasparik

    Also being able to install wheels in some form using rip would be nice for my production use case:

    I'm currently using this workaround (with the annoyance that pip is still in my prod environment):

    [project]
    name = "my-project"
    channels = ["conda-forge"]
    platforms = ["osx-arm64", "osx-64", "linux-64", "linux-aarch64"]
    
    [dependencies]
    python = ">=3.12"
    
    [host-dependencies]
    pip = "*"
    
    [feature.test.dependencies]
    pytest = ">=6"
    [feature.test.tasks]
    test = "pytest"
    
    [feature.build.dependencies]
    python-build = "*"
    setuptools = ">=61"
    setuptools-scm = "*"
    [feature.build.tasks]
    postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ."
    build-wheel = "python -m build --no-isolation --wheel ."
    
    [feature.prod.tasks]
    postinstall-production = "pip install --no-deps --disable-pip-version-check dist/my_project-*.whl"
    
    [environments]
    default = ["test", "build"]
    build = ["build"]
    prod = ["prod"]

    Thanks, @pavelzw for this suggestion. One question though - how could you accomodate a following use case: I have a foo package withing a src folder which I want to build as a package. This is how I would set it up in pyproject.toml:

    [tool.setuptools.packages.find]
    where = ["src"]
    include = ["foo"]

    Is there a way to do this without having the pyproject.toml in addition to pixi.toml?

  13. pavelzw commented on Apr 2, 2024

    @pavelzw
    CollaboratorAuthor

    pixi.toml now (not released yet) also supports pyproject.toml. I would wait for the new release and then figure out best practices

  14. spacecaterpillar commented on Mar 22, 2025

    @spacecaterpillar

    Can we get a better explanation of the pixi-endorsed way to do this now? It seems like I am required to have a pyproject.toml. Does that mean I have to use its way of specifying dependencies, rather than specifying dependencies via pixi? If so, that seems not ideal.

    I have a top-level pixi.toml and then I have multiple packages that I want installed in an editable manner. My understanding is that the top-level pixi.toml can refer to these by package_name = { path = "path/to/package", editable = true }, but each of these packages needs to have their own pyproject.toml, which meant that I needed to specify dependencies in the non-pixi manner. But then all those dependencies are installed using pypi instead of conda. And if I want them installed from conda, then I actually need to duplicate the dependencies in the top-level pixi.toml

    All of this seems suboptimal. So I am hoping I have just missed how this is intended. The current approach makes me not want to put any dependencies in my internal packages and just have a vanilla pyproject.toml. Then I specify each package's dependences as featuers in the top-level pixi.toml

  15. danielsanjosepro commented on May 13, 2025

    @danielsanjosepro

    Can we get a better explanation of the pixi-endorsed way to do this now? It seems like I am required to have a pyproject.toml. Does that mean I have to use its way of specifying dependencies, rather than specifying dependencies via pixi? If so, that seems not ideal.

    I have a top-level pixi.toml and then I have multiple packages that I want installed in an editable manner. My understanding is that the top-level pixi.toml can refer to these by package_name = { path = "path/to/package", editable = true }, but each of these packages needs to have their own pyproject.toml, which meant that I needed to specify dependencies in the non-pixi manner. But then all those dependencies are installed using pypi instead of conda. And if I want them installed from conda, then I actually need to duplicate the dependencies in the top-level pixi.toml

    All of this seems suboptimal. So I am hoping I have just missed how this is intended. The current approach makes me not want to put any dependencies in my internal packages and just have a vanilla pyproject.toml. Then I specify each package's dependences as featuers in the top-level pixi.toml

    I totally agree with this. I am working now with an empty pyproject.toml inside of my package, but this does not seem to be the way to go. And creating subpackages inside of my package which only requires one subpackage also looks suboptimal.

  16. loodvn commented on Dec 8, 2025

    @loodvn

    I don't think #879 solves the question above right? Especially the following text:

    But then all those dependencies are installed using pypi instead of conda. And if I want them installed from conda, then I actually need to duplicate the dependencies in the top-level pixi.toml.

    My use-case: I have package A, that imports an editable install of package B (which then installs package B plus its dependencies using pypi). One of those dependencies is a conda package though, which then fails when installing from pip.

    If I'm understanding correctly, it would be nice if pixi installed package A's requirements using pixi, and also installed all package B's requirements using pixi too (instead of doing all those dependencies using pypi).

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

    enhancementpypi

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions