Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to miniconda Python version format #28

Closed
Tseing opened this issue Apr 18, 2024 · 0 comments · Fixed by #29
Closed

Add support to miniconda Python version format #28

Tseing opened this issue Apr 18, 2024 · 0 comments · Fixed by #29
Assignees

Comments

@Tseing
Copy link

Tseing commented Apr 18, 2024

Steps to reproduce

  • Install pdm by scoop in a Windows device installed with Miniconda.
  • Run pdm init.

Actual behavior

> pdm init -v
Creating a pyproject.toml for PDM...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Leo\scoop\apps\pdm\current\venv\Scripts\pdm.exe\__main__.py", line 7, in <module>
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\core.py", line 359, in main
    return core.main(args or sys.argv[1:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\core.py", line 277, in main
    raise cast(Exception, err).with_traceback(traceback) from None
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\core.py", line 272, in main
    self.handle(project, options)
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\core.py", line 208, in handle
    command.handle(project, options)
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\cli\commands\init.py", line 237, in handle
    self.do_init(project, options=options)
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\cli\commands\init.py", line 40, in do_init
    self.set_python(project, options.python, hooks)
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\cli\commands\init.py", line 214, in set_python
    python_info = UseCommand().do_use(
                  ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\cli\commands\use.py", line 111, in do_use
    selected_python = self.select_python(
                      ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\cli\commands\use.py", line 73, in select_python
    found_interpreters = list(dict.fromkeys(project.iter_interpreters(python, filter_func=version_matcher)))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\project\core.py", line 652, in iter_interpreters
    for interpreter in self.find_interpreters(python_spec, search_venv):
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\pdm\project\core.py", line 722, in find_interpreters
    for entry in finder.find_all(finder_arg, allow_prereleases=True):
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\findpython\finder.py", line 122, in find_all
    matched_python = set(self._find_all_python_versions())
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\findpython\finder.py", line 171, in _find_all_python_versions
    yield from provider.find_pythons()
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\findpython\providers\winreg.py", line 41, in find_pythons
    Version(py_version) if py_version else None,
    ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\packaging\version.py", line 200, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'py39_4.12.0'

According above error log, I try to locate at file "C:\Users\Leo\scoop\apps\pdm\2.14.0\venv\Lib\site-packages\findpython\providers\winreg.py and print path of invalid Python.

# ......
if path.exists():
  py_version = getattr(version.info, "version", None)
  print(py_version, path)
  py_ver = self.version_maker(
      path,
      Version(py_version) if py_version else None,
      getattr(version.info, "sys_architecture", SYS_ARCHITECTURE),
      path,
  )
  yield py_ver

After that, run pdm init again. And the log shows Python in Miniconda (F:\Miniconda\python.exe) is invalid.

> pdm init
Creating a pyproject.toml for PDM...
py39_4.12.0 F:\Miniconda\python.exe
[InvalidVersion]: Invalid version: 'py39_4.12.0'

Python in Miniconda (F:\Miniconda\python.exe) is removed temporarily then pdm init works successfully. Obviously findpython cannot recognize Python version of Miniconda, which causes pdm initilization crash.

> pdm init -v
Creating a pyproject.toml for PDM...
3.7.4 D:\Python37\python.exe
3.9.10 D:\Python39\python.exe
Please enter the Python interpreter to use
 0. cpython@3.12 (C:\Users\Leo\scoop\apps\python\current\python.EXE)
 1. cpython@3.12 (C:\Users\Leo\scoop\shims\python3.exe)
 2. cpython@3.9 (D:\Python39\python.exe)
 3. cpython@3.7 (D:\Python37\python37.exe)
 4. cpython@3.7 (D:\Python37\python.exe)

Expected behavior

It seems Miniconda uses custom Python version format which is not supported. I hope findpython can successfully recognize miniconda Python and conflict of packaging.version.InvalidVersion: Invalid version can be solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants