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 installation using --target #3450

Closed
wants to merge 6 commits into from
Closed

fix installation using --target #3450

wants to merge 6 commits into from

Conversation

esc
Copy link
Contributor

@esc esc commented Feb 3, 2016

We encountered a problem on CentOS 7 machines when using the --target option
to install packages that are equipped with c-extensions.

Observe:

me@box ~ $ uname -a
Linux box.d.rz.is 3.10.0-327.4.4.el7.x86_64 #1 SMP Tue Jan 5 16:07:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

me@box ~ $ python --version
Python 2.7.5

me@box ~ $ virtualenv --version
1.10.1

me@box ~ $ virtualenv venv
New python executable in venv/bin/python
Installing Setuptools.......................................................................................................................................................done.
Installing Pip............................................................................................................................................................................................................................................................................done.

me@box ~ $ source venv/bin/activate

(venv)me@box ~ $ mkdir target

(venv)me@box ~ $ ls
target  venv

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev -U pip
Collecting pip
  Downloading https://my_proxy:5000/root/pypi/+f/205/6f553d5b593d3/pip-8.0.2-py2.py3-none-any.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 14.3MB/s
Installing collected packages: pip
  Found existing installation: pip 1.4.1
    Uninstalling pip-1.4.1:
      Successfully uninstalled pip-1.4.1
Successfully installed pip-8.0.2

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target pyyaml
Collecting pyyaml
  Downloading https://my_proxy:5000/root/pypi/+f/89c/bc92cda979042/PyYAML-3.11.zip (371kB)
    100% |████████████████████████████████| 372kB 18.6MB/s
Installing collected packages: pyyaml
  Running setup.py install for pyyaml ... done
Successfully installed pyyaml
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmpz2LoDs/lib/python'

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target simplejson
Collecting simplejson
  Downloading https://my_proxy:5000/root/pypi/+f/b84/41f1053edd9dc/simplejson-3.8.1.tar.gz (76kB)
    100% |████████████████████████████████| 77kB 19.0MB/s
Installing collected packages: simplejson
  Running setup.py install for simplejson ... done
Successfully installed simplejson
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmpEFNOZq/lib/python'

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target markupsafe
Collecting markupsafe
  Downloading https://my_proxy:5000/root/pypi/+f/f5a/b3deee4c37cd6/MarkupSafe-0.23.tar.gz
Installing collected packages: markupsafe
  Running setup.py install for markupsafe ... done
Successfully installed markupsafe
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmp4UuvDJ/lib/python'

(venv)me@box ~ $ ls /tmp/tmp4UuvDJ/
lib64

As you can see using --target first installs into a temporary directory and
then installes into the desired target. Well, at least it tries to: for any
packages that have c-extensions (in this case pyyaml, simplejson and
markupsafe) it incorrectly looks for a lib directory whereas it should be
looking for a lib64 directory. This patch fixes that for us by looking in a
fallback location. We can confirm that this fixes the issue for us.

Please advise.

Review on Reviewable

We encountered a problem on CentOS 7 machines when using the `--target` option
to install packages that are equipped with c-extensions.

Observe:

```
me@box ~ $ uname -a
Linux box.d.rz.is 3.10.0-327.4.4.el7.x86_64 #1 SMP Tue Jan 5 16:07:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

me@box ~ $ python --version
Python 2.7.5

me@box ~ $ virtualenv --version
1.10.1

me@box ~ $ virtualenv venv
New python executable in venv/bin/python
Installing Setuptools.......................................................................................................................................................done.
Installing Pip............................................................................................................................................................................................................................................................................done.

me@box ~ $ source venv/bin/activate

(venv)me@box ~ $ mkdir target

(venv)me@box ~ $ ls
target  venv

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev -U pip
Collecting pip
  Downloading https://my_proxy:5000/root/pypi/+f/205/6f553d5b593d3/pip-8.0.2-py2.py3-none-any.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 14.3MB/s
Installing collected packages: pip
  Found existing installation: pip 1.4.1
    Uninstalling pip-1.4.1:
      Successfully uninstalled pip-1.4.1
Successfully installed pip-8.0.2

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target pyyaml
Collecting pyyaml
  Downloading https://my_proxy:5000/root/pypi/+f/89c/bc92cda979042/PyYAML-3.11.zip (371kB)
    100% |████████████████████████████████| 372kB 18.6MB/s
Installing collected packages: pyyaml
  Running setup.py install for pyyaml ... done
Successfully installed pyyaml
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmpz2LoDs/lib/python'

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target simplejson
Collecting simplejson
  Downloading https://my_proxy:5000/root/pypi/+f/b84/41f1053edd9dc/simplejson-3.8.1.tar.gz (76kB)
    100% |████████████████████████████████| 77kB 19.0MB/s
Installing collected packages: simplejson
  Running setup.py install for simplejson ... done
Successfully installed simplejson
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmpEFNOZq/lib/python'

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target markupsafe
Collecting markupsafe
  Downloading https://my_proxy:5000/root/pypi/+f/f5a/b3deee4c37cd6/MarkupSafe-0.23.tar.gz
Installing collected packages: markupsafe
  Running setup.py install for markupsafe ... done
Successfully installed markupsafe
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmp4UuvDJ/lib/python'

(venv)me@box ~ $ ls /tmp/tmp4UuvDJ/
lib64
```

