Question

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.

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.

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:

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? What if I didn't have the first version of Python installed? I know it's shipped with most Linux but hypothetically -- how does such a seeming catch-22 like that work?

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. 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. 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. 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!!

Était-ce utile?

La solution

Try to read this SO question.

Also read this thread. I hope you solve the problem.

Autres conseils

The installation procedure is described in multiple places.

It's all right in the README...

You don't need to use python to install, in fact, you shouldn't...just:

./configure
make
make install

If you want to install in a specific dir, just follow what the README says:

Installing

To install the Python binary, library modules, shared library modules (see below), include files, configuration files, and the manual page, just type

    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 theexec_prefix' Make variable (defaults to the --prefix directory) is given.

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.

All subdirectories created will have Python's version number in their name, e.g. the library modules are installed in "/usr/local/lib/python/" by default, where is the . release number (e.g. "2.1"). The Python binary is installed as "python" and a hard link named "python" is created. 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.

If you want to install multiple versions of Python see the section below entitled "Installing multiple versions".

The only thing you may have to install manually is the Python mode for Emacs found in Misc/python-mode.el. (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.

EDIT: virtualenv is apparently for already-installed Python versions. Disregard this recommendation.

I think what you want is 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.

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? 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.

EDIT: Upon review, I think you want Alberto's answer, so I voted him up for visibility.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top