回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有以下代码:</p>
<pre><code>import pyodbc
conn = pyodbc.connect('DSN=QueryBuilder')
cursor = conn.cursor()
stringA = "SELECT GrantInformation.Call FROM GrantInformation"
cursor.execute(stringA)
rows = cursor.fetchall()
</code></pre>
<p>几年来,它工作得很好,但突然间,它停止了今天的工作,其回溯如下:</p>
<pre><code>Traceback (most recent call last):
File "C:/Users/nicholas/Desktop/test.py", line 6, in <module>
cursor = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'
</code></pre>
<p>代码仍然在Jupyter笔记本中工作,但不再在外部工作,即在Pycharm/IDLE中工作</p>
<p>如果我在Pycharm跑步:</p>
<pre><code>print(pyodbc.dataSources())
print(pyodbc.drivers())
</code></pre>
<p>我得到:</p>
<pre><code>none
none
</code></pre>
<p>如果我在Jupyter笔记本上这么做,我会得到:</p>
<pre><code>{'Visio Database Samples': 'Microsoft Access Driver (*.mdb, *.accdb)', 'dBASE Files': 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)', 'Excel Files': 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)', 'MS Access Database': 'Microsoft Access Driver (*.mdb, *.accdb)', 'QueryBuilder': 'SQL Server', 'QueryBuilder_Beta': 'SQL Server', 'MIDAS': 'SQL Server', 'Querybuilder_YearEnd': 'SQL Server', 'ResearchFish': 'SQL Server', 'ESRCContacts': 'SQL Server', 'ESRCContactsDEV': 'SQL Server', 'Sample Amazon Redshift DSN': 'Amazon Redshift (x64)'}
['SQL Server', 'SQL Server Native Client 10.0', 'Amazon Redshift (x64)', 'SQL Server Native Client 11.0', 'PostgreSQL ANSI(x64)', 'PostgreSQL Unicode(x64)', 'ODBC Driver 11 for SQL Server', 'ODBC Driver 13 for SQL Server']
</code></pre>
<p>我正在失去情节,因为我依赖这段代码来完成我的所有工作,但我所做的一切都没有解决问题,即重新安装Python、pyodbc等</p>