As you can see using `--target` first installs into a temporary directory and
then  installes into the desired `target`. Well, at least it tries to: for any
packages that have c-extensions (in this case pyyaml, simplejson and
markupsafe) it incorrectly looks for a `lib` directory whereas it should be
looking for a `lib64` directory. This patch fixes that for us by looking in a
fallback location. We can confirm that this fixes the issue for us.

Please advise.
@esc
Copy link
Contributor Author

esc commented Feb 3, 2016

cc @snordhausen

@esc
Copy link
Contributor Author

esc commented Feb 3, 2016

I can spice this up with tests, cleaner code and better error messages if you would principally accept the patch.

@esc
Copy link
Contributor Author

esc commented Feb 3, 2016

currently failing because pypi is down

snordhausen referenced this pull request in Scout24/pybuilder_aws_plugin Feb 8, 2016
@esc
Copy link
Contributor Author

esc commented Feb 9, 2016

This is green, would appreciate some feedback from the developers, our project is currently blocking on this.

@xavfernandez xavfernandez added this to the 8.1 milestone Feb 9, 2016
@rbtcollins
Copy link

I think this will break if things are installed into both purelib and platlib. We shouldn't presume its either-or.

@esc
Copy link
Contributor Author

esc commented Feb 11, 2016

@rbtcollins that is correct, but this patch would already fix if it were either or, which fixes issues we are having today. If any package installs into purelib and platlib it would be currently broken and would continue to be broken after this PR is merged.

Do you know of any package that installs into purelib and platlib?

@esc
Copy link
Contributor Author

esc commented Feb 11, 2016

I rewrote the code to copy both purelub and platlib, though I have no idea if it will work or not, an example package would come in handy.

@rbtcollins
Copy link

Thanks. So - we're about to deprecate the --target option unless we can put together a sensible use case for it - this bug report reminded us how broken it is. Could you perhaps explain the use case you have that leads you to use it?

@esc
Copy link
Contributor Author

esc commented Feb 11, 2016

Yes, this is quite important when it comes to making AWS Lambda-Functions in Python. In fact -t is explicitly mentioned in the official AWS howto here:

https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

Not having this would cause some serious breakage in our builds and deployments since we rely heavily on it via: https://github.com/ImmobilienScout24/pybuilder_aws_plugin

Granted, the way AWS expects us to package so-called lambda-zips isn't exactly standard, but we would request to keep --target until a suitable alternative method of packaging lambda-zips has been devised.

@esc
Copy link
Contributor Author

esc commented Feb 11, 2016

I'll fix the PR tomorrow, currently not on the correct device.

@rbtcollins
Copy link

rbtcollins commented Feb 11, 2016 via email

@esc
Copy link
Contributor Author

esc commented Feb 11, 2016

Hmm, that get's a bit messy, since we already have a virtualenv for development and running the build tool, I suppose one could make it work. The nice thing about --target is that we can select the dependencies from the build tool and simply install them into a directory. Also, a virtualenv always includes pip, I suppose.

@wm75
Copy link

wm75 commented Feb 16, 2016

Please do not deprecate the --target option! Our use case is a command line upgrade command for a package (MiModD) we are maintaining, which uses pip install --target under the hood to grab the correct distribution from pypi and install it into a temporary directory. We then modify the "installed" files before copying them over to the actual location of the currently installed version.
While we could certainly find ways around it, it would mean quite a lot of extra work and would mean that the current version of MiModD would not work when used with later pip versions.

@dstufft dstufft removed this from the 8.1 milestone Mar 4, 2016
This was referenced Apr 22, 2016
@xavfernandez xavfernandez added the C: target pip install's --target option's behaviour handling label Apr 24, 2016
@dstufft dstufft closed this May 18, 2016
@dstufft
Copy link
Member

