Search code examples
pythonpython-poetry

Can I install a new version of python using only poetry?


Disclaimer

I'm new to poetry and I've searched around, but apologies if I've missed something obvious..

What I want to do is:

  1. specify an arbitrary python version in a poetry project (I don't care how I specify it, but presumably in pyproject.toml)
  2. run a command (presumably poetry shell or poetry install, maybe in conjunction with poetry env use) that puts me into an environment that uses the python version I specified above (I don't mind if it's a few commands instead of just one)

I've already tried:

  • poetry env use 3.10 (when I don't have python 3.10 installed already)
    • This gives me an error: /bin/sh: python3.10: command not found
    • Notably, I get why this error is showing up, I'd just like to have poetry install python 3.10 in this case
  • poetry env use 3.10 (when I'm in a conda env that has python 3.10 installed)
    • This works! But... the python executeable is symlinked to the one in the conda env
    • Maybe this is fine, but my goal is to use poetry instead of conda so I'd like to avoid relying on conda to install python versions

What I've seen people do is:

Use poetry in conjunction with pyenv (where pyenv is used to install the python version).

So, my question is:

Is using something like pyenv to install python versions necessary? Is there no way to tell poetry that I want it to install a given python version?

I've looked through the poetry docs, their GH issues, and some SO posts, but (again) apologies if I'm missing something.

Additional Info

  • poetry version: 1.1.13
  • OS: MacOS (Catalina)
  • python version used to install poetry (and therefore the one it seems to default to): 3.7.6
  • happy to add anything else relevant :)

Solution

  • Poetry cannot and will not install any python interpreter for you. This is out of scope. It's the responsibility of the user to provide one.

    pyenv is one way of doing it.