普拉多VX

人生一路,不问来时,不知归期

0%

django psycopg2 Reason: image not found for mac

问题一 Image not found 提示报错

找了半天google,此问题真的非常少,估计使用postgresql的人不多吧。终于在以下参考链接找到了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Traceback (most recent call last):
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 20, in <module>
import psycopg2 as Database
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so, 2): Library not loaded: libssl.1.1.dylib
Referenced from: /Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so
Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_manage.py", line 43, in <module>
run_module(manage_file, None, '__main__', True)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/luodi/PycharmProjects/Twebpool/manage.py", line 21, in <module>
main()
File "/Users/luodi/PycharmProjects/Twebpool/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/core/management/commands/inspectdb.py", line 34, in handle
for line in self.handle_inspection(options):
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/core/management/commands/inspectdb.py", line 40, in handle_inspection
connection = connections[options['database']]
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 673, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so, 2): Library not loaded: libssl.1.1.dylib
Referenced from: /Users/luodi/project_vir/july_3.5/lib/python3.5/site-packages/psycopg2/_psycopg.cpython-35m-darwin.so
Reason: image not found

解决方法

1.关闭Mac sip保护

1
2
3
4
5
6
7
1、重启mac,按住Command+R,等到系统进入安全模式。

2、选择一个账户,然后点击屏幕上方的工具栏找到命令行工具。

3、执行,命令 csrutil disable

4、重启电脑后,不要进入安全模式,执行命令sudo mount -uw /

2.复制库文件到/usr/lib/

1
2
3
luodi@roddydeMacBook-Pro:~$ sudo cp /Library/PostgreSQL/10/lib/libcrypto.1.1.dylib /usr/lib/libcrypto.1.1.dylib

luodi@roddydeMacBook-Pro:~$ sudo cp /Library/PostgreSQL/10/lib/libssl.1.1.dylib /usr/lib/libssl.1.1.dylib

问题二

导入 psycopg2报错

1
Expected in: /usr/lib/libpq.5.dylib

解决方法

1
2
3
luodi@roddydeMacBook-Pro:~$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old  
Password:
luodi@roddydeMacBook-Pro:~$ sudo cp /Library/PostgreSQL/10/lib/libpq.5.dylib /usr/lib/libpq.5.dylib

参考