dstufft commented May 18, 2016

Accidentally closed this, reopening. Sorry!

@dstufft dstufft reopened this May 18, 2016
@esc
Copy link
Contributor Author

esc commented May 18, 2016

You can close this in favour of #3684

@BrownTruck
Copy link
Contributor

Hello!

As part of an effort to ease the contribution process and adopt a more standard workflow pip has switched to doing development on the master branch. However, this Pull Request was made against the develop branch so it will need to be resubmitted against master.

If you do nothing, this Pull Request will be automatically migrated by @BrownTruck for you.

If you would like to retain control over this pull request then you should resubmit it against the master branch, closing and referencing the original Pull Request.

If you choose to migrate this Pull Request yourself, here is an example message that you can copy and paste:

We encountered a problem on CentOS 7 machines when using the --target option
to install packages that are equipped with c-extensions.

Observe:

me@box ~ $ uname -a
Linux box.d.rz.is 3.10.0-327.4.4.el7.x86_64 #1 SMP Tue Jan 5 16:07:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

me@box ~ $ python --version
Python 2.7.5

me@box ~ $ virtualenv --version
1.10.1

me@box ~ $ virtualenv venv
New python executable in venv/bin/python
Installing Setuptools.......................................................................................................................................................done.
Installing Pip............................................................................................................................................................................................................................................................................done.

me@box ~ $ source venv/bin/activate

(venv)me@box ~ $ mkdir target

(venv)me@box ~ $ ls
target  venv

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev -U pip
Collecting pip
  Downloading https://my_proxy:5000/root/pypi/+f/205/6f553d5b593d3/pip-8.0.2-py2.py3-none-any.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 14.3MB/s
Installing collected packages: pip
  Found existing installation: pip 1.4.1
    Uninstalling pip-1.4.1:
      Successfully uninstalled pip-1.4.1
Successfully installed pip-8.0.2

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target pyyaml
Collecting pyyaml
  Downloading https://my_proxy:5000/root/pypi/+f/89c/bc92cda979042/PyYAML-3.11.zip (371kB)
    100% |████████████████████████████████| 372kB 18.6MB/s
Installing collected packages: pyyaml
  Running setup.py install for pyyaml ... done
Successfully installed pyyaml
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmpz2LoDs/lib/python'

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target simplejson
Collecting simplejson
  Downloading https://my_proxy:5000/root/pypi/+f/b84/41f1053edd9dc/simplejson-3.8.1.tar.gz (76kB)
    100% |████████████████████████████████| 77kB 19.0MB/s
Installing collected packages: simplejson
  Running setup.py install for simplejson ... done
Successfully installed simplejson
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmpEFNOZq/lib/python'

(venv)me@box ~ $ pip install --index-url https://my_proxy:5000/dev/dev --target target markupsafe
Collecting markupsafe
  Downloading https://my_proxy:5000/root/pypi/+f/f5a/b3deee4c37cd6/MarkupSafe-0.23.tar.gz
Installing collected packages: markupsafe
  Running setup.py install for markupsafe ... done
Successfully installed markupsafe
Exception:
Traceback (most recent call last):
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/data/home/me/venv/lib/python2.7/site-packages/pip/commands/install.py", line 357, in run
    for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmp4UuvDJ/lib/python'

(venv)me@box ~ $ ls /tmp/tmp4UuvDJ/
lib64


As you can see using --target first installs into a temporary directory and
then  installes into the desired target. Well, at least it tries to: for any
packages that have c-extensions (in this case pyyaml, simplejson and
markupsafe) it incorrectly looks for a lib directory whereas it should be
looking for a lib64 directory. This patch fixes that for us by looking in a
fallback location. We can confirm that this fixes the issue for us.

Please advise.

---

*This was migrated from pypa/pip#3450 to reparent it to the ``master`` branch. Please see original pull request for any previous discussion.*

If this pull request is no longer needed, please feel free to close it.

@BrownTruck
Copy link
Contributor

This Pull Request has been automatically migrated to #3730 to reparent it to the master branch. Please see the new pull request for any new discussion.

@BrownTruck BrownTruck closed this May 26, 2016
janhybs added a commit to flow123d/flow123d that referenced this pull request Jul 20, 2016
  -- fix using pip with --target option (pypa/pip#3056 and pypa/pip#3450)
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2019
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 C: target pip install's --target option's behaviour handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants