DistutilsOptionError: must supply either home or prefix/exec-prefix — not both

前端 未结 8 2096
旧时难觅i
旧时难觅i 2020-11-28 01:03

I\'ve been usually installed python packages through pip.

For Google App Engine, I need to install packages to another target directory.

I\'ve tried:

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 01:45

    As other mentioned, this is known bug with pip & python installed with homebrew.

    If you create ~/.pydistutils.cfg file with "empty prefix" instruction it will fix this problem but it will break normal pip operations.

    Until this bug is officially addressed, one of the options would be to create your own bash script that would handle this case:

     #!/bin/bash
    
     name=''
     target=''
    
     while getopts 'n:t:' flag; do
         case "${flag}" in
             n) name="${OPTARG}" ;;
             t) target="${OPTARG}" ;;
         esac
     done
    
     if [ -z "$target" ];
     then
         echo "Target parameter must be provided"
         exit 1
     fi
    
     if [ -z "$name" ];
     then
         echo "Name parameter must be provided"
         exit 1
     fi
    
     # current workaround for homebrew bug
     file=$HOME'/.pydistutils.cfg'
     touch $file
    
     /bin/cat <$file
     [install]
     prefix=
     EOM
     # end of current workaround for homebrew bug
    
     pip install -I $name --target $target
    
     # current workaround for homebrew bug
     rm -rf $file
     # end of current workaround for homebrew bug
    

    This script wraps your command and:

    1. accepts name and target parameters
    2. checks if those parameters are empty
    3. creates ~/.pydistutils.cfg file with "empty prefix" instruction in it
    4. executes your pip command with provided parameters
    5. removes ~/.pydistutils.cfg file

    This script can be changed and adapted to address your needs but you get idea. And it allows you to run your command without braking pip. Hope it helps :)

提交回复
热议问题