Pylons  - 讨论区

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

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

Step By Step
一步一步

The Python Package Index
Python软件包索引

All Python packages can be downloaded from a special part of the Python website known as the Python Package Index (PyPI). As well as providing the packages themselves, the Python Package Index also contains information about each packages such as the author, the projects homepage and a description of the project. Python packages can contain Python source code, configuration files, data files, C or C++ extensions and meta data about the package.

所有Python软件包都可以从Python网站的一个特殊部分,Python Package Index (PyPI)下载。除提供的软件包本身之外,PyPI还包含每一个软件包的相关信息,如作者,项目主页,项目介绍等。Python软件包中可以包含源代码,配置文件,数据文件,C或C + +扩展和关于包的元数据。

The Python Package Index can be found at  http://pypi.python.org/  but most of the time you do not need to worry about PyPI as the easy_install script takes care of everything for you including finding a package on the Python Package Index, getting the latest compatible version and installing the package and its dependencies.

PyPI在 http://pypi.python.org/ ,但大部分时间则不必关心PyPI,因为easy_install脚本可以为你做好一切工作,包括在PyPI查找软件包,获取最新的兼容版本,安装软件包及其依赖的包。

In Part 3 of the book you'll learn how you can package up your Pylons applications and automatically upload them to PyPI but for the moment you only need to know that PyPI is the main place where Python software can be found.

在本书第3部分你将了解到如何将你的Pylons应用打包和将它们自动上传到PyPI,但目前你只需要知道,PyPI是获取Python软件的主要地方。

Virtual Python Environments
虚拟Python环境

A virtual environment is an isolated Python environment set up in such a way that the libraries do not affect programs outside it, making it a good choice for experimenting with new packages or to deploy different programs with conflicting library requirements. You can also create a virtual Python environment and install software to it without requiring root or administrator privileges making it a very useful technique for installing Pylons in a shared environment. It is highly recommended you install Pylons this way if it's your first time using it.

虚拟环境是一个孤立的Python环境,以这种方式建立的环境,类库不会影响环境之外的程序,这使其成为一个很好的选择,可以尝试新的软件包或部署不同的类库要求有冲突的程序。你也可以创建一个虚拟的Python环境,安装软件到其中,无需root用户或管理员的权限,这使它成为一项非常有用的技术,可以将Pylons安装到一个共享的环境。强烈建议您用这种方式安装Pylons,如果这是你第一次使用它的话。

There are a number of tools available in the Python community for creating a virtual Python environment but the two most popular are virtualenv.py and Buildout. Buildout is popular in the Zope community because it has lots of features which help you manage all aspects of a deployment but it can be rather complicated. virtualenv.py is a lighter solution designed to just handle the creation of a virtual Python environment which makes it perfect for most use cases involving Pylons.

目前在Python社区,有一些工具可以建立一个虚拟的Python环境,有两个最流行,分别是virtualenv.py和Buildout。Buildout在Zope社区很受欢迎,因为它有很多的特性,可以帮助你管理部署的所有方面,但相当复杂。virtualenv.py是一个轻量型的解决方案,只是处理虚拟的Python环境的建立,这使得它完美适用于大多数的案例,包括Pylons。

To create a virtual environment you need the virtualenv.py bootstrapping script. The current version of this script at the time of writing the book is available at  http://pylonsbook.com/virtualenv.py  and many Linux distributions provide a python-virtualenv package but you will probably want to use the most recent version available instead. To obtain the latest version visit the Python Package Index and search for virtualenv. Download the .tar.gz version of the software and extract the virtualenv.py file from the distribution.

要创建一个虚拟环境你需要virtualenv.py引导脚本。在撰写这本书时,当前版本的脚本可以在 http://pylonsbook.com/virtualenv.py 得到,许多Linux发行版也提供了python-virtualenv软件包,但您可能会想要使用最新版本。要获取最新版本,访问PyPI并查找virtualenv。下载.tar.gz版本的软件包,并从中提取virtualenv.py。

You can do so like this with commands similar to this, but be sure to update them for the version you wish to download:

