V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
paloalto
V2EX  ›  macOS

升级ML后,python的开发环境悲剧了。

  •  
  •   paloalto · 2012-07-26 23:30:17 +08:00 · 7185 次点击
    这是一个创建于 4533 天前的主题,其中的信息可能已经有所发展或是发生改变。
    (︸_︸) 不知道哪里出了问题。

    以前好不容易才搭好的,最近用着特顺手,结果升级之后发现少了好多东西?(本来只剩5G空间的,升级之后变成了50多G)。mysql之类的好在,但是web.py、mysqldb什么的都需要重新装。/library/python/2.7/site-packages里空空如也。

    LZ正在苦逼的装包中。

    ( >﹏<。)
    13 条回复    1970-01-01 08:00:00 +08:00
    paloalto
        1
    paloalto  
    OP
       2012-07-26 23:36:58 +08:00
    mysql-python还装不上。。。

    $ sudo easy_install mysql-python
    Searching for mysql-python
    Reading http://pypi.python.org/simple/mysql-python/
    Reading http://sourceforge.net/projects/mysql-python/
    Reading http://sourceforge.net/projects/mysql-python
    Best match: MySQL-python 1.2.3
    Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
    Processing MySQL-python-1.2.3.tar.gz
    Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-KsFBj4/MySQL-python-1.2.3/egg-dist-tmp-5MHDrO
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
    unable to execute clang: No such file or directory
    error: Setup script exited with error: command 'clang' failed with exit status 1
    pepsin
        2
    pepsin  
       2012-07-26 23:42:30 +08:00
    Ruby的情况是有些需要gcc的因为gcc丢失出错了,Xcode把command line tool装上然后重新link一下就好了。或许你的一些情况类似这个?
    nichan
        3
    nichan  
       2012-07-26 23:43:34 +08:00
    开虚拟机吧233
    nichan
        4
    nichan  
       2012-07-26 23:45:52 +08:00
    正经的说, 开虚拟机用linux做, 坏了大不了重开一个, 自己的系统折腾起来挺麻烦的。
    paloalto
        5
    paloalto  
    OP
       2012-07-26 23:55:16 +08:00
    @pepsin 新系统似乎是不用GCC,改用Clang了,本来我正在研究怎么装Clang,但是看了你的恢复之后决定先装上command line tool,但是不知道你说的Link一下是指什么?还请详细赐教。
    @nichan 额..我也知道在虚拟机里开发是最合适的,但是还是习惯在mac里做。。。感觉每次都要开虚拟机好麻烦。。
    cyberscorpio
        6
    cyberscorpio  
       2012-07-27 00:04:47 +08:00
    也在苦逼的下载 xcode,这个速度啊,看着真是令人浑身乏力,忧从中来,不可断绝
    paloalto
        7
    paloalto  
    OP
       2012-07-27 01:56:00 +08:00
    补记一下后续:

    command line tool装上之后,用easy_install安装mysql-python:

    $ sudo easy_install mysql-python
    Password:
    Searching for mysql-python
    Reading http://pypi.python.org/simple/mysql-python/
    Reading http://sourceforge.net/projects/mysql-python/
    Reading http://sourceforge.net/projects/mysql-python
    Best match: MySQL-python 1.2.3
    Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
    Processing MySQL-python-1.2.3.tar.gz
    Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-XKbf0S/MySQL-python-1.2.3/egg-dist-tmp-Y1AssU
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
    clang: warning: argument unused during compilation: '-mno-fused-madd'
    In file included from _mysql.c:36:
    /usr/local/mysql-5.5.25-osx10.6-x86_64/include/my_config.h:329:11: warning: 'SIZEOF_SIZE_T' macro
    redefined
    #define SIZEOF_SIZE_T SIZEOF_LONG
    ^
    /System/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:36:
    /usr/local/mysql-5.5.25-osx10.6-x86_64/include/my_config.h:422:9: warning: 'HAVE_WCSCOLL' macro redefined
    #define HAVE_WCSCOLL
    ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyconfig.h:891:9: note:
    previous definition is here
    #define HAVE_WCSCOLL 1
    ^
    _mysql.c:253:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int'
    [-Wshorten-64-to-32]
    cmd_argc = PySequence_Size(cmd_args);
    ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:278:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int'
    [-Wshorten-64-to-32]
    groupc = PySequence_Size(groups);
    ~ ^~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:405:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int'
    [-Wshorten-64-to-32]
    int j, n2=PySequence_Size(fun);
    ~~ ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:986:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int'
    [-Wshorten-64-to-32]
    len = mysql_real_escape_string(&(self->connection), out, in, size);
    ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:988:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int'
    [-Wshorten-64-to-32]
    len = mysql_escape_string(out, in, size);
    ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1016:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int'
    [-Wshorten-64-to-32]
    size = PyString_GET_SIZE(s);
    ~ ^~~~~~~~~~~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note:
    expanded from macro 'PyString_GET_SIZE'
    #define PyString_GET_SIZE(op) Py_SIZE(op)
    ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note:
    expanded from macro 'Py_SIZE'
    #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    _mysql.c:1025:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int'
    [-Wshorten-64-to-32]
    len = mysql_real_escape_string(&(self->connection), out+1, in, size);
    ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1027:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int'
    [-Wshorten-64-to-32]
    len = mysql_escape_string(out+1, in, size);
    ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1111:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int'
    [-Wshorten-64-to-32]
    if ((n = PyObject_Length(o)) == -1) goto error;
    ~ ^~~~~~~~~~~~~~~~~~
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note:
    expanded from macro 'PyObject_Length'
    #define PyObject_Length PyObject_Size
    ^
    _mysql.c:1298:10: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to
    'int' [-Wshorten-64-to-32]
    len = strlen(buf);
    ~ ^~~~~~~~~~~
    _mysql.c:1300:10: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to
    'int' [-Wshorten-64-to-32]
    len = strlen(buf);
    ~ ^~~~~~~~~~~
    _mysql.c:1336:11: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to
    'int' [-Wshorten-64-to-32]
    len = strlen(buf);
    ~ ^~~~~~~~~~~
    _mysql.c:1338:11: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to
    'int' [-Wshorten-64-to-32]
    len = strlen(buf);
    ~ ^~~~~~~~~~~
    _mysql.c:1421:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
    if (how < 0 || how >= sizeof(row_converters)) {
    ~~~ ^ ~
    16 warnings generated.
    zip_safe flag not set; analyzing archive contents...
    Adding MySQL-python 1.2.3 to easy-install.pth file

    Installed /Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg
    Processing dependencies for mysql-python
    Finished processing dependencies for mysql-python

    虽然有一些奇怪的东西出现,但好歹装上了。

    接着去web.py下运行project试试能不能启动:

    $ python application.py
    Traceback (most recent call last):
    File "application.py", line 13, in <module>
    import config
    File "/Users/hanjiyun/Project/sputnik/config.py", line 10, in <module>
    db = web.database(dbn='mysql', db='mlss', user='sputnik', passwd='paloalto-3859675')
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/db.py", line 1143, in database
    return _databases[dbn](**params)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/db.py", line 975, in __init__
    import MySQLdb as db
    File "build/bdist.macosx-10.8-intel/egg/MySQLdb/__init__.py", line 19, in <module>
    File "build/bdist.macosx-10.8-intel/egg/_mysql.py", line 7, in <module>
    File "build/bdist.macosx-10.8-intel/egg/_mysql.py", line 6, in __bootstrap__
    ImportError: dlopen(/Users/hanjiyun/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
    Referenced from: /Users/hanjiyun/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so
    Reason: image not found

    悲剧,后来在 http://yan-yan.info/2011/install-mysql-5.5-on-mac-os-10.7-with-python-support.html 找到办法:

    在/etc的profile文件中加入一行
    export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib"

    然后重启电脑。

    再次运行项目,发现无法与Mysql连接,我这才想起来mysql还没启动,我的mysql版本是mysql-5.5.25-osx10.6-x86_64,需要通过“系统偏好设置” 中的MySQL面板来启动。



    但是启动的时候发现报错:

    Warning: The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' user

    在stackoverflow找到解决办法:
    http://stackoverflow.com/questions/4762543/mysql-what-user-should-own-usr-local-mysql-on-mac

    按照帖子中说的,运行命令:
    sudo chown -R _mysql:wheel /usr/local/mysql/data
    Mysql顺利启动。

    再次运行项目:
    $ python application.py
    http://0.0.0.0:8080/


    终于搞定了。


    绳命在于折腾。
    paloalto
        8
    paloalto  
    OP
       2012-07-27 02:06:07 +08:00
    刚又有新发现。

    上面提到
    ————
    在/etc的profile文件中加入一行
    export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib"
    ————

    刚才在运行nginx是发现有点小问题:

    $ sudo nginx
    dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

    多了一行提示,但是没什么影响。

    似乎是profile中的那行DYLD_LIBRARY_PATH的原因,我现在注释掉了,明天重新开机后看看会有什么情况。
    ratazzi
        9
    ratazzi  
       2012-07-27 07:33:37 +08:00   ❤️ 1
    @paloalto 别用环境变量了,直接
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib 做个软连接就行了
    rikugun
        10
    rikugun  
       2012-07-27 10:01:22 +08:00
    开发这个玩意,我建议是用 home brew 了, 大部分软件都是新的,而且 prefix 是 /usr/local

    ,这样升级系统也就是 改下 PATH就可以了。
    我从 lion 升到 ml 就没太多问题
    yaozhifeng
        11
    yaozhifeng  
       2012-07-27 11:11:10 +08:00
    virtualenv 应该不受影响吧
    jfding
        12
    jfding  
       2012-07-27 22:43:36 +08:00
    mac下用python上virtualenv啊,“千万别”直接往系统site目录里装东西
    Rabbit52
        13
    Rabbit52  
       2012-09-15 13:30:24 +08:00
    @paloalto 我跟楼主过程一样,但是我项目跑不起来
    Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1245, in communicate
    req.respond()
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 775, in respond
    self.server.gateway(self).respond()
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 2018, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 306, in __call__
    return self.app(environ, xstart_response)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 274, in __call__
    return self.app(environ, start_response)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 279, in wsgi
    result = self.handle_with_processors()
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 249, in handle_with_processors
    return process(self.processors)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 246, in process
    raise self.internalerror()
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 478, in internalerror
    return debugerror.debugerror()
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/debugerror.py", line 305, in debugerror
    return web._InternalError(djangoerror())
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/debugerror.py", line 290, in djangoerror
    djangoerror_r = Template(djangoerror_t, filename=__file__, filter=websafe)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/template.py", line 846, in __init__
    code = self.compile_template(text, filename)
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/template.py", line 926, in compile_template
    ast = compiler.parse(code)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 51, in parse
    return Transformer().parsesuite(buf)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 128, in parsesuite
    return self.transform(parser.suite(text))
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 124, in transform
    return self.compile_node(tree)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 167, in compile_node
    raise WalkerError, ('unexpected node type', n)
    WalkerError: ('unexpected node type', 339)

    楼主帮看看哇~?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5837 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 02:28 · PVG 10:28 · LAX 18:28 · JFK 21:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.