-
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
poetry add/install not using venv python #3501
Comments
Hello @mattsta, what's your problem with the current behavior? fin swimmer |
short version:
longer version: On a system with 3+ python versions installed, always only using the poetry-system-script python for the temporary build-venv leads to confusion because the the project venv python (or even just the environment and yeah, the third party packages are doing bad things by directly importing dependence in their setup.py, but it is also slightly confusing how poetry builds using the python of the poetry script and not the python environment of the project venv itself (or even the python of the current shell |
@mattsta Are those projects public (Github or anything like that)? I guess those projects need to use a |
you'd think so, right? But it still seems confusing to build packages using the python of poetry instead of the python of the environment (which could be multiple major releases different, maybe pyenv/conda has deployed 10 python versions on a system, etc). Unless I've been using poetry wrong, poetry isn't installed inside the project environment, it's installed on the system python, but builds should use the project environment (or, at a minimum the Example live package with broken setup.py: https://github.com/facebookresearch/detectron2/blob/master/setup.py which fails doing |
Hello @mattsta, in your case poetry needs to build the package twice. The first one is needed to fetch metadata like name, version and dependencies. poetry tries first to parse these information from the The second one is needed to build the wheel and install it. Here poetry uses the python version it finds within the venv. In both cases a new build environment is created. If no pyproject.toml is provided for the package (as @sinoroc suggested) the newly created build env just contains So as it stands now, poetry cannot do anything here. It doesn't have to do something with which python poetry uses. But there are things that the maintainers of the package must and can do:
fin swimmer |
I don't understand that bit:
I do not know poetry's code base well enough. My gut feeling though, is that if it were the case the issue would show up much more often, and it would be a big problem in general. I have not managed to clearly identify what your proof is that poetry is not using an adequate Python interpreter for that step. This is my debug attempt:
|
but but but... using the project environment as the first build step seems reasonable, right? If there's no difference, then what's the harm in using the project's environment for both build stages?
Using the currently activated project env to build dependencies seems logical, or at a minimum, consulting the current path for which |
Building an external package should never happen within the current environment. Building the package can introduce new dependencies only for the build step, that you don't want to have in your environment. So whether you use the python version that's available within the venv or outside doesn't matter here. Because this python is only used to create a new temporary venv with no other packages available then |
I am not sure I follow. How would that help? |
ooh, got it. Thanks for the insight! Sorry for the mistaken assumptions.
In this one case, it would let us override the initial setup.py evaluation environment with the current project environment already containing the Closing as "notabug; other projects need to get their act together and stop breaking established norms of the language ecosystem!" |
@mattsta |
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. |
Ran into a bit of a python environment error when trying to install unruly packages (where they explicitly import dependency modules in their
setup.py
to see if it exists).The current poetry environment package install process uses the
python
executable of whatever is runningpoetry
and never actually thepython
of thevenv
itself.poetry/poetry/inspection/info.py
Lines 453 to 456 in bf30ca6
Because here, if no
executable
argument is provided tobuild_venv()
, it defaults to the executable runningpoetry
—could be anything anywhere with any packages!—(viaexecutable or sys.executable
). If we are using an explicit env set bypoetry env use
which isn't the same binary runningpoetry
itself, the install process will never have a usable environment we expect:poetry/poetry/utils/env.py
Lines 804 to 819 in bf30ca6
Proper suggested fix: use the current value of the project's
env
python setting for all installs. (left as an exercise for the reader)Hack fix: change the executable discovery line to at least consult the environment for python before defaulting to the current executable:
executable or shutil.which("python3") or sys.executable,
so it will at least be able to install when attempted inside the project's ownpoetry shell
session.The text was updated successfully, but these errors were encountered: