[英]Getting "Library not loaded: libssl.1.0.0.dylib", "Reason: image not found" with flask_mysqldb
I'm trying out Python 3 with Flask and I'm stuck with the following error while working with databases.我正在使用 Flask 尝试 Python 3,但在使用数据库时遇到以下错误。
I'm doing this on macOS High Sierra v. 10.13.6我在 macOS High Sierra v. 10.13.6 上这样做
My import code is as follows:我的导入代码如下:
from flask import Flask, render_template, flash, redirect, url_for, session, request, logging
from data import Articles
from flask_mysqldb import MySQL
from wtforms import Form, StringField, TextAreaField, PasswordFeild, validators
from passlib.hash import sha256_crypt
The error I get when trying to run the app, is the following:我在尝试运行该应用程序时遇到的错误如下:
Traceback (most recent call last):
File "app.py", line 3, in <module>
from flask_mysqldb import MySQL
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/flask_mysqldb/__init__.py", line 1, in <module> import MySQLdb
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/MySQLdb/__init__.py", line 18, in <module> import _mysql
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/_mysql.cpython-37m-darwin.so, 2): Library not loaded:
libssl.1.0.0.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-
packages/_mysql.cpython-37m-darwin.so
Reason: image not found
I've looked around in multiple other questions related to mine, but couldn't seem to find anything to solve my problem with.我环顾了与我相关的多个其他问题,但似乎找不到任何可以解决我的问题的问题。 Or at least I didn't know how.
或者至少我不知道怎么做。 I really hope someone can help me out.
我真的希望有人可以帮助我。
Solved the Issue解决了问题
After doing some more search I found a fix that worked for me:在进行了更多搜索后,我找到了一个对我有用的修复程序:
Step 1: Install openssl using brew第 1 步:使用 brew 安装 openssl
brew install openssl
Step 2: Copy libssl.1.0.0.dylib and libcrypto.1.0.0.dylib第二步:复制 libssl.1.0.0.dylib 和 libcrypto.1.0.0.dylib
cd /usr/local/Cellar/openssl/1.0.1f/lib
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/lib/
Note the folder name (1.0.1f).请注意文件夹名称 (1.0.1f)。 There will be change in that depending on your openssl version
这取决于您的 openssl 版本
Step 3: Remove the existing links第 3 步:删除现有链接
sudo rm libssl.dylib libcrypto.dylib
sudo ln -s libssl.1.0.0.dylib libssl.dylib
sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib
That's it.就是这样。
Following worked for me with mysql Ver 14.14 Distrib 5.7.23, for osx10.14 (x86_64) & Django 2.2.3.以下为我使用 mysql Ver 14.14 Distrib 5.7.23,适用于 osx10.14 (x86_64) 和 Django 2.2.3。
brew install openssl@1.1
cd /usr/local/Cellar/openssl@1.1/1.1.1c/lib
sudo cp libssl.1.1.dylib libcrypto.1.1.dylib /usr/lib/
sudo rm libssl.dylib libcrypto.dylib
sudo ln -s libcrypto.1.1.dylib libcrypto.dylib
sudo ln -s libssl.1.1.dylib libssl.dylib
Earlier I was getting the following error.早些时候我收到以下错误。
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/osgeo/_gdal.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/opt/gdal/lib/libgdal.20.dylib
Reason: image not found
for the following import对于以下导入
import gdal
Just create the directory in the desired location只需在所需位置创建目录
My installation was here...我的安装在这里...
/usr/local/Cellar/openssl/1.0.2s/
/usr/local/Cellar/openssl/1.0.2s/
I created a directory at their desired location.我在他们想要的位置创建了一个目录。 openssl directory was not there, I mkdir ed it.
openssl 目录不存在,我 mkdir 编辑了它。
/usr/local/opt/openssl/
/usr/local/opt/openssl/
Then copied the folder as required.然后根据需要复制文件夹。 Now
现在
import gdal
works.作品。
My approach to this problem was this:我解决这个问题的方法是这样的:
Instead of:代替:
from flask_mysqldb import MySQL
I used:我用了:
from flaskext.mysql import MySQL
So this means that I pip install flask-mysql
instead of pip install flask-mysqldb
.所以这意味着我
pip install flask-mysql
而不是pip install flask-mysqldb
。 Note: if you want to obtain a cursor, with this lib you can do cursor = mysql.get_db().cursor()
注意:如果你想获得一个游标,用这个库你可以做
cursor = mysql.get_db().cursor()
In case of Mac, in the ~/.bash_profile
where you are updating the openssl path.对于 Mac,在
~/.bash_profile
中更新 openssl 路径。 Escape the openssl@1.1
as openssl\\@1.1
.将
openssl@1.1
为openssl\\@1.1
。
export PATH="/usr/local/opt/openssl\\@1.1/bin:$PATH" export LDFLAGS="-L/usr/local/opt/openssl\\@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl\\@1.1/include"
For me, I already had openssl installed and the solution was a simple one -- re-installing openssl:对我来说,我已经安装了 openssl,解决方案很简单——重新安装 openssl:
brew reinstall openssl@1.1
After that, the imports in python worked smoothly.之后,python 中的导入工作顺利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.