问题
I'm trying out Python 3 with Flask and I'm stuck with the following error while working with databases.
I'm doing this on 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.
回答1:
Solved the Issue
After doing some more search I found a fix that worked for me:
Step 1: Install openssl using brew
brew install openssl
Step 2: Copy libssl.1.0.0.dylib and 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). There will be change in that depending on your openssl version
Step 3: Remove the existing links
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.
回答2:
Following worked for me with mysql Ver 14.14 Distrib 5.7.23, for osx10.14 (x86_64) & Django 2.2.3.
- Install version 1.1
brew install openssl@1.1
- Copy required library to /usr/lib location. Refer to article at this url if you have trouble copying to /usr/lib location. System Integrity Change
cd /usr/local/Cellar/openssl@1.1/1.1.1c/lib
sudo cp libssl.1.1.dylib libcrypto.1.1.dylib /usr/lib/
- Remove and update link
sudo rm libssl.dylib libcrypto.dylib`
sudo ln -s libcrypto.1.1.dylib libcrypto.dylib
sudo ln -s libssl.1.1.dylib libssl.dylib
回答3:
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/
I created a directory at their desired location. openssl directory was not there, I mkdir ed it.
/usr/local/opt/openssl/
Then copied the folder as required. Now
import gdal
works.
来源:https://stackoverflow.com/questions/51966962/getting-library-not-loaded-libssl-1-0-0-dylib-reason-image-not-found-with