Pylons  - 讨论区

标题:转:【翻译】The Definitive Guide to Pylons(十三)

2010年10月22日 星期五 17:09

Windows

If you are using Windows 95, 98, NT, 2000, ME, XP, 2003 Server or Vista you can download the Python installer from  http://python.org/download/ . At the time of writing the latest version is Python 2.5.1. Once you have downloaded the correct version for your platform (which will usually be the x86 version) you simply double click the python-2.5.1.msi file and follow the installation instructions.

如果您是使用Windows 95,98,NT,2000,ME,XP,2003服务器或Vista,你可以从 http://python.org/download/ 下载Python安装程序。在撰写本文时,最新版本是Python 2.5.1。一旦你为您的平台(这通常会是x86版本)下载了正确的版本,你只需双击python - 2.5.1.msi文件,按照安装说明操作。

 


Figure 2-2. The Python 2.5 Installer running on Windows XP
图2-2.运行于Windows XP的Python 2.5安装程序

Note

To use the installer, the Windows system must support Microsoft Installer 2.0. Just save the installer file to your local machine and then run it to find out if your machine supports MSI. Windows XP and later already have MSI but many older machines will already have MSI installed too.

If your machine does not have the Microsoft Installer you can download it:

Windows 95, 98 and ME platforms use this version:  http://www.microsoft.com/downloads/details.aspx?FamilyID=cebbacd8-c094-4255-b702-de3bb768148f&displaylang=en

Windows NT 4.0 and 2000 use this version:  http://www.microsoft.com/downloads/details.aspx?FamilyID=4b6140f9-2d36-4977-8fa1-6f8a0f5dca8f&DisplayLang=en

注意:  
要使用安装程序,Windows系统必须支持Microsoft Installer 2.0搭配使用。只要保存安装文件到本地计算机,然后运行它,看看你的机器支持MSI。Windows XP和更高版本已经有MSI,很多老机器也可以安装MSI。 
如果你的机器没有此安装程序,可以下载它: 
Windows 95,98和ME平台使用此版本:  http://www.microsoft.com/downloads/details.aspx?FamilyID=cebbacd8-c094-4255-b702-de3bb768148f&displaylang=en  
Windows NT 4.0和2000年使用此版本:  http://www.microsoft.com/downloads/details.aspx?FamilyID=4b6140f9-2d36-4977-8fa1-6f8a0f5dca8f&DisplayLang=en

 

On Windows, any scripts which are installed by third party packages will be put in the Scripts directory of your Python installation, typically C:\Python25\Scripts. By default neither this directory nor your main Python executable are on your PATH so you will not be able to run Python itself or any Python scripts from a Command Prompt unless you first navigate to the correct directory or specify the full path each time.

在Windows环境下,第三方软件包安装后的脚本都将放在Python安装目录中的Scripts目录下,通常为C:\Python25\Scripts。默认情况下,Python安装目录和主Python可执行文件都没放在PATH中,因此,你将无法在命令提示符中运行Python或任何的Python脚本,除非每次你首先都浏览到正确的目录或指定完整的路径。

To fix this and save yourself a lot of typing in the future you should add some directories to your PATH environment variable. Luckily, this is straightforward to do so the examples in this book will assume you have set up your path correctly.

要解决此问题,在以后节省很多的打字,你应该添加一些目录到你的PATH环境变量。幸运的是,这是很容易做到的,因此,在这本书中的例子将假定你已经设定了正确的路径。

Of course if you are using a virtual Python environment you should specify the Scritps directory within the virtual Python environment rather than the system Python or you could activate your virtual Python environment instead as described earlier in the chapter.

当然,如果你使用的是一个虚拟的Python环境,你应该指定虚拟的Python环境下的Scritps目录,而不是系统的Python,或者可以按照早先本章中所描述的,激活虚拟的Python环境。

If you are using Windows 95, 98 or ME you can do the following:
如果你使用的是Windows 95,98或ME,你可以做以下几点工作:

1. Edit your C:\autoexec.bat file, and add the following line to the end of the file:
编辑你的C:\autoexec.bat文件,添加以下行到文件结束处:

set PATH=%PATH%;C:\Python25\;C:\Python25\Scripts

2. Restart your computer.
重新启动计算机。

If you are using Windows 2000 or Windows XP you can do the following:
如果你使用的是Windows 2000或Windows XP ,你可以做以下几点工作:

