Category: Python

  • pip 源

    douban

    pip install requests -i https://pypi.douban.com/simple
    

    aliyun

    pip install requests -i https://mirrors.aliyun.com/pypi/simple
    

    私有 nexus 源

    pip install requests -i https://nexus.example.com/nexus/repository/pip-internal/simple
    
    
  • brew 切换 python 版本

    切换 python 至 3.6.5

    brew list python --versions
    brew switch python 3.6.5
    

    升级 python3

    brew install python3
    

    link 切换

    ➜  ✗ brew link python
    Linking /usr/local/Cellar/python/3.7.7... 
    Error: Could not symlink Frameworks/Python.framework/Headers
    Target /usr/local/Frameworks/Python.framework/Headers
    is a symlink belonging to python@2. You can unlink it:
      brew unlink python@2
    解除 python@2 link
    Unlinking /usr/local/Cellar/python@2/2.7.17... 34 symlinks removed
    
    
    To force the link and overwrite all conflicting files:
      brew link --overwrite python
    
    To list all files that would be deleted:
      brew link --overwrite --dry-run python
    ➜  ✗ brew link python --overwrite python
    Linking /usr/local/Cellar/python/3.7.7... 28 symlinks created
    
  • python date相减

    python 计算时间相差天数

    from datetime import date
    
    d0 = date(2008, 8, 18)
    d1 = date(2008, 9, 26)
    delta = d0 - d1
    print delta.days
    
  • python smtplib 发邮件

    http://www.mkyong.com/python/how-do-send-email-in-python-via-smtplib/

  • centos7 python 升级

    脚本

    #!/bin/bash
    
    yum install -y gcc make
    cd /usr/src
    curl -O https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
    tar xzf Python-2.7.12.tgz
    cd Python-2.7.12
    ./configure
    make altinstall
    

    CentOS 7 安装 python 3.6.5

    sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
    sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
    

    CentOS 7.7, Python 3 is available in the base package repository

    # cat /etc/redhat-release 
    CentOS Linux release 7.7.1908 (Core)
    # yum install -y python3 python3-devel
    
  • python读取ini

    http://wklken.me/posts/2012/02/19/python-ini-configparser.html