question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

poetry add/install not using venv python

See original GitHub issue

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 running poetry and never actually the python of the venv itself.

https://github.com/python-poetry/poetry/blob/bf30ca696aa47bcc42937910d620c95c95c0741e/poetry/inspection/info.py#L453-L456

Because here, if no executable argument is provided to build_venv(), it defaults to the executable running poetry—could be anything anywhere with any packages!—(via executable or sys.executable). If we are using an explicit env set by poetry env use which isn’t the same binary running poetry itself, the install process will never have a usable environment we expect:

https://github.com/python-poetry/poetry/blob/bf30ca696aa47bcc42937910d620c95c95c0741e/poetry/utils/env.py#L804-L819

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 own poetry shell session.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
sinoroccommented, Dec 19, 2020

@mattsta If I were you, I think maybe I would look into deploying a private local index (i.e. a PyPI alternative like devpi) and upload my own pre built wheels of those “difficult” projects (detectron2, pytorch, etc.) on it.

1reaction
finswimmercommented, Dec 19, 2020

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?

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 setuptools and wheel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poetry not installing the packages in the venv - Stack Overflow
I do have a actual python 3.9 installed in my machine, but Poetry is supposed to install the package in the virtualenv instead...
Read more >
Configuration | Documentation | Poetry - Python dependency ...
Create the virtualenv inside the project's root directory. If not set explicitly, poetry by default will create virtual environment under {cache-dir}/ ...
Read more >
Python Poetry: Package and venv Management Made Easy
A cheat sheet of Poetry commands ; poetry add <package>, Add package to pyproject.toml , resolve dependencies, and install the package in the ......
Read more >
Python Virtual Environments tutorial using Virtualenv and Poetry
virtualenvs.path is needed to find a path to python.exe inside created virtual environment which will let JetBrains or VSCode to index installed ......
Read more >
Poetry Advance - Python Biella Group
Install the dependencies listed in the pyproject.toml file. ... tell poetry not to use venv inside the proj folder poetry config virtualenvs.in-project ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found