Python安裝
安裝Python及配置環境變量
一、博主自言
此篇文章是博主自學的筆記整理,順便分享給大家。
希望會對大家有所幫助,歡迎留言提問。
二、Python的安裝
2.1下載Python
下載地址:https://www.python.org/downloads/(目前最新版本爲Python3.8,以下安裝以3.6爲例)
根據自已的系統平臺選擇相應的版本進行下載。
2.2 安裝Python
2.2.1下載完成後雙擊執行下載的exe程序,進入安裝界面。
2.2.2安裝過程中記得勾選“Add Python 3.X to PATH”選項。安裝完成在開始菜單中生成Python3.X的目錄
- IDLE(Python 3.X 64-bit):Python自帶的IDE。
- Python 3.X( 64-bit):在Windows命令提示符下進入Python Shell模式。
- Python 3.X Manuals(64-bit):Python自帶的官方文檔。
- Python 3.X Module Docs(64-bit):Python的模塊文檔。它自動啓動一個服務,以Web形式顯示Python模塊的文檔。
2.2.3 安裝完畢後,打開CMD輸入python,返回版本號即安裝成功
2.3 配置環境變量
首先找到python安裝目錄,添加到“右擊我的電腦-屬性-高級系統變量-高級-環境變量-系統變量-Path-編輯-目錄粘貼到Path下面。
三、擴展庫的安裝
我們學習Python,例如要開發Web網站,我要做Web UI自動化測試,這就少不了要安裝第三方擴展庫。
所以,接下來可以在PyPI(Python Package Index)中查找想要的庫。
PyPI地址:https://pypi.python.org/pypi
3.1 pip 安裝擴展庫
pip是一個安裝和管理Python包的工具,通過pip來管理Python包非常簡單。
3.1.1 查看pip是否可用
運行CMD,輸入“pip”命令,出現命令說明,可以正常使用。(提示錯誤,到python目錄找到Scripts,添加到系統變量Path下面)。
C:\Windows\system32>pip
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to
WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
(a)bort.
--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the
certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is available for
download. Implied with --no-index.
--no-color Suppress colored output
C:\Windows\system32>pip show django
Name: Django
Version: 2.2.7
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: [email protected]
License: BSD
Location: c:\program files\python38\lib\site-packages
Requires: sqlparse, pytz
Required-by:
3.1.2 使用pip安裝擴展庫
pip install django
Django是Python下面開發Web項目非常強大的一個庫,也是接下來學習的重點。
3.1.3 使用pip安裝指定版本的庫
pip install django=1.10.3
3.1.4 查看當前安裝的庫
pip show django
使用show命令查看庫的版本號和安裝路徑。
3.1.5 使用pip卸載庫
pip uninstall django
使用uninstall命令即可裝安裝的庫輕鬆卸載。
總結
1、安裝Python,過程中勾選“Add Python 3.X to PATH”選項;
2、安裝完成後再Windows命令提示符下“python”命令,驗證是否安裝成功;
3、使用pip安裝Django擴展庫;