-
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
Install globally with --user #1214
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one. |
I picked up this issue and started working on an implementation Can somebody re-open the issue please? cc: @sdispater |
Hey @richin13 , thanks a lot for your contribution! I reopened this issue and assigned you for seeing that this is in progress. As this is a new feature @sdispater has to decide if it gets included. But it looks like a useful thing to me 👍 fin swimmer |
Awesome, thank you @finswimmer |
Shouldn't the following just work? pip install --user /path/to/poetry-project This should result in your project being built in an isolated environment without development requirements and |
@richin13 did your submission go anywhere or was it ignored? Currently my workaround is: pip install --user --requirement <(poetry export --format requirements.txt) However, this doesn't give me the project itself installed into the user. I also tried setting |
@harrybiddle why not let pip install the project itself as suggested above? @raxod502 @richin13 I beleive this behaviour is dependent on the underlying pip version (ie. the pip provided in your container). This often times (if ensured via |
Hey @abn, thanks for the help, I really appreciate it. I just gave this a go and it worked, except for two things: (1) my dev dependencies didn't get installed, and (2) I think your command installs the dependencies in the I couldn't see an option to pip install --requirement <(poetry export --dev --format requirements.txt)
pip install --no-deps . This works where |
@raxod502 What is the reason you don't want to install the dependencies "system wide" on the container? It would just require to do the |
At the time, it was because I was working with a system where the dependencies were installed at runtime (in response to incoming requests), not as part of the Dockerfile build. Therefore, any solution that required modifying the base image wasn't ideal. I believe it would be possible to work around the problem by creating a virtualenv in the base image and hardcoding some environment variables (or initializing them as part of the |
Oh interesting. |
Found this here issue when looking for the equivalent of It would even be better to just configure this, somehow, so that my development container could have these settings here:
or similar. It's perfectly possible to create a virtualenv inside the development container, but this is really quite redundant, because in most cases, there is only ever the single environment inside it. This saves a bunch of steps and indirections. |
Please see #6398 -- virtual environments are not really a layer of 'fuss', but the way you keep your Python peas and potatoes from touching. They're closer to a I'm mostly of the opinion that installing to This is difficult/unlikely to be supported in the medium term as we are planning to migrate from pip to performing installs ourselves -- and thus |
Thanks for your comment. Containers can provide exactly the same kind of application isolation as virtualenvs do, and so using one within the other is often quite superfluous. Of course, Poetry is great with virtualenvs and dependency management and thus our preferred tool. People on mac/linux, for example, won't use the dev container, but just the virtualenv. People on Windows may elect to use a dev container, because that gives them a linux environment. And when building production containers, we install directly into the root. No big deal, just wanted to throw this out there :) |
I'm still asking the question of why -- you don't control every Python package in the root, as you are subject to packages that come from the operating system. If your base image does something odd, you will be exposed to packages outside your control in the system prefix. This is not a hypothetical -- Ubuntu ships Python code in dist-packages with version numbers incompatible with standard tooling, causing Poetry to choke on their version numbers. It's not superfluous to isolate Poetry from your code, and your code from the operating system -- you of course are free to do what you want, but it's an incredible burden to try to support every quirky patch a linux distribution ships, when a virtual environment prevents 90% of their upstream-incompatible changes to Python from affecting your project. I have to stress that if you give up letting Poetry manage your environment exclusively (by having Poetry operate in a virtual environment that only it installs packages to), you do so at your own risk and with breakage being likely. |
I've been a core developer of CPython since long before virtualenvs were invented and so I´m well aware of their utility. As a developer, I elect to install my locked dependencies in to the root of the deployment container, because there is nothing to isolate them from, and there is no virtualenv to initialize at runtime. And as explained, this already is trivial to do, by disabling virtualenv generation for Poetry and using the uid of root, as one does during Dockerfile execution. As a developer, I also control the contents of my development container. It also is very slim and has no distro baggage. I'd like the simplicity of installing my locked dependencies directly and not into a virtualenv. It is a safety belt, a tool that I might elect not to use, as an adult, in the safety of my own dev container. But allow me to reiterate, it is no fuss. I was simply assuming that it was possible and looking for the knob to turn, because already, the option is in place not create a virtualenv, and so it looks like an obvious extension: If not using a virtualenv, install into the user folder rather than the root. Poetry is an awesome tool even if it doesn't respond to every whim of a cranky old developer. Cheers! |
It's technically been there on and off (as we have used pip to implement installation -- in 1.2 I don't think just setting |
Right. Didn't realize there was anything to implement, as such, since the user folder has been part of Python since before importlib (IIRC). And also, didn't know that it was even possible to go without |
I came to this bug looking for a solution for the following scenario. Although as I'll get to, it turns out I think we can actually get away without We create Docker images of our Python websites to push to Kubernetes. We naturally want these images to be as lean as possible so deployment and any dynamic replacement done by Kubernetes itself are as quick as possible. We'd also like them to be as straightforwardly implemented as possible so they're easier to reason about and fix. Nonetheless, it would be a fantastic improvement for us to be able to benefit from Poetry's lockfile functionality. I accept that using a Python virtualenv isn't much of an overhead. But in this case is should genuinely be unnecessary, as we start from a very stripped down base-layer version of Ubuntu, which doesn't even have Python installed, and then we explicitly choose what goes in. We currently use However it turns out that we don't really need to do that because in fact the actual |
Yes. When building deployment images, this is exactly that which we do ourselves. It's easy because at build-time we are UID==0. |
I think it would be useful to reconsider this issue in order to enhance the relationship between poetry and devcontainers as stated by #1214 (comment). 🙏 |
There is another use case where this feature would be useful: extending a pre-existing image where pip install was done to the user location. An example is adding custom code to the stock airflow image. |
I landed in this issue for this exact reason, most of my devcontainers I run as a non-privileged user, but for poetry managed projects I'm finding I need to run as root so I don't need to jump through a bunch of hoops just to run poetry install. |
For a devcontainer you could pre-create the virtual environment that will be used. I.e.:
And ensure that your user in the container has write access to $VIRTUAL_ENV. Poetry commands after this will use the venv |
Seconded, this would be a nice feature to have, I also want to be able to extend an existing pre-built python installation at runtime so that i do not have to reinstall all 400+ packages into a new virtualenv. |
My use-case is a bit more mundane. I just want to have a global Using
|
I think I've found a workaround: just create a venv in same location as user's .local RUN python3 -m venv $HOME/.local \
&& source $HOME/.local/bin/activate \
&& poetry install |
@sryabkov @DougPlumley @fjmacagno out of curiosity, is there a reason why https://python-poetry.org/docs/configuration/#virtualenvsoptionssystem-site-packages does not work for your scenario? In this case, poetry will only install the packages that it needs to override or if the version available in the system environment does not satisfy the locked versions. And that is the reason why this option was added in the first place. If you have a container example I can tinker with to understand the issue better - airflow or devcontainer scenario, I would maybe offer specific resolutions or better understand how we can improve the poetry features. And as for when running as an unprivileged user, poetry should not (when using the new installer) try to install to the root site. I will detect the user site (or the venv site) and install it there. This is determined by the property below. poetry/src/poetry/utils/env/site_packages.py Lines 61 to 71 in cff4d7d
|
Hi @abn, it might? I took an example project where I ran into the permission issues and trimmed it down to this https://github.com/DougPlumley/poetry-devcontainer. Hopefully that provides some context. If I recall correctly the reason I was using It could be there is an easy workaround that would have solved that, I used |
I'm in a similar boat as other users: |
As a work around I have a script
The other thing that confused me was that because you're doing In summary, whilst it's possible to use poetry in a devcontainer, I'm having to do a lot of fiddle work to get it to work nicely, and it would entirely be solved if I could just do |
Feature Request
I am using Poetry to install project dependencies into a Docker container where I do not have root access. Since using a virtualenv would be unnecessary (there is only ever one project in this container) and a waste of time (this is done as part of a web service aiming at speed), I configure
settings.virtualenvs.create
tofalse
. However, this causes Poetry to try to install the packages system-globally, which fails because I don't have root access in the container.I would like a way to tell Poetry to use
pip install --user
instead of justpip install
to install packages when virtualenvs are disabled.The text was updated successfully, but these errors were encountered: