简体   繁体   English

如何在没有安装以前版本的情况下在 Linux 中安装 Python

[英]How to install Python in Linux without previous version installed

I'm currently doing some embedded systems programming.我目前正在做一些嵌入式系统编程。 This was set up by somebody else a few years ago.这是几年前别人设置的。 So now I'm looking to upgrade to Python 2.7.2 to make things simpler because I have already run into two cases where what I coded wasn't supported.所以现在我希望升级到 Python 2.7.2 以使事情变得更简单,因为我已经遇到了两种不支持我编写的代码的情况。

What is currently running:当前正在运行的内容:

: uname -a
Linux host1 2.6.18-6-486 #1 Sun Feb 10 22:06:33 UTC 2008 i586 GNU/Linux
: python -v
Python 2.4.4
: pyversions -i
python2.4

So right now only 2.4 is installed.所以现在只安装了 2.4。

I untarred python2.7.2 and when I go to that directory and run python27 setup.py install --home=/home/jhemilian and it seems like python2.4 doesn't seem to know the with...as statement syntax:我解压缩了 python2.7.2,当我进入该目录并运行python27 setup.py install --home=/home/jhemilian时,似乎 python2.4 似乎不知道with...as语句语法:

host1:/home/jhemilian/src/Python-2.7.2: python setup.py install --home=/home/jhe
milian
  File "setup.py", line 361
    with open(tmpfile) as fp:
            ^
SyntaxError: invalid syntax

Before I go figuring this out I first have a question: python itself is being used to install Python?在我弄清楚这一点之前,我首先有一个问题:python 本身被用来安装 Python? What if I didn't have the first version of Python installed?如果我没有安装 Python 的第一个版本怎么办? I know it's shipped with most Linux but hypothetically -- how does such a seeming catch-22 like that work?我知道大多数 Linux 都附带了它,但假设是——这样一个看起来像这样的 catch-22 是如何工作的?

What I am looking to do is install python2.7 in a benign location, keeping the python command still as using Python 2.4 just in case the "legacy" software i'm running is dependent on it, and running python2.7 myscript.py et cetera when I want to run one of my newer scripts.我要做的是将python2.7安装在一个良性位置,保持python命令仍然使用Python 2.4,以防我运行的“旧”软件依赖于它,并运行python2.7 myscript.py当我想运行我的一个较新的脚本时等等。 Feel free to comment if there is a cleaner or more practical (or even safer!) way to do this.如果有更清洁或更实用(甚至更安全!)的方式来做到这一点,请随时发表评论。

I don't think it would make much sense to go replacing all the with statements with compatible try blocks.我认为用兼容的 try 块替换所有 with 语句没有多大意义。 I've looked though the READMEs and online documentation but I can't seem to find a way to install Python without already having Python.我查看了自述文件和在线文档,但我似乎找不到在没有 Python 的情况下安装 Python 的方法。 Note that I DO NOT have internet connection, although if desirable or necessary I could.请注意,我没有互联网连接,但如果需要或必要的话,我可以。 It would be great if somebody could point me in the right direction.如果有人能指出我正确的方向,那就太好了。 Thanks!!谢谢!!

Try to read this SO question. 尝试阅读 SO问题。

Also read this thread. 另请阅读主题。 I hope you solve the problem. 希望您能解决问题。

EDIT: virtualenv is apparently for already-installed Python versions.编辑: virtualenv 显然适用于已安装的 Python 版本。 Disregard this recommendation.忽略此建议。

I think what you want is virtualenv .我认为您想要的是virtualenv

I haven't used it myself, but I understand this is what it's meant for.我自己没有使用过它,但我知道这就是它的意思。

From the website :网站

virtualenv is a tool to create isolated Python environments. virtualenv是一个创建隔离 Python 环境的工具。

The basic problem being addressed is one of dependencies and versions, and indirectly permissions.正在解决的基本问题是依赖关系和版本之一,以及间接权限。 Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications?想象一下,您有一个应用程序需要 LibFoo 版本 1,但另一个应用程序需要版本 2。您如何同时使用这两个应用程序? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.如果您将所有内容都安装到 /usr/lib/python2.7/site-packages(或任何您平台的标准位置)中,很容易导致您无意中升级了不应升级的应用程序。

EDIT: Upon review, I think you want Alberto's answer, so I voted him up for visibility.编辑:经审查,我认为您想要 Alberto 的答案,所以我投票支持他以提高知名度。

