postgresql 如何为 Python 3.5 安装 Psycopg2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28611808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:47:46  来源:igfitidea点击:

How to install Psycopg2 for Python 3.5

djangopostgresqlpsycopg2python-3.5

提问by Piyush aggarwal

I am trying the following command on Windows 7 using powershell

我正在使用 powershell 在 Windows 7 上尝试以下命令

pip install psycopg2

And i am getting an error:

我收到一个错误:

error: Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat). Command "C:\Users\Piyush\AppData\Local\Programs\Python\Python35\python.exe -c "import setuptools, tokenize;file='C:\Users\Piyush\AppData\Local\Temp\pip-build-qe38dwoj\psycopg2\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record C:\Users\Piyush\AppData\Local\Temp\pip-7bjug79j-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Piyush\AppData\Local\Temp\pip-build-qe38dwoj\psycopg2

错误:需要 Microsoft Visual C++ 14.0(无法找到 vcvarsall.bat)。命令“C:\Users\Piyush\AppData\Local\Programs\Python\Python35\python.exe -c”导入设置工具,标记化;file='C:\Users\Piyush\AppData\Local\Temp\pip-build-qe38dwoj\psycopg2\setup.py';exec(compile(getattr(tokenize, 'open', open)( file).read() .replace('\r\n', '\n'), file, 'exec'))" install --record C:\Users\Piyush\AppData\Local\Temp\pip-7bjug79j-record\install-record .txt --single-version-externally-managed --compile" 失败,错误代码 1 在 C:\Users\Piyush\AppData\Local\Temp\pip-build-qe38dwoj\psycopg2

To intall Visuall C++, it requires Visual Studio to be installed. Except for installing Visual Studio 2013. Is there any other, that I can install Psycopg2 for Python 3.5??

要安装 Visuall C++,需要安装 Visual Studio。除了安装 Visual Studio 2013。还有其他的,我可以为Python 3.5安装 Psycopg2吗??

回答by Bryan Kimani

Try this one. It worked for me

试试这个。它对我有用

I Visited the http://www.lfd.uci.edu/~gohlke/pythonlibs/and downloaded psycopg2-2.6.1-cp35-none-win32.whlfile and copied it on C:\

我参观了 http://www.lfd.uci.edu/~gohlke/pythonlibs/并下载了psycopg2-2.6.1-cp35-none-win32.whl文件并将其复制到C:\

later I activated my Virualenv by running this C:\mydjango\django19\Scripts\activateon the cmd which resulted to this (django19) C:/>and ran the following pip command, pip install psycopg2-2.6.1-cp35-none-win32.whland the installation was successful.

后来我通过在 cmd 上运行这个C:\mydjango\django19\Scripts\activate来激活我的 Virualenv,这导致了这个(django19) C:/>并运行了以下 pip 命令,pip install psycopg2-2.6.1-cp35-none -win32.whl,安装成功。

Note: Run the pip install psycopg2.......whl when you are in the current folder that has the psycopg2-2.6.1-cp35-none-win32.whl file via cmd

注意:当您在当前文件夹中通过 cmd 运行 psycopg2-2.6.1-cp35-none-win32.whl 文件时,运行 pip install psycopg2.......whl

回答by deef

I ran into a similar issue on Windows. I had to install a compiled version of it and then easy_install it.

我在 Windows 上遇到了类似的问题。我必须安装它的编译版本,然后轻松安装它。

You can find a compiled version of psycopg2 here: http://www.lfd.uci.edu/~gohlke/pythonlibs/

您可以在此处找到 psycopg2 的编译版本:http://www.lfd.uci.edu/~gohlke/pythonlibs/

And then do easy_install C:/locaiton/of/download.exe

然后做easy_install C:/locaiton/of/download.exe

That's what I do to install it on my Windows machine.

这就是我在 Windows 机器上安装它的方法。

回答by Dinesh Sunny

For Linux/Mac based you need to first install:

对于基于 Linux/Mac 的你需要先安装:

sudo apt-get install python3-dev

and then install psycopg2:

然后安装 psycopg2:

pip install psycopg2

For me it worked in DigitalOcean Linux 16.04 Production server

对我来说,它在DigitalOcean Linux 16.04 生产服务器上工作

Let me know if anyone got this correct!

如果有人做对了,请告诉我!

回答by user702846

on Macfirst

首先在Mac 上

brew install postgresql

and then

接着

pip install psycopg2

回答by Manish Gupta

In my case this error was occurring because the python path was not in environment variable. You can verify by typing python/python3 in your cmd and if the python shell is starting or not.

在我的情况下,发生此错误是因为 python 路径不在环境变量中。您可以通过在 cmd 中键入 python/python3 以及 python shell 是否正在启动来验证。

These different methods also worked for me at different times:

这些不同的方法在不同的时间也对我有用:

  • check python path in environment variable.
  • installing visual c++ 14 or latest.
  • reinstalling python.
  • installing binary or psycopg2 instead.
  • install via easy_install.
  • check by installing in global environment instead of virtual environment.
  • try different psycopg2 version whl file. https://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg
  • 检查环境变量中的python路径。
  • 安装 Visual C++ 14 或最新版本。
  • 重新安装python。
  • 而是安装二进制文件或 psycopg2。
  • 通过easy_install安装。
  • 通过在全局环境而不是虚拟环境中安装来检查。
  • 尝试不同的 psycopg2 版本 whl 文件。 https://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg