官术网_书友最值得收藏!

  • Learning Flask Framework
  • Matt Copperwaite Charles Leifer
  • 407字
  • 2021-07-30 10:18:33

Installing Python packages

Now that you have ensured that Python is installed correctly, we will install some popular Python packages that will be used over the course of this book.

We will be installing these packages system-wide but, once they are installed, we will be working exclusively in virtual environments.

Installing pip

The de-facto Python package installer is pip . We will use it throughout the book to install Flask and other third-party libraries.

If you already have setuptools installed, you can install pip by simply running the following command:

$ sudo easy_install pip

After completing the installation, verify that pip is installed correctly:

$ pip --version
pip 1.2.1 from /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg (python 2.7)

The version numbers are likely to change, so for a definitive guide please consult the official instructions, which can be found at http://www.pip-installer.org/en/latest/installing.html.

Installing virtualenv

Once pip is installed, we can proceed to install the most important tool in any Python developer's toolkit: virtualenv. Virtualenv makes it easy to produce isolated Python environments, complete with their own copies of system and third-party packages.

Why use virtualenv?

Virtualenv solves a number of problems related to package management. Imagine you have an old application that was built using a very early version of Flask, and you would like to build a new project using the most-recent version of Flask. If Flask was installed system-wide, you was be forced to either upgrade your old project or write your new project against the old Flask. If both projects were using virtualenv, then each could run its own version of Flask, with no conflicts or issues.

Virtualenv makes it easy to control which versions of the third-party package is used by your project.

Another consideration is that installing packages system-wide generally requires elevated privileges (sudo pip install foo). By using virtualenvs, you can create Python environments and install packages as a regular user. This is especially useful if you are deploying to a shared hosting environment or are in a situation where you do not have administrator privileges.

Installing virtualenv with pip

We will use pip to install virtualenv; since it is a standard Python package, it can be installed just like any other Python package. To ensure that virtualenv is installed system-wide, run the following command (it requires elevated privileges):

$ sudo pip install virtualenv
$ virtualenv --version
1.10.1

The version numbers are likely to change, so for a definitive guide please consult the official instructions at http://virtualenv.org.

主站蜘蛛池模板: 衡南县| 驻马店市| 云梦县| 财经| 万源市| 新乡市| 临夏市| 修武县| 吉首市| 论坛| 通城县| 兴城市| 潼南县| 泊头市| 诸暨市| 上思县| 沁源县| 上栗县| 安化县| 铜川市| 崇礼县| 昆山市| 胶州市| 阿克陶县| 侯马市| 昌乐县| 广东省| 乐至县| 普格县| 龙山县| 湘潭县| 新乡市| 自治县| 开江县| 天峨县| 淮安市| 抚顺县| 盘山县| 凤阳县| 杭州市| 太仆寺旗|