Unable to install Python without sudo access

前端 未结 4 951
孤城傲影
孤城傲影 2020-12-04 06:51

I extracted, configured and used make for the installation package in my server.

However, I could not use make install. I get the error

[~/w         


        
相关标签:
4条回答
  • 2020-12-04 07:18

    As of year 2020, pyenv is the best choice for installing Python without sudo permission, supposing the system has necessary build dependencies.

    # Install pyenv
    $ curl https://pyenv.run | bash
    
    # Follow the instruction to modify ~/.bashrc
    
    # Install the latest Python from source code
    $ pyenv install 3.8.3
    
    # Check installed Python versions
    $ pyenv versions
    
    # Switch Python version
    $ pyenv global 3.8.3
    
    # Check where Python is actually installed
    $ pyenv prefix
    /home/admin/.pyenv/versions/3.8.3
    
    # Check the current Python version
    $ python -V
    Python 3.8.3
    
    0 讨论(0)
  • 2020-12-04 07:20

    Extending bobince answer, there is an issue if you don't have the readline development package installed in your system, and you don't have root access.

    When Python is compiled without readline, your arrow keys won't work in the interpreter. However, you can install the readline standalone package as follows: Adding Readline Functionality Without Recompiling Python

    On the other hand, if you prefer to compile python using a local installation of readline, here's how.

    Before doing as bobince was telling, compile and install readline. These are the steps to do so:

    • wget ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz
    • tar -zxvf readline-6.2.tar.gz
    • cd readline-6.2
    • ./configure --with-prefix=$HOME/.local
    • make
    • make install

    Then, add this line to your .bash_profile script:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib
    

    Last, but not least, execute the following command

    export LDFLAGS="-L$HOME/.local"
    

    I hope this helps someone!

    0 讨论(0)
  • 2020-12-04 07:21

    You can't; not to /usr, anyway. Only superusers can write to those directories. Try installing Python to a path under your home directory instead.

    0 讨论(0)
  • 2020-12-04 07:24

    How can I install to a path under my home directory?

    mkdir /home/masi/.local
    
    cd Python-2.6.1
    make clean
    ./configure --prefix=/home/masi/.local
    make
    make install
    

    Then run using:

    /home/masi/.local/bin/python
    

    Similarly if you have scripts (eg. CGI) that require your own user version of Python you have to tell them explicitly:

    #!/home/masi/.local/bin/python
    

    instead of using the default system Python which “#!/usr/bin/env python” will choose.

    You can alter your PATH setting to make just typing “python” from the console run that version, but it won't help for web apps being run under a different user.

    If you compile something that links to Python (eg. mod_wsgi) you have to tell it where to find your Python or it will use the system one instead. This is often done something like:

    ./configure --prefix=/home/masi/.local --with-python=/home/masi/.local
    

    For other setup.py-based extensions like MySQLdb you simply have to run the setup.py script with the correct version of Python:

    /home/masi/.local/bin/python setup.py install
    
    0 讨论(0)
提交回复
热议问题