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

improving error message when "pdm init" encounters an error related to pyenv. #1601

Closed
dango89emo opened this issue Jan 7, 2023 · 2 comments · Fixed by j178/pdm#1
Closed
Labels
⭐ enhancement Improvements for existing features

Comments

@dango89emo
Copy link

Is your feature request related to a problem? Please describe.

Hello.

Firstly, it is my first time to open an issue to open a source project and my English could be poor.
So excuse me if this issue is not good one and I would be very glad if you suppose a better way to post an issue.

Problem

After I installed pdm on my Mac, pdm init failed and the message was like,

<my_username>@<my_pcname> pdm_sample % pdm init -v                           
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
Traceback (most recent call last):
  File "/Users/<my_username>/.local/bin/pdm", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/core.py", line 259, in main
    return Core().main(args)
           ^^^^^^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/core.py", line 191, in main
    raise cast(Exception, err).with_traceback(traceback)
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/core.py", line 186, in main
    f(project, options)
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/cli/commands/init.py", line 60, in handle
    python = actions.do_use(
             ^^^^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/cli/actions.py", line 628, in do_use
    f"({py_version.identifier})"
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/models/python.py", line 78, in identifier
    return f"{self.major}.{self.minor}"
              ^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/models/python.py", line 52, in major
    return self._py_ver.major
           ^^^^^^^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/findpython/python.py", line 71, in major
    return self.version.major
           ^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/findpython/python.py", line 65, in version
    self._version = self._get_version()
                    ^^^^^^^^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/findpython/python.py", line 164, in _get_version
    version = self._run_script(script, timeout=GET_VERSION_TIMEOUT).strip()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<my_username>/.local/pipx/venvs/pdm/lib/python3.11/site-packages/findpython/python.py", line 180, in _run_script
    return subprocess.check_output(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/<my_username>/.pyenv/shims/python3', '-c', 'import platform; print(platform.python_version())']' returned non-zero exit status 1.

It took some time for me to think of how to solve this, and the cause seemed to be around the command done by findpython through subprocess.

And I checked in the following fashion.

<my_username>@<my_pcname> ~ % /Users/<my_username>/.pyenv/shims/python3 -c 'import platform; print(platofrm.python_version())'
/Users/<my_username>/.pyenv/shims/python3: line 8: /usr/local/Cellar/pyenv/1.2.24.1/libexec/pyenv: No such file or directory

My environment and How I Solved

I installed pyenv with homebrew, and It seems that pyenv was updated with homebrew.
And the path of ~/.pyenv/shims/python became outdated.

After I renewed the path with pyenv rehash, pdm init succeeded.

Describe the solution you'd like

The future users might save their time if the message directly suggest to trying pyenv rehash, not just throwing traceback message.

If it is OK, I will implement and make a Pull Request.
Or is it better to post another issue to findpython?

@dango89emo dango89emo added the ⭐ enhancement Improvements for existing features label Jan 7, 2023
@frostming
Copy link
Collaborator

We landed a resolution to skip the invalid paths(because it is the case for other non-pyenv pythons). No reason to treat pyenv special. If users find it doesn't show in the list, they should check the paths manually.

@dango89emo
Copy link
Author

thanks to fixing

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

Successfully merging a pull request may close this issue.

2 participants