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

Fix pip install --target #4111

Closed
wants to merge 5 commits into from
Closed

Fix pip install --target #4111

wants to merge 5 commits into from

Conversation

halms
Copy link

@halms halms commented Nov 13, 2016

As I messed up my branch, github force closed my last PR.
So this is a new, clean version of PR #4103 .

Sorry for the mess.


For reference: the original description of PR #4103:

Currently pip install --target does fail when a prefix is set (e.g. in a .pydistutils.cfg).
This is especially the case on macOS when Python is installed via Homebrew.
It used to fail in the same way when using the --user flag. This was initially fixed in b227c45

Now I just replicated this fix for the usage of --target.

Interestingly, --target used to work when supplying --install-option="--prefix=" at the command line as advised in Homebrew-and-Python.md, but now doesn't anymore.
The error message changes though whether --install-option="--prefix=" is set or not. - When the option is set, pip fails when get_lib_location_guesses calls distutils_scheme, so it seems the --install-prefix switch is ignored there.

Anyway, this pull request should fix it all by enforcing prefix to be empty when --target is used.
Although this works fine for me, I am not yet sure if these changes would break anything else.


This change is Reviewable

@techtonik
Copy link
Contributor

This needs a rebase.

@@ -266,6 +276,7 @@ def run(self, options, args):
"continue."
)
install_options.append('--home=' + temp_target_dir)
install_options.append('--prefix=')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add --prefix here?

Copy link
Author

@halms halms Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the same thing as already exists for the --user command (line 260).
An empty prefix is set in order to overwrite one set as a default somewhere else (e.g. as it is the case with homebrew python).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch should be dead because of exception above. Filled #4132

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Tests are failing. Looks like this piece of code is still needed.

Copy link
Author

@halms halms Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my understanding the exception only avoids both options being set at the pip command line.
This line ensures that a prefix set somwhere else is effectively overriden as it does basically the same as the workaround there:
https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md#note-on-pip-install---user

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not fully understand, how install_options and distutils_scheme() in locations.py do work together, but it seems to work this way.

@halms
Copy link
Author

halms commented Nov 21, 2016

I just wanted to add a follow-up to the discussion that started in #4103 .

Regarding mutual exclusivity of the options:
https://docs.python.org/3/install/index.html#alternate-installation states that for setup.py --user, --home, and --prefix are mutually exclusive. As --target uses --home, that makes the combination in question mutually exclusive as well.

I would also suggest that we can assume that if one of the flags is given on the command line (or in a requirements.txt), that any default configuration can be overridden quietly.

@mgwio
Copy link

mgwio commented Dec 11, 2016

I'm interested in this change. Will we see it go forward any time soon?

@halms
Copy link
Author

halms commented Dec 20, 2016

Is there anyone we should ping to review the code or something?
I'm not yet familiar with the responsibilities around here.

@mijohansen
Copy link

After some plundering I just commented out the check that raises the error in /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py:262

image

As I am new to Python/PiP and just want to continue testing this really dirty hack saved the day.

@silverwind
Copy link

Looking forward to this fix landing. pip install -t localdir is broken on Homebrew, and the only workaround that is working (echo -e '[install]\nprefix=' > ~/.pydistutils.cfg) must be removed afterwards as it breaks global package installs.

@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Apr 1, 2017
Also override defaults set somewhere (e.g. .pydistutils.cfg) when command line switches are given.
@BrownTruck BrownTruck removed the needs rebase or merge PR has conflicts with current master label Apr 1, 2017
Replace ``--no-use-wheel`` with ``--no-binary=:all:``
Replace --no-use-wheel with --no-binary=:all: and remove assertion of deprecation message.
@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Jun 2, 2017
@techtonik
Copy link
Contributor

For those who want to see this fixed, here is the way:

  1. read the proposed fix
  2. make sure you understand what it does
  3. make sure to ask questions and research if you don't understand
  4. write a report to prove to maintainers that it solves the problem
  5. get link to your report here

Even partial reports can help.

@flebel
Copy link

flebel commented Jun 16, 2017

This workaround fixed it for me:
PYTHONPATH=$PREFIX_PATH/lib/python2.7/site-package pip install --install-option="--prefix=$PREFIX_PATH" -r requirements.txt

https://stackoverflow.com/a/2916320

@techtonik
Copy link
Contributor

@halmi try to resolve conflict. It is just a few lines fix.

@pradyunsg pradyunsg added S: awaiting response Waiting for a response/more information type: enhancement Improvements to functionality labels Aug 21, 2017
@halms
Copy link
Author

halms commented Oct 10, 2017

This is now handled in #4557.

@halms halms closed this Oct 10, 2017
@pradyunsg pradyunsg removed the S: awaiting response Waiting for a response/more information label Oct 10, 2017
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
@pradyunsg pradyunsg removed the needs rebase or merge PR has conflicts with current master label Apr 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants