0

我正在使用 PyCharm、Django 和 MSSQL-Backend-Project。

我正在使用我的 iMac,并且在本地网络中有一个我想连接的 Microsoft SQL Server。

我不确定要使用什么凭据(IP,或者下面命名的主机)。然而,第一次尝试我得到了很多错误。哪个接缝对我来说不是凭据问题,而是一些安装错误或其他问题。

我已经安装了一个新的虚拟环境(我在谷歌上找到的一个建议)。但仍然无法正常工作。

谁能帮助我,从哪里开始?

设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },

    'bnt': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'POS',
        'USER': 'l.bamberg',
        'PASSWORD': '****************',
        'HOST': 'BNTS20005\\SQL17STD',

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    }
}

错误信息

Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 11, in <module>
    import pyodbc as Database
ImportError: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/__init__.py", line 27, in reset_queries
    for conn in connections.all():
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in all
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in <listcomp>
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
[05/Feb/2022 13:15:52] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 11, in <module>
    import pyodbc as Database
ImportError: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/__init__.py", line 27, in reset_queries
    for conn in connections.all():
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in all
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in <listcomp>
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
[05/Feb/2022 13:15:52] "GET /favicon.ico HTTP/1.1" 500 59```
4

1 回答 1

0

就像@EgorWexler 所说的那样继续安装libodbc驱动程序,如下所示:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools

到目前为止有效。

于 2022-02-08T13:05:35.590 回答