-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Create an implicit virtual environment based on pyproject.toml and following PEP 394 #1386
Comments
That's something that I already mentioned before but, for instance, Now, maybe we could improve the error message by mentioning the |
Agree on mentioning the Recommend hard-setting the Python version rather than making it a semvar requirement. |
Contrary to any other dependencies, the lowest version available I guess. Because otherwise I am not sure how Poetry would do the lookup. For instance with the And even if Poetry looked up only by the major version number, it would have the same issue for constraints without upper limits. For instance with the So here are a few examples showing how I see the lookup order (of the lowest version available):
As you can see, prior to trying
+1 Yes, definitely. But before failing with this error message, I think that Poetry should try several commands instead of merely [Edit] Forget all of this and see my initial post for the proposed solution. |
Here's one approach to consider: Attempt to run Note that this won't pick up Python installations not on the PATH. |
If you want to use the lowest version possible, does it mean that you would prefer |
If you have the |
@maggyero
Oh, i see, so you are just trying different binaries in PATH, from the most specific to the least specific. So, let's say that I have
It seems that there is no option left. But there is! We also have |
What does the alias matter? It's the associated Python version that's significant. Search all possible aliases for associated versions, and pick the one with the newest compatible version. |
I can agree with that. But if that's the case, then the argument against using the latest version possible is no longer valid. |
@David-OConnor I like the resolution you suggested before (letting the user choose when there are multiple versions available), I'm just disputing the "use the minimal version" attitude :-). |
This seems very bad to me. I think the interpretation of I don’t see why poetry shouldn’t treat python the same as any other dependency in this regard — if python 3.9, 3.10, etc are available on the path then use it, the same as you would if dependency X was pinned in such a way that v3.9 was the most recent compatible version available on PyPI. If you want to impose a cap on the python version then just mark it as such. I think it could make sense to be able to specify the desired version of python for a development environment as part of pyproject.toml, and to use it if possible (allowing and using compatible fallbacks), but I don’t think there should be an implicit python version selection process that differs from the standard dependency version selection process. |
Yes of course, but how could Poetry know that |
I would also prefer Poetry to find the highest Python version available in the OS |
I agree - lowest version is inconsistent with what a user expects from semvar, and how dependency versions are chosen. |
3.12 or so, so we won't have to change it for a while. It's computationally quick to check these. Re
We know what versions of Python are avail, and expected to be released soon. |
Yeah, my point wasn't that I think poetry needs to support finding exactly the right version in the From a practical perspective, I personally would be fine with @David-OConnor 's suggestion of checking for a limited list of future versions (if it were sufficiently fast). I would also be fine with requiring some other form of explicit specification for the desired default environments (e.g., an extra key in the poetry config with value listing out the python executables to look for), or with some form of interactive selection (skippable in builds). |
This has been discussed before, and other people have linked to this comment in other issues:
I don't think this is going to happen, and in my personal experience, working with Edit Hm, I've been behind the curve on 1.0.0 developments, apparently this is partially supported now, so ignore my comment! |
Yes, but that means we have to hard code this into Poetry and update it frequently (new Python minor versions are released every year). It creates a maintenance burden. I would prefer a future-proof algorithm, that is why I suggested to look up the lowest Python version instead of the highest one. But this is not ideal.
I agree. SolutionThe more I think about it, the more I think we should just stick to PEP 394:
This means that Poetry should only look up So with the following
When Python 4 is available, we will update the current highest Python major version released to
If no
If a
(Example given with a What do you think @sdispater? |
Let's be practical: It will likely be decades before we encounter a python 5.3, if ever, at which point the ecosystem will have changed beyond recognition. It will be years before we encounter a Python 3.11. When we hit the latter, it'll be a trivial update.
Popular linux distros like Ubuntu distinguish using |
I think it is not Poetry's responsibility to look up minor versions. Poetry should only look up |
I understood your original issue as wanting to specify the environment's Python version version using
|
My concern was that Poetry looks up
I am against this as Poetry provides an explicit way to do it: |
I think the python-version should be project specific - If a project contains something like dataclasses or f-strings, you can specify |
It seems this issue has been addressed in #1477, so maybe this issue can be closed? |
Hi @sdispater I have just tested your PR #1477 with the latest Poetry (1.0.0b5) on MacOS Catalina (10.15.1). (Sorry for not providing any feedback earlier.) Poetry now correctly creates virtual environments based on the requirements of Consequently, with the value
Both installed Python respect the |
@maggyero This is the expected behavior. Poetry will always prioritize the currently used Python version. The reason for that is to support the use case of managing Python environments with |
@sdispater That makes sense. I am closing this issue. Thanks a lot for you hard work! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue
In the absence of an activated virtual environment (I insist), the
poetry add
,poetry build
,poetry install
,poetry lock
,poetry remove
,poetry run
,poetry shell
,poetry show
andpoetry update
commands implicitly create a Poetry built-in virtual environment. However currently, the Python interpreter that they include in this virtual environment is the one called by the#!/usr/bin/env python
shebang line of the~/.poetry/bin/poetry
script. The problem is that on MacOS and most Linux distributions,/usr/bin/env python
resolves to the Python 2.7 interpreter.So if for instance a user specified in his
pyproject.toml
file a dependency on the Python 3.7 interpreter:when he runs one of the
poetry add
,poetry build
,poetry install
,poetry lock
,poetry remove
,poetry run
,poetry shell
,poetry show
andpoetry update
commands for the first time, aRuntimeError
is raised:This is a terrible user experience. Many users have been repeatedly complaining about this since Poetry's inception, so this issue cannot be ignored: #77, #305, #522, #655, #721, #952, #988.
Solution
In #988, @Suor made an excellent suggestion that could address this issue:
tool.poetry.dependencies.python
property of thepyproject.toml
file for the implicit creation of Poetry built-in virtual environments.In PR #731 that will be part of Poetry 1.0.0, @sdispater added a new
poetry env
command that implements the first point, which is great. Thank you for that @sdispater. But that only addresses half of the problem, the explicit virtual environment creation problem. That does not address the implicit virtual environment creation problem that still raises aRuntimeError
.If we also implemented the second point I think it would greatly improve user experience.
[Edit] Specification for the second point
We should just stick to PEP 394:
This means that Poetry should only look up
python
andpythonX
in the OSPATH
(notpythonX.Y
norpythonX.Y.Z
), that is to say Poetry should not be more specific than the major Python version. And since we want to look up the highest Python version for consistency with the dependency lookup mechanism, we should hard code in Poetry the current highest Python major version released (3
). With the relatively slow Python release cycle, there will be practically no maintenance: just a number to update every 10 years or so (Python 3 was released in 2008 and Python 4 will not be released before 2020, and possibly never).So with the following
pyproject.toml
requirements, Poetry will use the followingPATH
lookup orders:python = ">=3.4.1"
: [python3
,python
];python = ">=2.6.3"
: [python3
,python2
,python
];python = ">=2.6.3,<3.0.0"
: [python2
,python
].When Python 4 is available, we will update the current highest Python major version released to
4
in Poetry, so thePATH
lookup orders of Poetry will become:python = ">=3.4.1"
: [python4
,python3
,python
];python = ">=2.6.3"
: [python4
,python3
,python2
,python
];python = ">=2.6.3,<3.0.0"
: [python2
,python
].If no
pythonX
orpython
is found in thePATH
, the following error message will be raised:If a
pythonX
orpython
is found in thePATH
but its version (given bypythonX -V
andpython -V
respectively) does not match thepyproject.toml
requirements, the following error message will be raised:(Example given with a
pyproject.toml
requirement ofpython = "^3.7"
and an OS withoutpython3
in thePATH
and apython
in thePATH
pointing to Python 2.7.14.)The text was updated successfully, but these errors were encountered: