简体   繁体   English

无法在没有 sudo 访问权限的情况下安装 Python

[英]Unable to install Python without sudo access

I extracted, configured and used make for the installation package in my server.我在我的服务器中提取、配置和使用了安装 package 的 make。

However, I could not use make install .但是,我无法使用make install I get the error我得到错误

[~/wepapps/python/Python-2.6.1]# make install
/usr/bin/install -c python /usr/local/bin/python2.6
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.6': Permission denied
make: *** [altbininstall] Error 1

I run the folder with我运行文件夹

chmod +x Python-2.6.1

I get still the same error.我仍然得到同样的错误。

How can I run make install without sudo access?如何在没有 sudo 访问权限的情况下运行make install

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:同样,如果您的脚本(例如 CGI)需要您自己的 Python 用户版本,您必须明确告诉他们:

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

instead of using the default system Python which “#./usr/bin/env python” will choose.而不是使用“#./usr/bin/env python”将选择的默认系统 Python。

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.您可以更改您的 PATH 设置以使从控制台中键入“python”运行该版本,但这对于在不同用户下运行的 web 应用程序没有帮助。

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.如果您编译链接到 Python 的东西(例如 mod_wsgi),您必须告诉它在哪里可以找到您的 Python,否则它将使用系统一。 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:对于其他基于 setup.py 的扩展,如 MySQLdb,您只需使用正确版本的 Python 运行 setup.py 脚本:

/home/masi/.local/bin/python setup.py install

As of year 2020, pyenv is the best choice for installing Python without sudo permission, supposing the system has necessary build dependencies.截至 2020 年, pyenv是安装 Python 无需 sudo 权限的最佳选择,假设系统具有必要的构建依赖项。

# 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

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.扩展 bobince 答案,如果您的系统中没有安装 readline development package 并且您没有 root 访问权限,则会出现问题。

When Python is compiled without readline, your arrow keys won't work in the interpreter.当 Python 在没有 readline 的情况下编译时,您的箭头键将无法在解释器中工作。 However, you can install the readline standalone package as follows: Adding Readline Functionality Without Recompiling Python但是,您可以安装 readline 独立 package,如下所示: 添加 Readline 功能而不重新编译 Python

On the other hand, if you prefer to compile python using a local installation of readline, here's how.另一方面,如果您更喜欢使用本地安装的 readline 编译 python,以下是方法。

Before doing as bobince was telling, compile and install readline.在按照 bobince 所说的做之前,编译并安装 readline。 These are the steps to do so:这些是这样做的步骤:

Then, add this line to your.bash_profile script:然后,将此行添加到 your.bash_profile 脚本:

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!我希望这可以帮助别人!

You can't;你不能; not to /usr , anyway.无论如何,不要/usr Only superusers can write to those directories.只有超级用户可以写入这些目录。 Try installing Python to a path under your home directory instead.尝试将 Python 安装到主目录下的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM