macOS系统Python+MySQL+Django环境配置

说明:系统版本为macOS Catalina 10.15.4,系统自带Python版本为Python 2.7.16
以下环境是根据项目中的requirements.txt记录的依赖包及其版本号来进行部署的。
Django==1.11.20 django-cors-headers==2.4.0 MySQL-python==1.2.5 python-jenkins==1.4.0 requests==2.6.0

  1. 安装Python:
    因为系统自带的Python环境和项目的需求一致,所以这块没有自己进行配置。需要Python 3等环境可去Python官网下载所需版本的安装包进行安装。如果是在终端使用brew install python3安装,一般都是下载比较新的版本,注意所下载版本号是否合适。

  2. 安装MySQL
    MySQL安装之前要结合环境要求的驱动来进行版本的选择,因为本项目以来的驱动版本号为MySQL-python==1.2.5,通过MySQL-python官网查询到其支持的MySQLPython环境为:

    MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported.

    因此到 MySQ官网下载了MySQL 5.5版本进行安装。如果是在终端使用brew install mysql安装,一般都是下载比较新的版本。

  3. 安装MySQL驱动
    由于MySQL服务器以独立的进程运行,并通过网络对外服务,所以,需要支持PythonMySQL驱动来连接到MySQL服务器。项目依赖的驱动为MySQL-python,在终端使用pip install MySQL-python==1.2.5安装。

  • 安装过程中遇到的问题
    • 安装驱动过程中,使用pip install MySQL-python==1.2.5一直报错'my_config.h' file not found
      _mysql.c:44:10: fatal error: 'my_config.h' file not found
       #include "my_config.h"
                ^~~~~~~~~~~~~
       1 error generated.
       error: command 'cc' failed with exit status 1
       ----------------------------------------
       ERROR: Failed building wheel for MySQL-python
      
      几乎试遍了网上所有能试的方法,再试了stackoverflow上的高赞解决方案还没成功后,我甚至重装了电脑系统,所有重新来过也没有解决这个问题。
      折腾了好久才发现是因为一开始没有意识到MySQL-python驱动版本号较低,不能支持最新的MySQL,安装MySQL之前没考虑过其版本的问题,直接使用命令brew install MySQL安装,安装的就是最新的版本。
    • pip install xxxx显示报错
      ERROR: Could not find a version that satisfies the requirement python-jenkins==1.4.0 (from versions: none)
      ERROR: No matching distribution found for python-jenkins==1.4.0
      
      参考这篇博客,更换安装源,加上·pip install python-jenkins==1.4.0 --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple,问题就解决了。

猜你喜欢

转载自blog.csdn.net/weixin_41524366/article/details/106307147
今日推荐