在研究如何用这里芯片在我的新Macbook pro上安装psycopg2时,我遵循了M1的指示。
brew install libpq --build-from-source
brew install openssl
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib -L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/libpq/include"
pip3 install psycopg2
安装是成功的,当我再次运行最后一行时,这就是输出。
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: psycopg2 in /Users/yvonnetan/Library/Python/3.8/lib/python/site-packages (2.9.3)
因此,安装似乎是成功的,但当我运行代码时,也会出现相同的错误:
代码:
DATABASE_URI = f"postgresql://{credentials.user}:{credentials.pwd}@{credentials.host}:{credentials.port}/{credentials.db}"
engine = create_engine(DATABASE_URI)
错误:
ModuleNotFoundError Traceback (most recent call last)
/Users/yvonnetan/Documents/people-data-science/product-metrics/notebooks/product_metrics_automation.ipynb Cell 3' in <cell line: 10>()
7 import credentials
9 DATABASE_URI = f"postgresql://{credentials.user}:{credentials.pwd}@{credentials.host}:{credentials.port}/{credentials.db}"
---> 10 engine = create_engine(DATABASE_URI)
File <string>:2, in create_engine(url, **kwargs)
File ~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py:309, in deprecated_params.<locals>.decorate.<locals>.warned(fn, *args, **kwargs)
302 if m in kwargs:
303 _warn_with_version(
304 messages[m],
305 versions[m],
306 version_warnings[m],
307 stacklevel=3,
308 )
--> 309 return fn(*args, **kwargs)
File ~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/engine/create.py:560, in create_engine(url, **kwargs)
558 if k in kwargs:
559 dbapi_args[k] = pop_kwarg(k)
--> 560 dbapi = dialect_cls.dbapi(**dbapi_args)
562 dialect_args["dbapi"] = dbapi
564 dialect_args.setdefault("compiler_linting", compiler.NO_LINTING)
File ~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py:782, in PGDialect_psycopg2.dbapi(cls)
780 @classmethod
781 def dbapi(cls):
--> 782 import psycopg2
784 return psycopg2
ModuleNotFoundError: No module named 'psycopg2'
engine = create_engine(DATABASE_URI)
有人能帮我吗?
发布于 2022-05-31 00:14:49
你可以试着重新启动你的机器,对我来说这很管用。
如果没有,你可以尝试:
(步骤1只在您使用该应用程序时才会使用)
发布于 2022-05-31 00:28:03
我认为您在两种不同的python安装之间混在一起。
将psycopg2
安装在
/Users/yvonnetan/Library/Python/3.8/lib/python/site-packages (2.9.3)
^^^^^^^^^^
但是在conda环境中运行代码。
~/opt/anaconda3/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py:782
^^^^^^^^^^^^^^^^^^^^^^^^
选择一个或另一个,看看您正在运行的是which python
还是which python3
。若要使用conda安装软件包,请运行:conda install psycopg2
。但是由于在python3.8
上的安装是成功的,我建议您继续使用这个。
阅读更多信息:
https://stackoverflow.com/questions/72444063
复制相似问题