The installation procedure is described in multiple places. 安装过程在多个地方进行了描述。

It's all right in the README...在 README 中没关系...

You don't need to use python to install, in fact, you shouldn't...just:你不需要使用python来安装,其实你不应该……只是:

./configure
make
make install

If you want to install in a specific dir, just follow what the README says:如果要安装在特定目录中,只需按照 README 中的说明进行操作:

Installing安装

To install the Python binary, library modules, shared library modules (see below), include files, configuration files, and the manual page, just type要安装 Python 二进制文件、库模块、共享库模块(见下文)、包含文件、配置文件和手册页,只需键入

 make install

This will install all platform-independent files in subdirectories of the directory given with the --prefix option to configure or to the prefix' Make variable (default /usr/local). All binary and other platform-specific files will be installed in subdirectories if the directory given by --exec-prefix or the这会将所有与平台无关的文件安装在带有 --prefix 选项的目录的子目录中,以配置或prefix' Make variable (default /usr/local). All binary and other platform-specific files will be installed in subdirectories if the directory given by --exec-prefix or the prefix' Make variable (default /usr/local). All binary and other platform-specific files will be installed in subdirectories if the directory given by --exec-prefix or the exec_prefix' Make variable (defaults to the --prefix directory) is given. prefix' Make variable (default /usr/local). All binary and other platform-specific files will be installed in subdirectories if the directory given by --exec-prefix or the

If DESTDIR is set, it will be taken as the root directory of the installation, and files will be installed into $(DESTDIR)$(prefix), $(DESTDIR)$(exec_prefix), etc.如果设置了DESTDIR,则作为安装的根目录,文件会安装到$(DESTDIR)$(prefix)、$(DESTDIR)$(exec_prefix)等。

All subdirectories created will have Python's version number in their name, eg the library modules are installed in "/usr/local/lib/python/" by default, where is the .所有创建的子目录都将在其名称中包含 Python 的版本号,例如库模块默认安装在“/usr/local/lib/python/”中,其中 . release number (eg "2.1").版本号(例如“2.1”)。 The Python binary is installed as "python" and a hard link named "python" is created. Python 二进制文件安装为“python”,并创建了一个名为“python”的硬链接。 The only file not installed with a version number in its name is the manual page, installed as "/usr/local/man/man1/python.1" by default.唯一没有安装名称中带有版本号的文件是手册页,默认安装为“/usr/local/man/man1/python.1”。

If you want to install multiple versions of Python see the section below entitled "Installing multiple versions".如果您想安装多个版本的 Python,请参阅下面标题为“安装多个版本”的部分。

The only thing you may have to install manually is the Python mode for Emacs found in Misc/python-mode.el.唯一可能需要手动安装的是在 Misc/python-mode.el 中找到的 Emacs 的 Python 模式。 (But then again, more recent versions of Emacs may already have it.) Follow the instructions that came with Emacs for installation of site-specific files. (但话又说回来,更新版本的 Emacs 可能已经有了它。)按照 Emacs 附带的说明安装特定于站点的文件。

暂无
暂无

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

相关问题 如何为 VSCode 安装以前版本的 Python 扩展 - How to install previous version of Python extension for VSCode 如何在 Linux 上安装另一个版本的 python? - How to install another version of python on Linux? 如何在 Linux 上安装软件包,用于 Python 2 与 pip 安装 ZA7F5F354213B9274117393 时 - How to install packages on Linux for Python 2 with pip when Python 3 is installed 如何使用自制软件在 macOS 中安装以前版本的 Python 3? - How can I install a previous version of Python 3 in macOS using homebrew? 如何在 Kali Linux 中安装 Python 3.6+ 版本? - How to install Python 3.6+ version in Kali Linux? 如何在Linux上安装和使用其他版本的python(python 2.7),默认python版本为python 2.6 - How install and use another version python(python 2.7) on linux with the default python version is python 2.6 安装自制软件 - 混淆版本和以前的安装 - 如何在没有警告的情况下安装所有内容? - Installation of homebrew - confusion over version and previous installation - how do I get everything installed without warnings? 安装较新版本后如何安装较旧版本的python - How to install older version of python when we have installed a newer version 如何在没有管理权限的情况下为linux安装lxml for python? - How to install lxml for python without administative rights on linux? 如何在预装python但没有root特权的Linux上安装Tkinter? - How to install Tkinter on linux with preinstalled python but without root privilege?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM