Python2

Python的下载和安装

1.下载Python安装包

官网链接

  • 下载安装包Python2
    Python2
    Python2

2.安装Python

Python2
Python2
Python2
Python2

3.检验是否安装成功

  • win键+R —>CMD —>回车—>输入Python
  • 命令行结构Python2
    Python2

4.pip工具的使用

  • pip的介绍
    Python官方的PyPi仓库为我们提供了一个统一的代码托管仓库,所有的第三方库,甚至你自己写的开源模块,都可以发布到这里,让全世界的人分享下载。
    python有两个著名的包管理工具easy_install和pip。在python 2中easy_install是默认安装的,而pip需要我们手动安装。随着Python版本的提高,easy_install已经逐渐被淘汰,但是一些比较老的第三方库,在现在仍然只能通过easy_install进行安装。目前,pip已经成为主流的安装工具,自Python2>=2.7.9或者Python 3.4以后默认都安装有pip
  • pip的使用
    在命令行下,输入pip,回车可以看到帮助说明:
    Python2
  • 查看pip的版本
  1. pip -V
  2. pip --version
    Python2
  • pip版本过低
    需要升级pip版本
  1. 解决命令:
    python -m pip install --upgrade pip
  2. 如果下载速度太慢,可以加上换源的方式升级
    python -m pip install --upgrade pip - ihttps://pypi.tuna.tsinghua.edu.cn/simple
    Python2
换源安装

豆瓣: http://pypi.douban.com/simple/
阿里∶ http://mirrors.aliyun.com/pypi/simple/
中国科学技术大学: http://pypi.mirrors.ustc.edu.cn/simple
清华:https://pypi.tuna.tsinghua.edu.cn/simple
例如: pip install SomePackage -i https://pypi.douban.com/simple

  • 普通安装库
    pip install requestsPython2
    Python2

  • 指定版本安装

  1. pip install somePackage
  2. pip install SomePackage1.0.5== #指定版本
  3. pip install 'SomePackage>=1.0.6 #最小版本
    升级指定的包,通过使用==,>=,<=,>,<来指定一个版本号。

Python2

  • 卸载已安装的库
    pip uninstall requests
    Python2
  • 列出已安装的库
    pip listPython2
  • 显示所安装包的信息
    pip show package
    Python2
  • 将已经安装的库列表保存到文本文件中
    pip freeze > D:\桌面\bao.txt
    Python2
    Python2
    注意后面要跟文件名,否则拒绝访问Python2
  • 批量下载导出来的包
  1. 使用pip freeze获取安装的 Python包
  2. pip install -r packages.txt
    Python2
  • 使用wheel文件安装
    除了使用上面的方式联网进行安装外,还可以将安装包也就是wheel格式的文件,下载到本地,然后使用pip进行安装。比如我在PYPI上提前下载的pillow库的wheel文件,后缀名为whl
    地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
    Python2
    可以使用pip install pillow-7.2xxxxxxx.whl的方式离线进行安装
  1. 安装 wheelPython2

  2. 找到下载的whl文件的目录进行安装以桌面为例)
    cd Desktop Python2

  3. 执行命令安装

  • 还可以直接去pycharm中直接下载
    打开pycharm----->点击File----->点击settings------>点击project------>点击projectinterpreter ------>点击’+'号,搜索你需要下载的库------>再点击Install Package下载
    Python2
    Python2
    Python2

pycharm的安装和配置

Python的解释器

  • 环境搭建就是安装Python的解释器
  • Python的解释器分类:
    • CPython(官方我们用的就是这个版本)用c语言编写的Python解释器
    • PyPy用Python语言编写的Python解释器
    • JPython用Java编写的Python解释器

Python2

  • 打开安装包Python2
    Python2
    Python2
    Python2
    Python2
    Python2
    Python2
    Python2
    Python2
    Python2
    Python2

  • 检查python解释器是否配置成功
    Python2
    Python2
    Python2
    Python2
    Python2

  • PyCharm的简单配置

    • 主题修改File–settings–apperance–theme
    • 代码字体修改File–settings–Editor-Font
    • 关闭更新File–settings—apperance—System Settings —Updates — Automatically check updates for取消打钩
    • 快捷键修改File–settings—apperance–Keymap选择自己习惯的
      快捷键方式
    • 自动导包File–settings—apperance–General—Auto lmport
      打钩
    • 进制打开上次的工程File–settings—apperance—System
      Settings —Reopen last project startup
    • 修改新建文件文件头File–settings–Editor—Code Style —File
      and Code Templates — Python Script
    • 修改字体编码File–settings–Editor—Code Style —File
      Encoding — Project Encoding
      Python2