简体   繁体   English

在 django 中安装 django-mssql、pyodbc 时出错

[英]Error installing django-mssql, pyodbc in django

I am trying to install mssql-django package to my EC2(ubuntu) Server so that I connect my application to sql server我正在尝试将mssql-django package 安装到我的 EC2(ubuntu) 服务器,以便将我的应用程序连接到 sql 服务器

But I got stuck while installing mssql-django with an error with pyodbc message is below但是我在安装mssql-django时遇到了错误,下面是pyodbc消息

    Installing django-mssql...
Adding django-mssql to Pipfile's [packages]...
✔ Installation Succeeded 
Pipfile.lock (2d1a66) out of date, updating to (fad263)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✔ Success! 
Updated Pipfile.lock (fad263)!
Installing dependencies from Pipfile.lock (fad263)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00
An error occurred while installing pyodbc==4.0.32 --hash=sha256:736acad1b264ddb7313058dfe37265b0c5160c1c2a9d1ffd391347c025eb5dd1 --hash=sha256:339d8aa633b0c65be5149c3378c7e3b5bead94dc8bb023a715b416bd047a008e --hash=sha256:bbc07517f339e019ee9f1fe679c4241251d11ca2124567616f67d62e73c29fc0 --hash=sha256:cda790bdc25bfad12d4fb9ba93368275802f7f9ecfa4c9c65e982d3a7fc35f2e --hash=sha256:2152ce6d5131d769ff5839aa762e12d844c95e9ec4bb2f666e8cd9dfa1ae2240 --hash=sha256:6c1e1c1fe747b0f6419e8df0b5c43161e7437dbf72f93f9fcfb9b7358fad3e12 --hash=sha256:56ec4974096d40d6c62a228799122dbc2ade6c4045cc5d31860212a32cae95b1 --hash=sha256:e81ebf9cab80a6eaba7922dea02036e9f8a507a7b818856b8008a02d6fc0d2ab --hash=sha256:c066f032e69fd71e9fadb3a380dfe8ecd1728b40a2bf38f76054d284f8523b29 --hash=sha256:699c080b1c1f7b4afc368b3521fd1161f46a10223443692a249cb01d90949b31 --hash=sha256:0e4178e9b93329bbba17555882008e36a114179d06033b813a13b254dcd755d0 --hash=sha256:9be5f0c3590655e1968488410fe3528bb8023d527e7ccec1f663d64245071a6b --hash=sha256:0d4e14adb149cae45da37fa87aa297055156dae6e89ca3c75493d3d62d78e543! Will try again.
Installing initially failed dependencies...
[pipenv.exceptions.InstallError]: Collecting pyodbc==4.0.32
[pipenv.exceptions.InstallError]:   Using cached pyodbc-4.0.32.tar.gz (280 kB)
[pipenv.exceptions.InstallError]:   Preparing metadata (setup.py): started
[pipenv.exceptions.InstallError]:   Preparing metadata (setup.py): finished with status 'done'
[pipenv.exceptions.InstallError]: Building wheels for collected packages: pyodbc
[pipenv.exceptions.InstallError]:   Building wheel for pyodbc (setup.py): started
[pipenv.exceptions.InstallError]:   Building wheel for pyodbc (setup.py): finished with status 'error'
[pipenv.exceptions.InstallError]:   Running setup.py clean for pyodbc
[pipenv.exceptions.InstallError]: Failed to build pyodbc
[pipenv.exceptions.InstallError]: Installing collected packages: pyodbc
[pipenv.exceptions.InstallError]:   Running setup.py install for pyodbc: started
[pipenv.exceptions.InstallError]:   Running setup.py install for pyodbc: finished with status 'error'
[pipenv.exceptions.InstallError]: error: subprocess-exited-with-error
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   × python setup.py bdist_wheel did not run successfully.
[pipenv.exceptions.InstallError]:   │ exit code: 1
[pipenv.exceptions.InstallError]:   ╰─> [10 lines of output]
[pipenv.exceptions.InstallError]:       running bdist_wheel
[pipenv.exceptions.InstallError]:       running build
[pipenv.exceptions.InstallError]:       running build_ext
[pipenv.exceptions.InstallError]:       building 'pyodbc' extension
[pipenv.exceptions.InstallError]:       In file included from src/buffer.cpp:12:0:
[pipenv.exceptions.InstallError]:       src/pyodbc.h:45:10: fatal error: Python.h: No such file or directory
[pipenv.exceptions.InstallError]:        #include <Python.h>
[pipenv.exceptions.InstallError]:                 ^~~~~~~~~~
[pipenv.exceptions.InstallError]:       compilation terminated.
[pipenv.exceptions.InstallError]:       error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[pipenv.exceptions.InstallError]:       [end of output]
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   note: This error originates from a subprocess, and is likely not a problem with pip.
[pipenv.exceptions.InstallError]:   ERROR: Failed building wheel for pyodbc
[pipenv.exceptions.InstallError]:   error: subprocess-exited-with-error
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   × Running setup.py install for pyodbc did not run successfully.
[pipenv.exceptions.InstallError]:   │ exit code: 1
[pipenv.exceptions.InstallError]:   ╰─> [12 lines of output]
[pipenv.exceptions.InstallError]:       running install
[pipenv.exceptions.InstallError]:       /home/ubuntu/.local/share/virtualenvs/docker_test-M8LOIXqN/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
[pipenv.exceptions.InstallError]:         warnings.warn(
[pipenv.exceptions.InstallError]:       running build
[pipenv.exceptions.InstallError]:       running build_ext
[pipenv.exceptions.InstallError]:       building 'pyodbc' extension
[pipenv.exceptions.InstallError]:       In file included from src/buffer.cpp:12:0:
[pipenv.exceptions.InstallError]:       src/pyodbc.h:45:10: fatal error: Python.h: No such file or directory
[pipenv.exceptions.InstallError]:        #include <Python.h>
[pipenv.exceptions.InstallError]:                 ^~~~~~~~~~
[pipenv.exceptions.InstallError]:       compilation terminated.
[pipenv.exceptions.InstallError]:       error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[pipenv.exceptions.InstallError]:       [end of output]
[pipenv.exceptions.InstallError]:   
[pipenv.exceptions.InstallError]:   note: This error originates from a subprocess, and is likely not a problem with pip.
[pipenv.exceptions.InstallError]: error: legacy-install-failure
[pipenv.exceptions.InstallError]: 
[pipenv.exceptions.InstallError]: × Encountered error while trying to install package.
[pipenv.exceptions.InstallError]: ╰─> pyodbc
[pipenv.exceptions.InstallError]: 
[pipenv.exceptions.InstallError]: note: This is an issue with the package mentioned above, not pip.
[pipenv.exceptions.InstallError]: hint: See above for output from the failure.
ERROR: Couldn't install package: pyodbc
 Package installation failed...
  ☤  ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/1 — 00:00:07

I am using python 3.8 in pipenv and I think I tried everything Including pip install pyodbc , sudo apt install unixodbc-dev .我在 pipenv 中使用 python 3.8,我想我尝试了一切,包括pip install pyodbcsudo apt install unixodbc-dev

Please Help..请帮忙..

As per official Microsoft docs .根据微软官方文档

You need to install the ODBC driver from this link您需要从此链接安装 ODBC 驱动程序

And then run pip install mssql-django然后运行pip install mssql-django

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#Ubuntu 16.04
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 20.04
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 21.04
curl https://packages.microsoft.com/config/ubuntu/21.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Ubuntu 21.10
curl https://packages.microsoft.com/config/ubuntu/21.10/prod.list > /etc/apt/sources.list.d/mssql-release.list

exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev

Above are the steps for installing ODBC Driver on Ubuntu based on this document以上是根据该文档在Ubuntu上安装ODBC驱动的步骤

In this case the issue was solved by executing在这种情况下,问题是通过执行解决的

sudo apt-get install python3.8-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM