- 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.
- Kali Linux Web Penetration Testing Cookbook
- Delphi程序設計基礎:教程、實驗、習題
- 企業級Java EE架構設計精深實踐
- 大學計算機應用基礎實踐教程
- OpenCV實例精解
- OpenNI Cookbook
- Practical DevOps
- Bootstrap Essentials
- 可解釋機器學習:模型、方法與實踐
- Mastering Drupal 8 Views
- Python編程:從入門到實踐
- Express Web Application Development
- 運用后端技術處理業務邏輯(藍橋杯軟件大賽培訓教材-Java方向)
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- Buildbox 2.x Game Development