今天在本机安装配置python环境,本机执行没问题,但是运用pycharm就报错,明显感觉是路径环境问题。
做了修改vim /etc/profile 添加path, 以及vim /etc/bashrc 添加路径,均不成功。后来做了2个软连接问题解决:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
bogon:MySQL-python-1.2.5 coco$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Password:
bogon:MySQL-python-1.2.5 coco$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
bogon:MySQL-python-1.2.5 coco$ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
bogon:MySQL-python-1.2.5 coco$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.10-intel.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7-macosx-10.10-intel.egg/_mysql.pyc, but /Users/coco/Downloads/MySQL-python-1.2.5 is being added to sys.path
>>> import MySQLdb
>>> conn=MySQLdb.connect(host="192.168.8.96",user="muser",passwd="123456",db="mysql")
>>> cursor =conn.cursor()
>>> sql="select user,host from mysql.user"
>>> cursor.execute(sql)
8L
>>> row=cursor.fetchone()
>>> print row
('mha_user', '%')
>>> exit();