Issue with PyBaMM installation using pyproject.toml file

Hi,

I am trying to install all the requirements and dependencies for PyBaMM v25.4.2 using the source repository available on Github. I tried creating a virtual environment that would automatically install the requirements from the pyproject.toml file. I am doing this in VS code. I get the following error while trying to do this. It shows that the problem is originating with the pyproject.toml file. Could someone help?

VENV_INSTALLING_PYPROJECT: "c:/Users/rajaa/MSMD_v25_4_2/pyproject.toml"
Running: c:\Users\rajaa\MSMD_v25_4_2\.venv\Scripts\python.exe -m pip install -e .
2025-06-04 00:16:43.699 [info] Obtaining file:///C:/Users/rajaa/MSMD_v25_4_2
2025-06-04 00:16:43.708 [info]   Installing build dependencies: started
2025-06-04 00:16:47.564 [info]   Installing build dependencies: finished with status 'done'
2025-06-04 00:16:47.566 [info]   Checking if build backend supports build_editable: started
2025-06-04 00:16:47.749 [info]   Checking if build backend supports build_editable: finished with status 'done'
2025-06-04 00:16:47.753 [info]   Getting requirements to build editable: started
2025-06-04 00:16:48.970 [info]   Getting requirements to build editable: finished with status 'done'
2025-06-04 00:16:48.977 [info]   Installing backend dependencies: started
2025-06-04 00:16:50.820 [info]   Installing backend dependencies: finished with status 'done'
2025-06-04 00:16:50.823 [info]   Preparing editable metadata (pyproject.toml): started
2025-06-04 00:16:53.175 [info]   Preparing editable metadata (pyproject.toml): finished with status 'error'
2025-06-04 00:16:53.181 [info]   error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [32 lines of output]
      Traceback (most recent call last):
        File "c:\Users\rajaa\MSMD_v25_4_2\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>
          main()
        File "c:\Users\rajaa\MSMD_v25_4_2\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main
          json_out["return_val"] = hook(**hook_input["kwargs"])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "c:\Users\rajaa\MSMD_v25_4_2\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 204, in prepare_metadata_for_build_editable
          whl_basename = build_hook(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\rajaa\AppData\Local\Temp\pip-build-env-rv7jmt_8\overlay\Lib\site-packages\hatchling\build.py", line 83, in build_editable
          return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\rajaa\AppData\Local\Temp\pip-build-env-rv7jmt_8\overlay\Lib\site-packages\hatchling\builders\plugin\interface.py", line 90, in build
          self.metadata.validate_fields()
2025-06-04 00:16:53.182 [info]       File "C:\Users\rajaa\AppData\Local\Temp\pip-build-env-rv7jmt_8\overlay\Lib\site-packages\hatchling\metadata\core.py", line 265, in validate_fields
          _ = self.version
              ^^^^^^^^^^^^
        File "C:\Users\rajaa\AppData\Local\Temp\pip-build-env-rv7jmt_8\overlay\Lib\site-packages\hatchling\metadata\core.py", line 149, in version
          self._version = self._get_version()
                          ^^^^^^^^^^^^^^^^^^^
        File "C:\Users\rajaa\AppData\Local\Temp\pip-build-env-rv7jmt_8\overlay\Lib\site-packages\hatchling\metadata\core.py", line 248, in _get_version
          version = self.hatch.version.cached
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\rajaa\AppData\Local\Temp\pip-build-env-rv7jmt_8\overlay\Lib\site-packages\hatchling\metadata\core.py", line 1456, in cached
          raise type(e)(message) from None
      LookupError: Error getting the version from source `vcs`: setuptools-scm was unable to detect version for C:\Users\rajaa\MSMD_v25_4_2.
      
      Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.
      
      For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
      
      Alternatively, set the version with the environment variable SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${NORMALIZED_DIST_NAME} as described in https://setuptools-scm.readthedocs.io/en/latest/config.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
2025-06-04 00:16:53.190 [info] error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
2025-06-04 00:16:53.191 [info] hint: See above for details.
2025-06-04 00:16:53.436 [info] Traceback (most recent call last):
  File "c:\Users\rajaa\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\create_venv.py", line 96, in run_process
2025-06-04 00:16:53.437 [info]     subprocess.run(args, cwd=os.getcwd(), check=True)  # noqa: PTH109
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rajaa\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 573, in run
2025-06-04 00:16:53.437 [info]     raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['c:\\Users\\rajaa\\MSMD_v25_4_2\\.venv\\Scripts\\python.exe', '-m', 'pip', 'install', '-e', '.']' returned non-zero exit status 1.
2025-06-04 00:16:53.438 [info] The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\rajaa\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\create_venv.py", line 262, in <module>
2025-06-04 00:16:53.438 [info]     main(sys.argv[1:])
2025-06-04 00:16:53.438 [info]   File "c:\Users\rajaa\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\create_venv.py", line 258, in main
2025-06-04 00:16:53.439 [info]     install_toml(venv_path, args.extras)
2025-06-04 00:16:53.439 [info]   File "c:\Users\rajaa\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\create_venv.py", line 125, in install_toml
2025-06-04 00:16:53.439 [info]     run_process(
  File "c:\Users\rajaa\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\create_venv.py", line 98, in run_process
2025-06-04 00:16:53.439 [info]     raise VenvError(error_message) from exc
2025-06-04 00:16:53.440 [info] VenvError: CREATE_VENV.PIP_FAILED_INSTALL_PYPROJECT
2025-06-04 00:16:53.477 [error] Error while running venv creation script:  CREATE_VENV.PIP_FAILED_INSTALL_PYPROJECT
2025-06-04 00:16:53.478 [error] CREATE_VENV.PIP_FAILED_INSTALL_PYPROJECT
2025-06-04 00:21:37.968 [info] > "~\MSMD_v25_4_2\.venv\Scripts\python.exe" -I ~\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\interpreterInfo.py
2025-06-04 00:21:37.969 [info] Environments refresh paths discovered: 27 milliseconds
2025-06-04 00:21:38.134 [info] Environments refresh finished (event): 192 milliseconds

Hi,

the issue is that the installation tool setuptools-scm cannot determine the PyBaMM version from the source tarball, and is unhappy about that. There are two main ways to work around this: You can either set the environment variable SETUPTOOLS_SCM_PRETEND_VERSION=25.4.2 before the installation to set the version manually. Or you use a full clone of the git repository, navigate to the correct version tag and run the install command there, which will make it possible for setuptools-scm to determine the version automatically. If you are familiar with git, this might be the easier option. The commands would be:

git clone https://github.com/pybamm-team/PyBaMM.git
cd  PyBaMM
git checkout v25.4.2
# then install from this directory, just as you did with the source you downloaded

Hi @valentin ,

The git option worked. thank you