1. From the desktop or Start Menu, right click My Computer and click Properties.
从桌面或开始菜单中,右键点击我的电脑,然后单击属性。

2. In the System Properties window, click on the Advanced tab.
在系统属性窗口中,点击高级选项卡。

3. In the Advanced section, click the Environment Variables button.
在高级选项部分,点击环境变量按钮。

4. Finally, in the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. Add the text C:\Python25\;C:\Python25
\Scripts to the end of the path. Each different directory should be separated by a semicolon so the end of your path might look something like this:

最后,在环境变量窗口中,在系统变量部分选择path变量,并点击编辑。新增C:\Python25\;C:\Python25\Scripts到path结尾。每一个不同的目录应该由分号分隔,因此,你的path结尾看起来应该像这样:

C:\Program Files;C:\WINDOWS;C:\WINDOWS\System32;C:\Python25\;C:\Python25\Scripts

5. You might need to restart computer for the change to take effect.
您可能需要重新启动计算机以使更改生效。

 

Figure 2-3 Configuring your PATH on Windows XP
图2-3在Windows XP配置你的路径

To test your installation has worked and your path is configured correctly you should click Start->Run... and enter the text cmd in the input field. When you click OK a Windows Command Prompt will load. You can then run Python by typing python at the prompt. You should see something similar to what is shown in the image below.

要测试你的安装可以工作,你的path是正确配置,你应该单击开始->运行...并在输入框中输入cmd。当你单击确定,Windows命令提示符会启动。然后,可以在提示符后输入python运行Python解释器。你应该会看到类似的东西,如在下方的图片显示的。


Figure 2-4 Windows command prompt running Python
图2-4 Windows命令提示符下运行Python

If so the installation has worked. To exit the Python interactive interpreter you can press CTRL+z followed immediately by pressing the Enter key.

如果是这样,表示安装可以工作。要退出Python交互式解释器,你可以按Ctrl + Z,然后立即按下回车键。

Tip

When you develop Pylons applications you will find you frequently need access to a Windows Command Prompt. It can be quickly become quite tedious to load a Command Prompt from the Run option on the Start menu and then manually navigate to the directory containing your Pylons application. To make life easier Microsoft has released an extension called the "Open Command Here Powertoy" which allows you to right click on a directory and load a command prompt at that location by choosing Open Command Window Here from the menu. You can download the extension from http://www.microsoft.com/windowsxp/downloads/powertoys/xp
powertoys.mspx

提示  
当你开发Pylons应用,你会发现你经常需要访问Windows命令提示符。使用在开始菜单上的运行选项加载命令提示符,然后手动浏览到包含Pylons的应用的目录,这会很快变得相当乏味。为了使生活更轻松,Microsoft发布了一个名为“Open Command Here Powertoy”的扩展,你可以右键点击一个目录,选择Open Command Window Here的菜单,在该地点启动命令提示符。你从这可以下载这个扩展 http://www.microsoft.com/windo
wsxp/downloads/powertoys/xppowertoys.mspx

 

 

There are two slight complications to be aware of when developing Python applications on Windows. The first is that paths on Windows use the \ character as a path separator rather than the / character used on Linux and Mac OS X platforms. The \ character is treated as an escape character in strings within Python source code so you cannot use Windows paths in source code strings without first escaping the \ characters. You can do this by adding an extra \ character before each \ in the string. For example a Windows path might be written like this:

当在Windows上开发Python应用程序时,有两个轻微并发症必须意识到。第一,在Windows中的路径使用\字符作为路径分隔符,而不是/字符,这是在Linux和Mac OS X平台上使用的。而在Python源代码中,\字符被视为字符串内的转义字符,因此,不首先摆脱\字符,你无法在源代码字符串中使用Windows路径。这可以通过在每个\中的字符串之前增加额外的\字符解决。例如,Windows路径可能会写成这样:

my_path = "C:\\Documents and Settings\\James\\Desktop\\Pylons"

Luckily Python also treats / characters in paths on the Windows platform as path separators so you can also write the same path like this:
幸运的是,Python也使用/字符作为在Windows平台上的路径的分隔符,这样你也可以将相同的路径写成这样:

 

my_path = "C:/Documents and Settings/James/Desktop/Pylons"

Note

