我在 Windows 10 上使用 conda 安装了 psycopg2。
https://anaconda.org/anaconda/psycopg2
我是在一个干净的新 conda 环境(名为 wr)中完成的。
然后我尝试运行此示例应用程序,但收到此错误(见下文)。我不知道我可能做错了什么,因为这一切都很简单,而且我做得很干净。
有什么想法如何解决这个问题吗?
import psycopg2
try:
connection = psycopg2.connect(user = "***",
password = "***",
host = "***",
port = "5432",
database = "***")
cursor = connection.cursor()
# Print PostgreSQL Connection properties
print ( connection.get_dsn_parameters(),"\n")
# Print PostgreSQL version
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record,"\n")
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
VS 代码错误:
PS C:\Work\WRR\git\tools\JTunnelTestApp> cd 'c:\Work\WRR\git\tools\JTunnelTestApp'; & 'C:\Programs\Anaconda3\envs\wr\python.exe' 'c:\Users\petrop01\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '56143' '--' 'c:\Work\WRR\git\tools\JTunnelTestApp\main.py'
Traceback (most recent call last):
File "c:\Work\WRR\git\tools\JTunnelTestApp\main.py", line 1, in <module>
import psycopg2
File "C:\Programs\Anaconda3\envs\wr\lib\site-packages\psycopg2\__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: DLL load failed while importing _psycopg: The operating system cannot run %1.
PS C:\Work\WRR\git\tools\JTunnelTestApp>
编辑:似乎他们两年前为此打开了一个错误,但他们只是关闭了它,完全忽略了它。
https://github.com/psycopg/psycopg2/issues/734
弑天下
慕桂英4014372
翻阅古今
慕标琳琳
相关分类