How to Install and Use Python Pip on Ubuntu 14.04 and pip install pytz

3451 단어 python
import pytz
import datetime

tz = pytz.timezone('Asia/Shanghai')
cur_date = datetime.datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S')
print cur_date

python 시간 대 설정 - pytz 모듈:http://blog.csdn.net/starrain00/article/details/18323807
Introduction
Pip (Pip installs packages) is a package management tool used to install and manage programs written in Python. PyPa also recommends the use of Pip for installing and managing packages.
In this tutorial we will discuss how to install Pip on Ubuntu 14.04 and how to use Pip to install and manage commands.
Installing Pip
Python pip package is available on Ubuntu apt-get package repository. But before we can install pip, we have to install necessary packages to run pip.
# sudo apt-get update
# sudo apt-get install python-dev build-essential 

Now we can install Pip using the following command:
# sudo apt-get install python-pip

However the pip version included on Ubuntu apt-get can be outdated, we can upgrade pip to latest version by using command below.
# pip install --upgrade pip

Basic usage
Now that we have the latest version of pip installed, let's take a look at some commands that we can use to manage packages.
Installing packages using pip is easy, following is the command syntax that is used to install packages using pip.
# pip install 

It is also possible to specify an exact or minimum package version using the command syntax below.
# pip install package==1.5
# pip install package>=1.5

Upgrading a package using pip is done by use of the the argument  --upgrade  as we did when upgrading pip to the latest version.
# pip install --upgrade 

As much fun can Installing new packages be, we sadly sometimes have to uninstall packages too, we can uninstall packages using the command:
# pip uninstall 

More useful usage
Now that we have the basic of pip covered, let's take a look at what other things we can do with pip.
Search
If you ever forget a name of a package or need to look up if a package exists, you can search pip repository by using the following command:
# pip search 

Show
Show is used to find information such as version, author on a given installed package.
$sudo pip install pytz
# pip show pytz
---
Metadata-Version: 1.1
Name: pytz
Version: 2013.7
Summary: World timezone definitions, modern and historical
Home-page: http://pythonhosted.org/pytz
Author: Stuart Bishop
Author-email: [email protected]
License: MIT

List
We can also list all installed python packages including editables by using the following command. Packages are listed in a case-insensitive sorted order.
# pip list

Conclusion
Most python modules are available on pip and pip simplifies the process of installing and managing python modules. Pip is a very useful package management program that every python developer needs to and should know how to use.
source: https://syscoding.com/tutorials/27/how-to-install-and-use-python-pip-on-ubuntu-1404/

좋은 웹페이지 즐겨찾기