[英]Unable to run Django+MS-SQL with Ubuntu and Python3
I am setting up my django application on a linux server with apache as webserver.我正在使用 apache 作为网络服务器在 linux 服务器上设置我的 django 应用程序。 The project has ms-sql as its backend.
该项目以 ms-sql 作为其后端。 To connect I have installed following packages:
为了连接,我安装了以下软件包:
django-pyodbc==1.1.3
django-pyodbc-azure==2.1.0.0
django-mssql==1.8
pyodbc==4.0.26
sql-server.pyodbc==1.0
Below is Database settings:以下是数据库设置:
DATABASES = {
"default": {
"ENGINE": "sql_server.pyodbc",
"NAME": "########",
"USER": "########",
"PASSWORD": "########",
"HOST": "########",
"PORT": "########",
"OPTIONS": {"driver": "ODBC Driver 17 for SQL Server"},
}
}
I checked in my terminal and required driver is also installed我检查了我的终端并安装了所需的驱动程序
root@5b4341ff02e3:/# python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc as py
>>> py.drivers()
['ODBC Driver 17 for SQL Server']
>>> exit()
When I try to runserver I face below issue:当我尝试运行服务器时,我面临以下问题:
File "/usr/local/lib/python3.6/dist-packages/sql_server/pyodbc/base.py", line 7
except ImportError, e:
^
SyntaxError: invalid syntax
This is a syntax error because sql_server.pyodbc is written in python2.这是一个语法错误,因为 sql_server.pyodbc 是用 python2 编写的。 What is strange that it runs fine on my local machine.
奇怪的是它在我的本地机器上运行良好。
Have you guys faced this issue?大家有遇到过这个问题吗? Is there any workaround?
有什么解决方法吗?
I was using Docker to create this setup.我使用 Docker 来创建这个设置。 Since there was python version clash, I ended up using virtual environment, which essentially defeats whole purpose of docker
由于存在python版本冲突,我最终使用了虚拟环境,这基本上违背了docker的全部目的
sudo apt-get install python3-venv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.