Python cannot find module

Hi,

I am new to Python. I need to install the package Casadi. I tried this and was told that I need the package or module cmake. Fine, so I installed cmake (pip install cmake) and “cmake --version” now produces
make version 3.27.7
CMake suite maintained and supported by Kitware (kitware.com/cmake).
However, it seems that Python cannot find cmake because “pip install Casadi” produces the following error message

× Building wheel for casadi (pyproject.toml) did not run successfully.

  • │ exit code: 1*
  • ╰─> [64 lines of output]*
  • :*
  •     File "C:\Users\mhedegar\AppData\Local\Programs\Python\Python312\Scripts\cmake.exe\__main__.py", line 4, in <module>*
    
  •  ModuleNotFoundError: No module named 'cmake'*
    
  •  Traceback (most recent call last):*
    

:

  •  [end of output]*
    
  • note: This error originates from a subprocess, and is likely not a problem with pip.*
  • ERROR: Failed building wheel for casadi*
    Failed to build casadi
    ERROR: Could not build wheels for casadi, which is required to install pyproject.toml-based projects

I have used : to denote that there are more lines which I have excluded. Please tell me if you want to see more details in the error message.

I am course very thankful for help. I really don’t know where to start.

BR

/Marcus

@M_hedegar

It’s possible that someone here will know what the issue is and you could get a better reply than this one, but have you tried the CasADi Support Community, given that the issue may very well be with the package, rather than with your Python environment.

Thank you Rob. It’s a good suggestion and I will try it. I hadn’t thought about the possibility that problem was within casadi.

Yet, if someone here has even more insight, please still respond.

1 Like

This is suspicious. It seems as if the Casadi installer is trying to import CMake as a Python package, but looking for it in the Scripts folder which is for wrapper executables (to offer a command-line interface like when you tried cmake --version). Normally, packages that you install from PyPI (using Pip) are supposed to specify their dependencies (i.e. Casadi would specify CMake), and Pip would automatically install them first - so you shouldn’t need to run a separate command, although it also shouldn’t cause a problem.

Casadi doesn’t seem to be open-source (and I’m currently having trouble trying to load the website), so I can’t really investigate any further than that. But I’m willing to agree that it is likely their fault, and their support ticket.

(I hope Python is not your first programming language; otherwise “a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs” (per the PyPI description) might not be the best place to start learning programming :slight_smile: )

Hi Karl! Good point I think. It’s good to be able to narrow it down to Casadi.I may try to install a completely different package which requires cmake to test this hypothesis.

I have 15 years of experience programming in Matlab. I have encountered Casadi as an add on to- Matlab, but I have almost not used it. The description sounds scary, I agree :slight_smile: Now, I need Casadi to simulate electric vehicle batteries with PyBaMM.

The problem was resolved. I thought of the possibility that cmake is a broader application than just for Python. That is the case. So I downloaded and installed this broader application from “cmake” homepage. Then it worked. I have a very vague memory of having to do this before on an old computer. Possibly for using casadi in Matlab.