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

Allow pip to install libraries in a directory. #446

Closed
skorokithakis opened this issue Feb 2, 2012 · 13 comments
Closed

Allow pip to install libraries in a directory. #446

skorokithakis opened this issue Feb 2, 2012 · 13 comments
Labels
auto-locked Outdated issues that have been locked by automation

Comments

@skorokithakis
Copy link
Contributor

Some environments, like AppEngine, require packages to be in a specific directory. Right now, I haven't found a way to automatically download and install these. It would be fantastic if pip could download the packages and extract them into a directory specified by the user, similar to --no-install or -d, except it wouldn't just download tarballs or place them in the "build" directory, it would place them in a directory the user specified.

This could be as easy as making -d extract the tarballs or --no-install move them to a directory.

For example:

$ pip download shortuuid

Downloading/unpacking shortuuid
Downloading shortuuid-0.1.tar.gz
Running setup.py egg_info for package shortuuid

Successfully downloaded shortuuid

$ ls shortuuid
init.py

This is different from --no-install, which extracts the package in "build/" ("download" would place the module at the directory, not the entire contents of the package, the setup.py files, etc), and different from -d, which just downloads the package.

@carljm
Copy link
Contributor

carljm commented Feb 2, 2012

I think this is already almost-possible two different ways, via pip install --install-option="--home=path/" and via pip install --user with the PYTHONUSERBASE env var set. Both of those install stuff to "lib/pythonX.X/site-packages" within the target dir, not to the target dir directly, but it only takes a smidgen of scripting to move them if that's what you want.

Just making -d extract the tarballs or --no-install move them will not work; there's much more that happens in a proper installation of a Python package than just unpacking a tarball. In many cases it amounts to little more than copying a directory, but not in all cases. There are often things included in a tarball that aren't actually installed, and some packages do additional manipulations to the installed files.

I might not be opposed to a pull request for something like a --target option to the install command that would essentially be a wrapper around --install-option="--home=path/", except it would install the files directly to the target directory.

@skorokithakis
Copy link
Contributor Author

Fantastic, I've already started work on this. Adding the extra options and aliasing to the required commands was trivial, and already works properly. However, is the assumption that I can just move all directories in "path/lib/python/" that don't end in ".egg-info" out to "path/" sound?

I am not entirely certain how pip installs packages, so I thought I should ask before assuming things that might not be correct.

@carljm
Copy link
Contributor

carljm commented Feb 3, 2012

@skorokithakis I'd actually recommend just moving everything, including the .egg-info directories. Those directories provide metadata about what's installed; their presence won't hurt anything, and there's no reason to remove that metadata.

@skorokithakis
Copy link
Contributor Author

Great, I'll send you the pull request in a few minutes, then, thank you. My reason for removing those directories is just because of added clutter (one usually works with all the libraries installed in the working directory in GAE, for example, so those would clutter things up too much).

You are correct, though, it's trivial to just remove those if you don't need them.

@skorokithakis
Copy link
Contributor Author

Well, everything is almost ready, except for one problem: What about libraries that already exist?

Currently, I'm using a temporary directory (from mkdtemp) to install everything in (as an argument to --home) and then I move everything to the target dir. Is the reasonable behaviour to replace anything that might already exist? If so, I'll push now.

@skorokithakis
Copy link
Contributor Author

I have sent a push request for review, let me know if something is wrong. Overwriting existing files sounds reasonable, at least.

@carljm
Copy link
Contributor

carljm commented Feb 3, 2012

Yes, I think overwriting existing files makes sense. In the typical use case for this, the target directory would be under version control anyway, and overwriting could be useful for upgrades.

@carljm
Copy link
Contributor

carljm commented Feb 3, 2012

Fixed with merge of #447

@carljm carljm closed this as completed Feb 3, 2012
@richburdon
Copy link

The -t option seems to break other options used with pip install.

1). with --upgrade -r requirements.txt
Error: Destination path '...' already exists (i.e., --upgrade seems to be ignored)

2). with -e git+git@github.com:.../foo.git#egg=foo
error: option --home not recognized

@webmaven
Copy link

As useful as it is, --target seems to have some problems. See Issue #1489, and the related issues linked from there.

@anentropic
Copy link

I get the following error when trying to use --target

Installing collected packages: httplib2.ca-certs-locater
  Running setup.py install for httplib2.ca-certs-locater
    error: must supply either home or prefix/exec-prefix -- not both

@zsims
Copy link

zsims commented Apr 22, 2015

As useful as it is, --target seems to have some problems.

Fits our use-case, please don't remove it!

@eramirem
Copy link

eramirem commented Aug 5, 2015

Did you ever get to fix the incompatibility between --target and --editable options, as reported by @richburdon?
I'm running through the same difficulty.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 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
Projects
None yet
Development

No branches or pull requests

7 participants