python pip安装ConfigParser/MySQL-python的Hack方案

python3.x下pip报错No module named 'ConfigParser'

cygwin下virtual-env的python3.6下安装 MySQL-python报错,错误消息如后,提示找不到ConfigParser模块,而事实上该模块在python3.x后改名了。那就照旧名做个包,引用进去。

文件 /path-to-you-python/site-packages/ConfigParser.py

内容如下(事实上只要第二行就行),再运行正常了。(当然mysql-python的其他依赖包之前已经安装过。)

"""compatible configparser"""
from configparser import *
$ pip install MySQL-python
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting MySQL-python
  Downloading https://mirrors.ustc.edu.cn/pypi/web/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 799kB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-install-pasqnywc/MySQL-python/setup.py", line 13, in 
        from setup_posix import get_config
      File "/tmp/pip-install-pasqnywc/MySQL-python/setup_posix.py", line 2, in 
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-pasqnywc/MySQL-python/
(py36)

python3.x下pip安装 pymysql 代替MySQL-python 的方案

MySQL-python/MySQLdb 模块实在太久没有更新了,MariaDB发布后,其devel包的文件与mysql-devel有所不同,将造成编译失败。网上有hack方案,照着做补丁编译实在太麻烦,其实完全可以使用pymysql代替。

pip install pymysql

安装pymysql

新建个文件 /path-to-you-python/site-packages/MySQLdb.py 内容如下

"""compatible MySQLdb"""
from pymysql import *
install_as_MySQLdb()

完工。

前述的错误消息示例如后。如果还没安装mysql-devel包,报错将如下:

    _mysql.c:44:10: fatal error: my_config.h: No such file or directory
     #include "my_config.h"

装过MariaDB的devel包安装会报如下编译错误:

    In file included from _mysql.c:44:0:
    /usr/include/mysql/my_config.h:3:2: warning: #warning This file should not be included by clients, include only <mysql.h> [-Wcpp]
     #warning This file should not be included by clients, include only <mysql.h>
      ^~~~~~~

 

 

macport pip install Cryptography/pyOpenSSL报错 Expected in: flat namespace

如题,macport pip安装pyOpenSSL过程中,要安装依赖包Cryptography,在该依赖包中,报错,经过不懈的查询,找到这篇文章 http://chriskief.com/2014/03/25/installing-cryptography-via-pip-with-macports-or-homebrew/comment-page-1/#comment-2809
按照作者的方案,要增加几个环境变量再pip,如下
sudo env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
记录并分享一下,再次感谢原作者Chris Kief