2015-06-03 63 views
6

首先,我開發一個Django應用程序,當我嘗試運行與服務器:錯誤,virtualenv中

蟒蛇manage.py的runserver 0.0.0.0:8000

終端所示:

"django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb" 

所以,我需要來安裝該包:

(app1)Me% pip install MySQL-python 

錯誤:

Collecting mysql-python 
    Using cached MySQL-python-1.2.5.zip 
Building wheels for collected packages: mysql-python 
    Running setup.py bdist_wheel for mysql-python 
    Complete output from command /Users/GFTecla/Documents/shoutout/bin/python -c "import setuptools;__file__='/private/var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/pip-build-ZMQOQm/mysql-python/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/tmp1JfTpfpip-wheel-: 
    running bdist_wheel 
    running build 
    running build_py 
    creating build 
    creating build/lib.macosx-10.5-intel-2.7 
    copying _mysql_exceptions.py -> build/lib.macosx-10.5-intel-2.7 
    creating build/lib.macosx-10.5-intel-2.7/MySQLdb 
    copying MySQLdb/__init__.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    copying MySQLdb/converters.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    copying MySQLdb/connections.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    copying MySQLdb/cursors.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    copying MySQLdb/release.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    copying MySQLdb/times.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    creating build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb/constants 
    running build_ext 
    building '_mysql' extension 
    creating build/temp.macosx-10.5-intel-2.7 
    gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.23/include/mysql -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.5-intel-2.7/_mysql.o -g -fno-omit-frame-pointer -fno-strict-aliasing 
    In file included from _mysql.c:44: 
    /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:348:11: warning: 'SIZEOF_SIZE_T' macro redefined 
    #define SIZEOF_SIZE_T SIZEOF_LONG 
      ^
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:43:17: note: previous definition is here 
    #  define SIZEOF_SIZE_T   8 
       ^
    In file included from _mysql.c:44: 
    /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:442:9: warning: 'HAVE_WCSCOLL' macro redefined 
    #define HAVE_WCSCOLL 
     ^
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyconfig.h:911:9: note: previous definition is here 
    #define HAVE_WCSCOLL 1 
     ^
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] 
      if (how < 0 || how >= sizeof(row_converters)) { 
       ~~~^~ 
    3 warnings generated. 
    gcc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot/-Qunused-arguments -Qunused-arguments build/temp.macosx-10.5-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.6.23/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.5-intel-2.7/_mysql.so 
    ld: library not found for -lbundle1.o 
    clang: error: linker command failed with exit code 1 (use -v to see invocation) 
    error: command 'gcc' failed with exit status 1 

    ---------------------------------------- 
    Failed building wheel for mysql-python 
Failed to build mysql-python 
Installing collected packages: mysql-python 
    Running setup.py install for mysql-python 
    Complete output from command /Users/GFTecla/Documents/shoutout/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/pip-build-ZMQOQm/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/pip-YOrOKA-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/GFTecla/Documents/shoutout/bin/../include/site/python2.7/mysql-python: 
    running install 
    running build 
    running build_py 
    copying MySQLdb/release.py -> build/lib.macosx-10.5-intel-2.7/MySQLdb 
    running build_ext 
    building '_mysql' extension 
    gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.23/include/mysql -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.5-intel-2.7/_mysql.o -g -fno-omit-frame-pointer -fno-strict-aliasing 
    In file included from _mysql.c:44: 
    /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:348:11: warning: 'SIZEOF_SIZE_T' macro redefined 
     #define SIZEOF_SIZE_T SIZEOF_LONG 
      ^
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:43:17: note: previous definition is here 
    #  define SIZEOF_SIZE_T   8 
        ^
    In file included from _mysql.c:44: 
    /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:442:9: warning: 'HAVE_WCSCOLL' macro redefined 
    #define HAVE_WCSCOLL 
      ^
    /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyconfig.h:911:9: note: previous definition is here 
    #define HAVE_WCSCOLL 1 
      ^
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] 
      if (how < 0 || how >= sizeof(row_converters)) { 
       ~~~^~ 
    3 warnings generated. 
    gcc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot/-Qunused-arguments -Qunused-arguments build/temp.macosx-10.5-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.6.23/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.5-intel-2.7/_mysql.so 
    ld: library not found for -lbundle1.o 
    clang: error: linker command failed with exit code 1 (use -v to see invocation) 
    error: command 'gcc' failed with exit status 1 

    ---------------------------------------- 
Command "/Users/GFTecla/Documents/shoutout/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/pip-build-ZMQOQm/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/pip-YOrOKA-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/GFTecla/Documents/shoutout/bin/../include/site/python2.7/mysql-python" failed with error code 1 in /private/var/folders/9g/1qrws9yj3wn7lghlrpgyh9cc0000gn/T/pip-build-ZMQOQm/mysql-python 

我有OS X 10.10.2

的Django 1.8.2

的Python 2.7

+0

'的virtualenv --version' 13.0.1 – aguilarpgc

回答

24

的解決方案是在重新安裝開發工具:

xcode-select --install 
+0

不知何故此解決方案有效...任何想法,爲什麼? – viviwill

+0

@viviwill我相信它安裝了編譯mysql所需的gcc版本 – Hortitude

1

什麼固定它對我來說是:

sudo pip install --upgrade setuptools

確保你有MySQL的安裝:

brew install mysql