Combine --user with --prefix error with setup.py install

后端 未结 5 1492
余生分开走
余生分开走 2020-11-30 18:53

I was trying to install Python packages a system I recently gained access to. I was trying to take advantage of Python\'s relatively new per user site-packages directory, an

相关标签:
5条回答
  • 2020-11-30 19:30

    One time workaround:

    pip install --user --install-option="--prefix=" <package_name>
    

    or

    python setup.py install --user --prefix=
    

    Note that there is no text (not even whitespace) after the =.

    Do not forget the --user flag.

    Installing multiple packages:

    Create ~/.pydistutils.cfg (or equivalent for your OS/platform) with the following contents:

    [install]
    prefix=
    

    Note that there is no text (not even whitespace) after the =.

    Then run the necessary pip install --user or python setup.py install --user commands. Do not forget the --user flag.

    Finally, remove or rename this file. Leaving this file present will cause issues when installing Python packages system-wide (i.e., without --user) as this user with this ~/.pydistutils.cfg.

    The cause of this issue

    This appears to be an issue with both OpenSUSE and RedHat, which has lead to a bug in virtualenv on these platforms.

    The error stems from a system-level distutils configuration file (in my case /usr/lib64/python2.6/distutils/distutils.cfg) where there was this

    [install]
    prefix=/usr/local
    

    Basically, this is equivalent to always running the install command as install --prefix=/usr/local. You have to override this specification using one of the techniques above.

    0 讨论(0)
  • 2020-11-30 19:36

    I had have the same problem. It was hidden inside the ~/.config/pip/pip.conf with:

    [global]
    target=/foo/bar
    

    Such a config was created by a third-party script without my knowledge.

    I suggest checking the pip configuration files and removing the target=/foo/bar options.

    0 讨论(0)
  • 2020-11-30 19:46

    As has been noted in the comments, the accepted answer (by @gotgenes, who, presumably, has genes) can lead to unexpected consequences.

    @rogeleaderr says, "Note that keeping this file like this will make Python think that / is your root python library directory, leading to confusing issues if you try to install other new packages."

    Rather than write a new config file, as @gotgenes recommends, a better option is to add --prefix= (with no text to the right of the equals sign) as an option on the command line, as in

    $ python setup.py install --user --prefix=
    
    0 讨论(0)
  • 2020-11-30 19:50

    You can simply run pip install --user . , no prefix args required.

    This is better anyway because it will default to python3 if your pip is configured to use Python 3. (I forgot to enter python3 setup.py and it installed a 3-only package under 2.7)

    (credit https://stackoverflow.com/a/1550235/4364036)

    0 讨论(0)
  • 2020-11-30 19:54

    Posting to save others time, as no available answers worked for me...

    In some environments, using the --target (-t) switch will still hit the same error. In my testing on two flavors of linux, I encountered the same issue when using the --prefix= parameter.

    Code:

    PYTHONUSERBASE=/tmp/ pip install --user --force-reinstall $PACKAGE
    

    Explanation: My workaround, which seems to work across many environments (MacOS, Amazon Linux, Debian) is to set the PYTHONUSERBASE environment variable to a temp location. --force-reinstall is used to trigger the local installation even when the package is already installed.

    This will result in the module being compiled/installed (depending on the OS and Python version) to: /tmp/lib/python2.7/site-packages/*

    0 讨论(0)
提交回复
热议问题