你可以这样运行与此类似的命令,但如果想要下载使用软件包的其它版本,则需要更新命令中的版本号:

wget  http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.1.tar.gz
tar zxfv virtualenv-1.1.tar.gz
cp virtualenv-1.1/virtualenv.py ./

You can now remove the old files if you like:

如果你想的话,可以马上删除旧的文件:

rm -r virtualenv-1.1
rm virtualenv-1.1.tar.gz

Windows users will need to download the file manually because wget is not available and use a tool such as 7-zip from  http://www.7-zip.org/  to extract the files. Mac users and some Linux users will need to use curl -O instead of wget to download the file. 
Windows用户需要手动下载文件,因为wget无法提供,使用的工具,如7-zip需从 http://www.7-zip.org/ 获取,然后用之提取文件。Mac用户和一些Linux用户需要使用curl -O代替wget下载文件。

Note

If you are using a system which already has the easy_install program installed you could instead install virtualenv automatically like this:

注意: 
如果您使用的系统中,已经安装了easy_install程序,你可以这样自动安装virtualenv:

easy_install virtualenv

The virtualenv.py script will then be available in your Python installation's bin or Scripts directory.

virtualenv.py脚本则会安装到你的Python安装目录的bin子目录中或Scripts子目录。

Whichever way you chose to obtaine the virtualenv.py script you can now use it to create an isolated virtual Python environment to keep your Pylons libraries separate from other libraries on your system.

无论您选择那种方式获取virtualenv.py 脚本,现在您可以使用它来建立一个孤立的虚拟Python环境,使Pylons与系统中的其他类库分开。

You are now ready to create a virtual Python environment. Here's how it looks on Windows:

现在你已经准备好创建一个虚拟Python环境。以下是在Windows中的情况:

C:\>C:\Python25\python.exe "C:\Documents and Settings\Administrator\Desktop\virt
ualenv-1.1\virtualenv.py" C:\env
New python executable in C:\env\Scripts\python.exe
Installing setuptools...............................done.

Windows users shouldn't create the virtual python environment in a path with a space. Otherwise you may see an error similar to this:

Windows用户不应在含有空格的路径中建立虚拟环境。否则您可能会看到与此类似的一个错误:

ValueError: The executable 'C:\\Documents and Settings\\Administrator\\Desktop\\
env\\Scripts\\python.exe' contains a space, and in order to handle this issue you must have the win32api module installed

As the error suggests, installing the win32api module from  http://sourceforge.net/project/showfiles.php?group_id=78018  fixes this issue.

错误建议,安装win32api模块 http://sourceforge.net/project/showfiles.php?group
_id=78018修正这个问题。

On Linux platforms you should ensure you have the python-dev package for your Python version installed, otherwise the virtualenv.py script might complain about include files.

在Linux平台上你应确保你已安装与你的Python版本一致的python-dev软件包,否则virtualenv.py脚本提示错误不包含文件。

It is also worth noting for advanced users that a virtual Python environment is not necessarily compatible with a customised distutils.cfg file.

高级用户还值得注意的是,虚拟Python环境不是必须符合定制的distutils.cfg文件。

Not everyone chooses to use a virtual Python environment. If you are an experienced user it is perfectly possible to run multiple Pylons applications from the system Python installation. Using a virtual Python environment helps you avoid dependency problems though. If you choose not to use a virtual Python environment you will will need to install the easy_install program yourself. Download the ez_setup.py file from http://peak.telecommunity.com/dist/ez_setup.py  and then run this command:

不是每个人都选择使用一个虚拟的Python环境。如果您是一位经验丰富的用户,完全有可能在Python系统安装环境运行多个Pylons应用。使用一个虚拟的Python环境可以帮助你避免依赖性问题。如果你选择不使用虚拟的Python环境,你将需要安装easy_install程序。从 http://peak.telecommunity.com/dist/ez_setup.py 下载ez_setup.py文件,然后运行下面的命令:

$ python ez_setup.py

原文: http://hi.baidu.com/zhuifengdenanhai/blog/item/9b28dea221b126aacbefd08f.html

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

    你的回复:

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

    Zeuux © 2024

    京ICP备05028076号