Linux 在没有 root 的情况下安装 Python 2.7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5824249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:51:27  来源:igfitidea点击:

Installing Python 2.7 without root

pythonlinux

提问by ktm5124

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

我尝试在远程 linux 机器上安装没有 root 的 Python 2.7。我运行了命令

./configure prefix=/  
make install DESTDIR=/xxx/yyy/ 

where /xxx/yyy/ is a directory for which I have read-write access.

其中 /xxx/yyy/ 是我具有读写访问权限的目录。

I ran into a problem at the end. It said:

最后我遇到了一个问题。它说:

building dbm using gdbm INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished, but the necessary bits to build these modules were not found: _tkinter bsddb185 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name.

running build_scripts running install_lib creating /lib/python2.7 error: could not create '/lib/python2.7': Permission denied

使用 gdbm 信息构建 dbm:无法找到 Tcl/Tk 库和/或标头

Python 构建已完成,但未找到构建这些模块所需的位: _tkinter bsddb185 dl imageop sunaudiodev 要找到必要的位,请在 detect_modules() 中的 setup.py 中查找模块名称。

运行 build_scripts 运行 install_lib 创建 /lib/python2.7 错误:无法创建“/lib/python2.7”:权限被拒绝

Did I take the correct steps in installing it without root access? (i.e., my configure and make commands?) Can anyone tell me why it would not install properly?

我是否在没有 root 访问权限的情况下安装它时采取了正确的步骤?(即,我的 configure 和 make 命令?)谁能告诉我为什么它不能正确安装?

Thanks,
ktm

谢谢,
ktm

回答by Steve Howard

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.

你应该有前缀=/xxx/yyy。使用 prefix=/,它会尝试将库安装到 /lib/python2.7,而不是 /xxx/yyy/lib/python2.7。

回答by Sridhar Ratnakumar

回答by SoLoMoN

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

我只是在没有管理员权限的情况下安装了 python2.7.5。我认为命令应该是:

./configure prefix=/xxx/yyy
make install

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

然后你应该在 .bashrc 中添加路径 /xxx/yyy/bin 为:

PYTHONPATH=/home/songmeixu/python/bin
export PATH=$PYTHONPATH:$PATH

回答by Jeff Hammerbacher

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

与其手动从源代码构建,我建议让linuxbrew为您构建。DigitalOcean 有一个很好的安装 linuxbrew 的教程。一旦完成,您就可以说brew install python并拥有一个管理良好的 python 安装,包括 pip。

回答by Jonathan Komar

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.

我编写了一个脚本,将 Python 2(缺少 Python 3 为用户安装提供的便利功能)和 Pip 2 安装到用户目录中,以便标准用户可以成为其模块等的管理员。

#!/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 ~/.bashrcfor the PATH ENV variable. If this is not desired, simply comment the related lines in the script.

警告:这个脚本是公认的,因为它会在你~/.bashrc的 PATH ENV 变量中附加几行。如果不需要,只需注释脚本中的相关行即可。



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.pyfollowed by deleting the whole install (saves space on a small Raspberry Pi Zero W).

案例:用于Avahi的Airprint服务文件的服务文件生成器不支持Python 3。为了保持系统干净,我只安装了本地版本的Python 2并运行,airprint-generate.py然后删除整个安装(节省空间一个小的 Raspberry Pi 零 W)。