Installing Python 2.7 without root

前端 未结 5 845
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 04:17

I tried installing Python 2.7 without root on a remote linux machine. I ran the commands

./configure prefix=/  
make install DESTDIR=/xxx/yyy/ 
相关标签:
5条回答
  • 2020-12-14 04:44

    You should have prefix=/xxx/yyy. With prefix=/, it tries to install the libraries to /lib/python2.7, rather than /xxx/yyy/lib/python2.7.

    0 讨论(0)
  • 2020-12-14 04:44

    I wrote a script that installs Python 2 (which is missing the convenience faculties provided by Python 3 for user installations) and Pip 2 into a user directory so that a standard user can be administrator over its modules etc.

    #!/bin/bash
    VERSION="2.7.11"
    BUILDDIR=~/"build/python"
    INSTALLDIR=~/"python/Python-$VERSION"
    
    mkdir -p ${BUILDDIR}
    cd ${BUILDDIR}
    if [ ! -f $BUILDDIR/Python-$VERSION.tgz ]
    then
    wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz
    tar zxfv Python-$VERSION.tgz
    fi
    find $BUILDDIR -type d | xargs chmod 0755
    cd Python-$VERSION
    
    
    mkdir -p ${INSTALLDIR}
    ./configure --prefix=${INSTALLDIR}
    make && make install
    
    # Append to user PATH or create symbolic link to .local/bin
    # [[ ":$PATH:" != *":$HOME/python/Python-$VERSION/bin:"* ]] && printf "export PATH=$HOME/python/Python-$VERSION/bin:$PATH\n" >> ~/.bashrc
    if [ ! -d ~/.local/bin ]; then mkdir -p ~/.local/bin; fi
    ln -s ~/python/Python-"$VERSION"/bin/python ~/.local/bin/
    
    source ~/.bashrc
    
    # Install local pip
    cd ..
    wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python - --user
    [[ ":$PATH:" != *":$HOME/.local/bin:"* ]] && printf "export PATH=$HOME/.local/bin:$PATH\n" >> ~/.bashrc
    
    # Install modules like this:
    # pip install --target="$HOME/.local/lib/python$VERSION/site-packages"
    
    # Add those modules to PYTHONPATH
    [[ ":$PYTHONPATH:" != *":$HOME/.local/lib/python$VERSION/site-packages:"* ]] && printf "export PYTHONPATH=$HOME/.local/lib/python$VERSION/site-packages:$PYTHONPATH\n" >> ~/.bashrc
    
    source ~/.bashrc
    

    Caveat: This script is admittedly opinionated in that it will append a few lines to your ~/.bashrc for the PATH ENV variable. If this is not desired, simply comment the related lines in the script.


    Case: The service file generator for Airprint service files for use in Avahi does not support Python 3. For the purpose of keeping the system clean, I just install a local version of Python 2 and run airprint-generate.py followed by deleting the whole install (saves space on a small Raspberry Pi Zero W).

    0 讨论(0)
  • 2020-12-14 04:48

    I just install python2.7.5 without admin right. I think the command should be:

    ./configure prefix=/xxx/yyy
    make install
    

    and then you should add the path /xxx/yyy/bin in .bashrc as:

    PYTHONPATH=/home/songmeixu/python/bin
    export PATH=$PYTHONPATH:$PATH
    
    0 讨论(0)
  • 2020-12-14 04:55

    Instead of building from source manually, I'd suggest letting linuxbrew do the build for you. DigitalOcean has a nice tutorial on installing linuxbrew. Once that's complete, you can just say brew install python and have a nicely managed python installation, including pip.

    0 讨论(0)
  • 2020-12-14 05:00

    Don't compile, get the pre-built binary from ActiveState.

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