Install Python packages to the current directory using PIP in Ubuntu 18

distutils.errors.DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base

I wanted to test something today and had to write a simple python script which required a few python modules. So I installed them using pip, but there was a little problem. I don't like it when package managers install packages globally or system wide. I wanted them to be installed in the current local directory. There's an option to create virtual environments for Python, but this was a simple script and I didn't want to do that, I just wanted to have the modules installed locally.

PIP has a --target option to define the target location to install the modules. But for some reason, it was not working and kept giving me the following error. It seems PIP uses the user scheme by default to install and when I use --target, it throws an error.

distutils.errors.DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base

After searching for a while, I found a workaround and got it working. Here's how to do that.  PIP also has another option as --system, it actually disables the user scheme option. That was it. But this option was not listed in pip man page.

Anyway, the final command should look like this:

pip install --system --target <target-dir> <package-name>

Ex: pip install --system --target ./ pexpect

Hope this post will save someone's time :)

8 comments :

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. As claimed by Stanford Medical, It is in fact the ONLY reason this country's women get to live 10 years more and weigh 19 kilos lighter than us.

    (And realistically, it has absoloutely NOTHING to do with genetics or some secret-exercise and really, EVERYTHING to around "how" they eat.)

    P.S, I said "HOW", and not "what"...

    CLICK on this link to discover if this short quiz can help you release your true weight loss potential

    ReplyDelete
  4. Thank you! Was stuck with this for a long time before I saw this post. Worked like a charm!

    ReplyDelete
  5. It let you observe concurrent system traffic and recognize hosts. This instrument was urbanized to locate flaws in PC networks and fix the detect flaws. Hack Wifi Password Online Android

    ReplyDelete
  6. Hitman Pro 2023 Crack occupied transfer affords you the protected PC inside few connects. This device practices performance grounded practices and perceives totally the drivers plus files that activate identical malware. Hitman Pro Product Key

    ReplyDelete