Rather than writing out different versions of commands for both Windows, Linux and Mac OS X platforms throughout this book we will instead assume you have set up the C:\Python25\Scr
ipts directory to be on your PATH. Also, we will write any paths using / characters rather than \ characters so please be aware that you may have to interpret these slightly differently on Windows.

注意:  
为了不写不同版本的命令以适用Windows,Linux和Mac OS X平台,在整个这本书,我们将假设你在PATH中设置了C:\Python25\Scripts目录。此外,我们将使用/字符书写所有的路径,而不是\字符,因此,请注意Windows中,你可能需要转换这些略有不同的地方。


The second slight complication is in the way Windows treats line end characters. On UNIX-like platforms the newline character \n is treated as the line end whereas on Windows the characters \r\n are used. If you have ever loaded a file in Notepad and wondered why it shows an enitre paragraph as one long line it is likely that the file was written on a UNIX-like platform and Notepad simply didn't understand the line end characters.

 

第二轻微并发症的方式是Windows对待行结束字符的方式。在类UNIX平台,换行符\n是被视为一行的结束,而在Windows,使用字符\ r \ n。如果你曾经在记事本中打开一个文件,看到它将一段文本显示为一行,很可能是该文件是在类UNIX平台书写的,记事本根本不理解行结束字符。

Luckily Python understands line end issues and will work equally well regardless of the line end characters used but not all software does. It is generally easiest to stick to one type of line end character. If you are going to deploy your software on a UNIX-like platform you should strongly consider writing all your Python source files with UNIX-style line ends even if you are using Windows. Although FTP software frequently tries to translate Windows line ends to UNIX-style line ends you can save yourself the complication by simply using UNIX line ends to start with.

 

幸运的是,Python理解换行符的问题,工作得一样好,不论使用哪种行结束字符,这并非所有的软件都做到的。人们通常容易坚持一类行结束字符。如果你要在类UNIX平台部署你的软件,你应该认真考虑所有的Python源文件用UNIX风格的行结束符,即使你使用的是Windows。虽然FTP软件经常尝试翻译Windows行结束符为Unix风格的,你只需使用UNIX行结束符开始编写,就可以远离这种问题。

Tip

Python comes with a built-in editor called IDLE for editing Python source files which you can read about at  http://www.python.org/idle/doc/idle2.html . IDLE is a very powerful IDE but unfortunately has no option for choosing which line end characters to use.

One free editor which does allow you to choose which line ends to use is called SciTE and can be downloaded from http://scintilla.sourceforge.net/SciTEDownload.html . You can choose your line end characters from the Menu by clicking Options->Line End Characters. The options are CR+LF, CR or LF. LF stands for Line Feed and is the UNIX line end character written \n in Python strings, CR stands for Carriage Return. Windows uses carriage returns and line feeds represented as \r\n in Python strings. If you want to convert from one type of line end to another you can use the Convert Line End Characters option from the Options menu.

提示 
Python带有一个内置的IDLE编辑器,编辑Python源文件,你可以阅读有关在 http://www .
python.org/idle/doc/idle2.html。IDLE是一个非常强大的IDE,但不幸的是,没有任何关于选择使用哪一种行结束字符的选项。 
一个叫SciTE的免费编辑器可以让你选择行结束符,可从 http://scintilla.sourceforge.net/
SciTEDownload.html下载。你可以在菜单点击Options->Line选择行结束字符。选项为CR+LF, CR 和 LF。LF表示Line Feed,是UNIX的行结束字符,如Python字符串中的\ n,CR表示回车\r。Windows使用回车和line feeds ,如Python字符串中的\r\n。如果你想将一种类型的行结束符转换为另一种,你可以从选项菜单使用转换行结束符选项。


Figure 2-5 SciTE line endings menu screenshot.
图2-5 SciTE行结尾符的菜单画面。

 

Summary
总结

You should now have a very good understanding of all the different tools and techniques used for setting up Python and Pylons and hopefully you have a virtual Python environment set up and ready to go. With everything in place it's time to move onto the next chapter and get started learning Pylons.
你现在应该对用于设立Python和Pylons环境的所有不同工具和技术有一个很好的了解,并希望你有一个已建立虚拟的Python环境,然后一切就绪准备开始。随着这一切的发生,是时候翻开下一章并开始学习Pylons。

原文: http://hi.baidu.com/zhuifengdenanhai/blog/item/136c34873814552dc65cc38f.html

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号