Skip to content

Cython source file is not compiled after pixi install/update #1695

Description

@MatthewSZhang

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

pixi run test

ERRORS
FileNotFoundError: [Errno 2] No such file or directory: '~/fastcan/build/cp312'

Here is my repo

Issue description

The project contains some cython code, which should be compiled when installing the default environment. The compiled file should be in the folder called build. There are some founding about the folder build

  1. when .pixi/envs/ does not contain default environment, pixi install will correctly generate build folder.
  2. when .pixi/envs/ contains default environment but build folder for some reason is missing, pixi install will not generate build folder and only print "The default environment has been installed."
  3. In the previous version of pixi (I can't remember the exact version number), pixi update will solve the problem 2, but the latest version 0.26.1 cannot anymore.
  4. When I use prefix-dev/[email protected] for github CI (cache enable), build folder is missing and cannot be regenerate by pixi update.

Expected behavior

When I run pixi install or pixi update, pixi should check whether the environment properly install the project (in editable mode) which contain cython code. If the build folder missing, pixi should notice it and regenerate it.

Activity

  1. added
    bug
    on Jul 30, 2024
  2. ruben-arts commented on Jul 30, 2024

    @ruben-arts
    Contributor

    Does the issue persist for editable = false?

    How do you expect an editable cython package to behave? Should that rebuild on install or what does it mean?

  3. tdejager commented on Jul 30, 2024

    @tdejager
    Contributor

    Hi! I think this is because uv became a bit smarter with just building the metadata of wheels, during the solve. The workaround for now is to use pixi clean && pixi install. I do not know a really good way of fixing this yet, as we cannot really detect that it this has happened. Only by adding an exception(s) for different build-backends.

    Something we could relatively easily implement is pixi install --force or something of the sort, that forces a re-install of enveryting (or maybe a specifiable packages), would this help at all?

  4. MatthewSZhang commented on Jul 31, 2024

    @MatthewSZhang
    Author

    Does the issue persist for editable = false?

    If editable = false, the cython source code will not be compiled. In other words, the command pip install . will install a python module without compiling cython source code. As far as I know, the common practice is to compile cython code inplace, either using python setup.py build_ext --inplace see ref or python -m pip install --no-build-isolation --editable . see ref.

    How do you expect an editable cython package to behave? Should that rebuild on install or what does it mean?

    As here says: "Please note that some kind of changes, such as the addition or modification of entry points or the addition of new dependencies, and generally all changes involving package metadata, require a new installation step to become effective."
    I think whenever cython source code change or package metadata change, the package should be reinstalled.

    Something we could relatively easily implement is pixi install --force or something of the sort, that forces a re-install of enveryting (or maybe a specifiable packages), would this help at all?

    I think it may not be plausible to reinstall the entire env whenever the cython code is changed. Because during the development, the cython code is changed very often. It will be helpful to provide cli to reinstall the local package only.
    Another thing is about using prefix-dev/[email protected] GitHub Action. I think the local package should be automatically reinstalled even when caching is enabled.

  5. ruben-arts commented on Jul 31, 2024

    @ruben-arts
    Contributor

    We're currently always "checking" if the environment is up-to-date when you run pixi run/shell/install/etc. which would make a reinstall on all of those an unusable experience.
    Would it make sense to have some special behavior for pixi install when using path dependencies? E.g. always reinstalling even if the cache is still valid. I'm not a fan of differences in behavior, but it might feel familiar for most people. But "familiar for most" is always a bad assumption so not sure what the best way forward would be.

    Plus to solve the action cache problem, also rebuild on a clean prefix installation to skip the cache here.

  6. MatthewSZhang commented on Aug 1, 2024

    @MatthewSZhang
    Author

    Plus to solve the action cache problem, also rebuild on a clean prefix installation to skip the cache here.

    It will solve the problem to simply set cache=false, but the whole env will be reinstalled. The way I can find to reinstall the local package only is to run

    pixi run "uv pip install --no-deps --force-reinstall -e ."

    However, pixi seems not to pre-install any installer, such as pip and uv, so I have to install uv first via

    curl -LsSf https://astral.sh/uv/install.sh | sh

    Should pixi also support flags, such as --no-deps and --force-reinstall to make reinstall local package easier?

  7. ruben-arts commented on Aug 1, 2024

    @ruben-arts
    Contributor

    I think all of these settings could make sense for pixi.

    • --no-deps: For this we fist have to modify pixi install to install only a given package.
    • --force-reinstall: This should not be to hard as we should just skip the cache.

    We deliberatly don't install any other package managers as there should in theory be no reason to need extra installers. For these more demanding projects you can also install uv with pixi add uv for now.

  8. tdejager commented on Aug 1, 2024

    @tdejager
    Contributor

    --no-deps would still hit the cache though, I think, so would not re-install. The problem is that a frontend only needs to rebuild if the metadata could be changed, as we do not really know what the backend does, we cant be sure.

    The quote:

    "Please note that some kind of changes, such as the addition or modification of entry points or the addition of new dependencies, and generally all changes involving package metadata, require a new installation step to become effective."

    So I think most of the times the C/C++ code does not change the metadata, so there is no need for a frontend to rebuild.

    However, I think, we could think of a combination of flags that would work :)

  9. tdejager commented on Aug 1, 2024

    @tdejager
    Contributor

    With some more testing, I'm now kind of rethinking the whole thing. I've tried doing an install with uv and while it does not seem to build the code, it is actually bringing back the build folder. But that build folder, is not contained in the wheel as expected. So it makes me wonder where that is cached.

    We should have a closer look at what's happening here. @olivier-lacroix do you have any experience with mesonpy in this regard?

  10. olivier-lacroix commented on Aug 1, 2024

    @olivier-lacroix
    Contributor

    None whatsoever @tdejager :-/

  11. tdejager commented on Aug 1, 2024

    @tdejager
    Contributor

    Again, now that I'm thinking of it, it might be meson doing it itself.

  12. tdejager commented on Aug 1, 2024

    @tdejager
    Contributor

    Sorry I'm thinking out loud here in this issue. But it works for uv if I add an empty dynamic = [] to the pyproject.toml. However, that does not work, for us that is a bug 🐛 and we should fix it. Let me make an issue later.

    uv also does not seem to rebuild when dynamic is added and build folder is deleted. They do have a --reinstall-package that seems to work. It's still pretty slow.

    @MatthewSZhang it would be great that if you could check if you like the flags for uv i.e. fit your workflow and behaves as you would expect, if you have the time of course. You can successfully install your repo with uv in an activated pixi shell.

    e.g

    # install uv, through github, homebrew, pip (pixi global install does not work as of now)
    uv venv .venv
    uv pip install -e .

    And then do the modifcations as you see fit.

  13. MatthewSZhang commented on Aug 2, 2024

    @MatthewSZhang
    Author

    Hi @tdejager , I have tried uv pip install -e .. And after I delete build folder, uv pip install --no-deps --force-reinstall -e . will recompile my cython code to .so file (.pyd for windows), and put it to build folder in a reasonable speed. So I think if pixi supports flags --no-deps and --force-reinstall will be helpful. -e may be unnecessary, as we define whether a package is editable in the pyproject.toml such as

    [tool.pixi.pypi-dependencies]
    mypk = { path = ".", editable = true }

    So the resulting cli is something like pixi update --no-deps --force-reinstall mypk I suppose?

    There are two things that may need to be clarified:

    1. If using uv pip install --force-reinstall -e ., that will be slow, as all the dependencies will be re-installed as well. See here says --force-reinstall:

    Reinstall package(s), and their dependencies, even if they are already up-to-date.
    Therefore, --no-deps is necessary.

    1. If mypk is written in pure python and installed in editable mode, it is not necessary to reinstall it when only .py source code changes. So it is expected that uv pip install -e . will not reinstall the local package when package meta does not change.
      However, if mypk contains .pyx cython code, even package meta data does not change, the mypk need to be re-installed whenever .pyx file changes. Because the mypk need to the compiled .so (.pyd for windows) file to work properly.
      Of course, .pyx file can be compiled manually using such as meson setup .. and meson compile .. or python setup.py build_ext --inplace for setuptools. But I have to set the build directory manually (such as build/cp312) to match the configuration used by the installer like pip or uv (also pixi). So reinstalling mypk via installers is better than compiling it manually to me.
  14. olivier-lacroix commented on Aug 2, 2024

    @olivier-lacroix
    Contributor

    Just chiming in on the possible API for this, as I had similar thoughts for docker layering purposes in #1652 (comment)

    I don’t feel like a —no-deps would be very suitable for pixi install, which deals with the entire environment. I feel like having flags to exclude / only deal with path dependencies, like poetry does, and as @ruben-arts suggested above is a more natural fit.

    This being said, there may be some value in having a separate pixi command (e.g. pixi force-install ?) to deal with a single / select package(s)

  15. 7 remaining items

  16. MatthewSZhang commented on Aug 8, 2024

    @MatthewSZhang
    Author

    Hi @rgommers Thanks for your explanation and I understand meson better now :)

    Hi @tdejager

    I'm not sure what in the original workflow by the OP results in a missing build dir.

    The build dir will loss when using github action prefix-dev/[email protected] and set cache: true. It seems pixi will not cache build dir.

  17. r1cheu commented on Oct 5, 2024

    @r1cheu

    I’m encountering a similar issue. I’m working on a C++ and Python project using scikit-build-core as the build backend. When I make changes to the C++ source code, running pixi install doesn’t recompile the .so files. I’ve tried running pixi run "uv pip install --no-deps --force-reinstall -e ." as well as pixi clean && pixi install, but neither approach works. Previously, using pip install -e . would rebuild the entire package as expected.

    The only way I’ve found to get pixi to reinstall my package is by toggling the editable flag in pyproject.toml between true and false.

  18. tdejager commented on Oct 5, 2024

    @tdejager
    Contributor

    I’m encountering a similar issue. I’m working on a C++ and Python project using scikit-build-core as the build backend. When I make changes to the C++ source code, running pixi install doesn’t recompile the .so files. I’ve tried running pixi run "uv pip install --no-deps --force-reinstall -e ." as well as pixi clean && pixi install, but neither approach works. Previously, using pip install -e . would rebuild the entire package as expected.

    The only way I’ve found to get pixi to reinstall my package is by toggling the editable flag in pyproject.toml between true and false.

    I think it should be --reinstall for uv and not --force-reinstall. In any case, I plan on working on PR next week to be able to re-install and refresh (which should trigger rebuilds) PyPI packages.

  19. munechika-koyo commented on Jan 10, 2025

    @munechika-koyo
    Contributor

    Seems like --reinstall has already been implemented at uv pip install.
    Can Pixi handle this functionality?

  20. tdejager commented on Jan 10, 2025

    @tdejager
    Contributor

    Yeah you are right, we should start including this!

  21. munechika-koyo commented on Feb 13, 2025

    @munechika-koyo
    Contributor

    Do you have any updates? I would greatly appreciate it if you could manage this, as it would free me from the tedious routines of pixi clean and pixi install for Cython code development.

  22. tdejager commented on Feb 13, 2025

    @tdejager
    Contributor

    Make sense, I'll update the issue once I know. Sorry for the delays!

  23. tdejager commented on Feb 27, 2025

    @tdejager
    Contributor

    So what I'm thinking:

    • --reinstall-package <pkg-name> to re-install a specific package.
    • --reinstall to re-install everything.

    Re-installing implies a refresh for the dependencies managed by uv, and that could be something we could add for conda later as well. Refresh meaning the refreshing of the cached metadata.

    Re-installing also implies the rebuilding of both the conda and PyPI source packages.

    Options to specifically refresh but not per se re-install for conda based source and binary packages is something that we can add CLI flags for at a later stage as well.

  24. tdejager commented on Mar 10, 2025

    @tdejager
    Contributor

    This is my plan for implementation:

    • Implement uv backend reinstallation
    • Implement reinstallation in rattler.
    • Expose in pyrattler bindings as well.
    • Rattler release and update in pixi
    • Wire this throughout the code
    • Needs some good integration test somehow.
  25. tdejager commented on Mar 10, 2025

    @tdejager
    Contributor

    Sketch of functionality:

    Image
  26. munechika-koyo commented on Mar 11, 2025

    @munechika-koyo
  27. Hofer-Julian commented on Mar 11, 2025

    @Hofer-Julian
    Member

    I noticed that even writing and redoing something in pyproject.toml causes the package to rebuild during pixi install. It seems that pixi checks its hash value, and its change triggers a rebuild.

    Yes, that is an unrelated issue @munechika-koyo

  28. added a commit that references this issue on Mar 12, 2025
    5baed6e
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

    area:buildbugpypi

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions