Skip to content
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

Add awareness of pip installed packages #3006

Closed
ketozhang opened this issue Sep 30, 2020 · 12 comments
Closed

Add awareness of pip installed packages #3006

ketozhang opened this issue Sep 30, 2020 · 12 comments
Labels
kind/feature Feature requests/implementations

Comments

@ketozhang
Copy link

ketozhang commented Sep 30, 2020

Poetry is not aware of accidental/purposeful use of pip to install packages

$ poetry init
$ poetry add tqdm
$ poetry shell
$ pip install numpy # e.g., user did this accidentally 

Actual

$ poetry lock && poetry install
$ poetry show
tqdm 4.50.0 Fast, Extensible Progress Meter

Expected

$ poetry lock && poetry install
$ poetry show
tqdm 4.50.0 Fast, Extensible Progress Meter
numpy 1.19.2 NumPy is the fundamental package for array computing with Python.

I understand this is very difficult to support currently and the current design recommends user to avoid pip in favor of installing via poetry. However, in peculiar cases (e.g., syntax conventions), sometimes install via poetry is not possible/easy and pip is preferred to be used.

@ketozhang ketozhang added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Sep 30, 2020
@malcolmgreaves
Copy link

malcolmgreaves commented Oct 1, 2020

This is actually expected behavior: nothing is wrong here.

Your project will be installed in an isolated virutalenv. When you do pip install numpy, that installs it to the system-wide environment -- not the project environment.

You don't want to have your project dependencies intermingled with your system, or other project, dependencies. This is a core design feature of poetry: it is a good thing.

EDIT -- Nope, I'm totally wrong. I didn't see the poetry shell 🤦‍♂️

@ketozhang
Copy link
Author

ketozhang commented Oct 1, 2020

My apologies, I forgot to mention the pip install is ran inside the virtual env hence this behavior exist inside the project environment. Will edit the example.

@n8sty
Copy link
Contributor

n8sty commented Oct 2, 2020

I think the suggested behavior would actually add a fair bit of difficulty to working on a poetry managed project. Sometimes I'll pip install ipython into a poetry managed virtual environment because I want to use a fancier REPL or pip install a dependency to play with some additional functionality that I may or may not want added to as a project dependency. If each of these actions automagically added a dependency, I'd have to remember to revert pyproject.toml and poetry.lock. I like the current behavior because it's explicit. When I add a new dependency I poetry add, and that's it. I think this proposal might lead to a fair bit of commit reverts because dependencies were erroneously added.

@ketozhang
Copy link
Author

ketozhang commented Oct 2, 2020

It looks like what I'm really looking for is to be able to undo pip install operation(s) without needing to know its name similar to pipenv's clean command. Unfortunately poetry install is not able to restore the environment.

@n8sty, in your case your python environment will not be representative by your lockfile or pyproject.toml which I believe poetry discourages.

@finswimmer
Copy link
Member

It looks like what I'm really looking for is to be able to undo pip install operation(s) without needing to know its name similar to pipenv's clean command.

$ poetry install --remove-untracked ?

@malcolmgreaves
Copy link

@ketozhang My apologies -- I totally did not see the poetry shell and completely misunderstood!

@ketozhang
Copy link
Author

No worries, as I've edited that in after your comment so your confusion was my fault

@ketozhang
Copy link
Author

ketozhang commented Oct 7, 2020

$ poetry install --remove-untracked ?

@finswimmer
Thanks that should satisfy my use case! Unfortunately, you must run it after the environment has been activated. It has weird behavior. Needing to activate the environment is not expected from poetry commands.

I've missed this having outdated poetry. Is it possible to make this behavior the default when running bare poetry install (maybe alias it to poetry [clean|sync]? My expectation is always "Python environment should always match the environment specification file". I wonder if this is a golden rule for poetry?

@finswimmer
Copy link
Member

Is it possible to make this behavior the default when running bare poetry install (maybe alias it to poetry [clean|sync]?

There is already a feature request for this: #2370 We haven't finally discussed it until now.

@phiresky
Copy link

In my opinion it would be best if pip would be aliased to something that just errors with "use poetry add to install packages". If I'm working together with others not familiar with poetry, they will inevitably use pip install and then wonder why the tool I've upsold them so greatly loses all of the dependency they add.

@finswimmer
Copy link
Member

The original issue seems to solved by poetry install --remove-untracked (or poetry install --sync from 1.2.0 on).

@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Feature requests/implementations
Projects
None yet
Development

No branches or pull requests

6 participants