14

I am trying to install the 64-bit version of NTLK, which comes in a .whl file, in a different directory than the standard python34/Lib folder. I am using Windows 10 64-bit and Python 3.4 64-bit.

I first tried using the instructions in this question (which worked for other modules).

The command I typed into CMD was:

py -m pip install --install-option="--prefix=$PATH_NAME" nltk-3.0.4-py2.py3-none-any.whl

It promptly gave me the following error:

UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.

It appears that I can't install WHL files using the --install-option. Is there an alternate way I can install the .whl package in a non default directory?

Edit: I marked this as solved because the proposed solution allows me to do what I need in my own use case. However, it doesn't completely answer the question due to inherent limitations in using --root to choose an alternate directory. There is technically no correct solution to this problem, see the answer's comments for details.

Edit - March 3, 2017: It looks like this issue has been resolved in version 8.0 of PIP with the addition of the --prefix parameter. I've changed the accepted answer accordingly.

Marlon Dyck
  • 575
  • 2
  • 6
  • 13
  • 1
    `pip install` from source invokes a build process, which runs the `setup.py` script and thus accepts `--install-options`for this step. Installing wheels however does not invoke this build process, and no decision has been made about [supporting these use cases (as of yet)](https://github.com/pypa/pip/issues/2677#issuecomment-94958884). – tutuDajuju Aug 13 '15 at 08:43
  • 1
    However, for some cases, pip install does currently support [`--user`](https://pip.pypa.io/en/latest/reference/pip_install.html#cmdoption--user) and [--root](https://pip.pypa.io/en/latest/reference/pip_install.html#cmdoption--root), which may achieve what you are looking for. – tutuDajuju Aug 13 '15 at 08:45
  • @tutuDajuju: What are the "some cases"? Does it accept those arguments for wheels, or are you saying it depends on even more specific things (like it works for some packages but not others)? – BrenBarn Aug 13 '15 at 17:34
  • These arguments work for wheels, what I meant is that these arguments do not cover all possible scenarios (which `--install-option` does), e.g `--root=$DIR` will install a package (incl. a `wheel`) to `$DIR/usr/local/lib/python2.7/site-packages`. – tutuDajuju Aug 13 '15 at 18:05
  • @tutuDajuju Using `--root` with the .whl worked but it kept saying "Requirement already satisfied" so i had to use `pip install --upgrade --root="$path" $file_path`, despite having no existing installation. I don't understand why this happened, perhaps you could offer an explanation? In any case, can you post your solution as an answer so I can mark it as correct? – Marlon Dyck Aug 13 '15 at 18:08
  • @MarlonDyck yes, this looks like [yet another issue](https://github.com/pypa/pip/issues/3029), with `--root` but not with `--user` . – tutuDajuju Aug 13 '15 at 18:36

3 Answers3

8

You can use the --prefix option of pip install, available since version 8:

--prefix

Installation prefix where lib, bin and other top-level folders are placed

Note that pip uninstall does not have the --prefix option, so there is no obvious way to uninstall packages installed this way. As a workaround, set PYTHONUSERBASE to the prefix directory, e.g.:

PYTHONUSERBASE=prefix-dir python3 -m pip uninstall package-name
Mihai Capotă
  • 2,271
  • 2
  • 32
  • 24
6

Why it happens

When running pip install from source, it invokes a build process, which runs the setup.py script and passes to it the --install-option you pass in.

Installing wheels however does not invoke this build process, and no decision has been made about supporting these use cases, as of yet (see the ongoing discussion).

Possible solution

However, pip install does currently support installing to custom locations with the options --user and --root, which may achieve what you are looking for.

Caveats

As mentioned in the comments, there seems to be an issue with detecting whether the package is already installed when using --root, and the workaround could be using --upgrade or --ignore-installed options.

Additionally, using --root will install the module to user_defined_path/python34/Lib/site-packages/. This makes this option useful for installing the library on a different drive or a non-default python installation, but does not allow installing to a specific folder within a specific directory.

Marlon Dyck
  • 575
  • 2
  • 6
  • 13
tutuDajuju
  • 10,307
  • 6
  • 65
  • 88
  • 1
    This explains why the error is raised, but doesn't answer the basic question of "Is there a way to install a wheel to a specific directory (not relative to user or root)?" Are you saying that is impossible? – BrenBarn Aug 13 '15 at 19:08
  • What do you mean not relative to root? root answers the question, but `--install-option` still has many more flexible options as detailed [in the github issue you commented on](https://github.com/pypa/pip/issues/2677#issuecomment-130521253). – tutuDajuju Aug 13 '15 at 19:13
  • 1
    As your comment said, using `--root==$DIR` will install to `$DIR/usr/local/lib/python2.7/site-packages`. What if I want to install to `/my/own/directory`? – BrenBarn Aug 13 '15 at 19:19
  • 1
    Exactly, the only thing you can do is use `--no-use-wheel` / `--no-binary` together with `--install-options` as usual. There are even more install schemes that [won't work with wheels](https://github.com/pypa/pip/issues/2677#issuecomment-94958884). – tutuDajuju Aug 13 '15 at 19:22
  • Alternatively, you could hack around with a symlink. – tutuDajuju Aug 13 '15 at 19:24
0

See another way of solving your problem would be by using 7-zip and unzipping the whl file which inside the unzipped directory will give you a proper folder of the python module which you can then copy and paste wherever you wish

Rayyan Merchant
  • 157
  • 3
  • 11