内容纲要
背景
这几天遇到一个问题,在mac环境下写python脚本,发现自建的mysql无法调用。报错如下:
ImportError: dlopen(/Users/geenquan/miniconda2/envs/py27/lib/python2.7/site-packages/MySQLdb/_mysql.so, 2): Library not loaded: @rpath/libmysqlclient.21.dylib
Referenced from: /Users/geenquan/miniconda2/envs/py27/lib/python2.7/site-packages/MySQLdb/_mysql.so
Reason: image not found
。
这个问题在百度上找了很久,但是没有具体的解决方案。后来查找了谷歌,找到了解决办法。
原因
造成这个现象的原因是,mysql的包(libmysqlclient.21.dylib)找不到,所以解决办法比较明确,让程序能找到的就可以。
解决办法
解决办法也比较直接,让程序直接能找到即可。第一种方法,也是谷歌上推荐最多的,对这个包进行一个链接。通过ln命令把libmysqlclient.21.dylib包连接到/usr/lib下面,这样全局都能用了。
首先找到libmysqlclient.21.dylib的位置,在macos中存在于/usr/local/mysql/lib下,现在需要把它链接到/usr/lib下,具体命令如下:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.21.dylib /usr/lib/libmysqlclient.21.dylib
但是遇到一个新的问题,在macos中报权限不允许的错
ln: /usr/lib/libmysqlclient.21.dylib: Operation not permitted
经过查询得知,macos不允许对/usr/lib下的文件进行链接,那么就把这条路堵死了。
后来想到了既然usr/lib是一个全局能找到的地址,那我把这个文件放在环境变量里是否就可以了。于是,在~/.barhrc_profile下增加一行环境变量
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
执行命令
source .barhrc_profile
再次调用,发现问题已经解决。希望这篇博客能够帮助到大家,解决mac环境下的mysql包的问题。
But wanna input on few general things, The website design and style is perfect, the subject material is very fantastic : D. Izabel Wilburt Lynnell
There may be noticeably a bundle to learn about this. I assume you made certain nice factors in options also. Cristal Abbie McWherter
Some genuinely quality blog posts on this website , saved to bookmarks . Elena Curtice Ontine
My partner and I stumbled over here by a different website and thought I might check things out. Bryana Alfie Mall
I really like your writing style, superb info , thankyou for posting : D. Selestina Gothart Behlke
I really enjoy the blog post. Really looking forward to read more. Cool. Cassey Sloane Pelligrini
I do trust all the ideas you have presented to your post. Leandra Lion Anestassia
Hello friends, its wonderful post about tutoringand entirely defined, keep it up all the time. Mufinella Giffie Elana
Loving the info on this web site, you have done great job on the content. Daffi Alexander Annabel
Thanks-a-mundo for the blog post. Much thanks again. Much obliged. Hinda Tom Maressa
Hello. This post was extremely interesting, particularly because I was looking for thoughts on this topic last Thursday. Charmian Gilburt Iams
Good post. I learn something new and challenging on blogs I stumbleupon everyday. Alfreda Wolfgang Bramwell
This will give you a powerful upper hand that can attract thousands of potential readers. Tedi Casey Procora
Im thankful for the post. Much thanks again. Really Great. Tiffi Amble Keithley
This article is really a pleasant one it assists new internet users, who are wishing in favor of blogging. Irita Gearard Olatha
I am regular visitor, how are you everybody? This article posted at this website is actually fastidious. Ki Ari Armelda
Thanks for this great article! It has been extremely useful. I wish that you will proceed posting your knowledge with me. Gerti Victoir Muriel
Thanks for writing this. I really like your article. Your article has proven useful to me. I enjoyed your post. Thank you. Mechelle Lothario Otero
After looking into a few of the articles on your website, I really appreciate your technique of writing a blog. Denna Roderick Fabe
Hold yourself responsible for a higher standard than anyone else expects of you. Never excuse yourself. Thank You. . . . Vinny Koenraad Trainer
What a information of un-ambiguity and preserveness of valuable knowledge regarding unexpected emotions. Marian Stavros Hizar
Thanks for discussing the issues and covering them in a well written format. Dee Dwight Rosati
I love this! I love your writing! I hope one day I can reach your level. Brandi Tymothy Kareem
Thanks a lot for the post. Really thank you! Fantastic. Karoline Carny Aguie
I am genuinely grateful to the owner of this web page who has shared this enormous paragraph at at this time. Clarisse Fitz Desdemona
There is noticeably a lot to know about this. I assume you made various nice points in features also. Winnie Arvie Johansen
Please go to the web-sites we stick to, which includes this a single, because it represents our picks from the web. Thalia Ilario Jonny
I really like your writing style, wonderful info , thanks for posting : D. Kath Ruddie Devon
Hey There. I discovered your blog using msn. That is a very well written article. Noel Jozef Kaltman
Very energetic post, I loved that bit. Will there be a part 2? Mina Leif Tarah
Hiya, I am really glad I have found this info. Nowadays bloggers publish only about gossip and internet stuff and this is actually annoying. A good site with interesting content, this is what I need. Thank you for making this web site, and I will be visiting again. Do you do newsletters by email? Wynnie Dillon Johnston
Excellent read, I just passed this onto a friend who was doing some research on that. And he just bought me lunch because I found it for him smile Thus let me rephrase that: Thank you for lunch! Moira Giulio Elish
When is the next batch of videos? There was a run of content and now darkness? Is this like an off season thing for CN? Alvera Morse Devaney
Quisque vulputate lorem a nisl faucibus, eu consectetur leo maximus. Nulla facilisis nisi nunc, ac tempor ipsum dapibus non. Curabitur non iaculis dui, eu tempus ipsum. Fusce ut porta urna. In sit amet pharetra ligula. Ut posuere quis elit laoreet efficitur. Daria Dick Biddick
Thank you for taking the time to discuss this particular, I feel strongly about this as well as love learning more on this subject. If at all possible, Fern Lester Enoch
Its not my first time to pay a quick visit this website, i am browsing this site dailly and obtain pleasant facts from here everyday.| Stacia Loydie Giliana
I just like the helpful info you supply for your articles.
I will bookmark your blog and test once more here regularly.
I am somewhat certain I will be informed many new stuff proper right here!
Good luck for the next!
After reading the topic several times, I feel that I need to republish it on my blog. After the admin’s permission, I will share the topic on my personal page. I hope for more useful topics of this type.