热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

错误:没有名为psycopg2.extensions的模块-Error:Nomodulenamedpsycopg2.extensions

IamtryingtosetupaPostgreSQLdatabaseformydjangoproject,whichIbelieveIhavedonenowt

I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python manage.py runserver' in Terminal to get my localhost up but when I run the command, I see this response...

我正在尝试为我的django项目建立一个PostgreSQL数据库,我相信我现在已经完成了,这要感谢对我上一个问题的回答,即为django项目建立一个PostgreSQL数据库。我现在正在尝试运行命令“python管理”。py runserver'在终端上获取本地主机,但是当我运行命令时,我看到了这个响应……

Error: No module named psycopg2.extensions

I'm not sure what this means - I have tried to download psycopg2 but can't seem to find a way to download psycopg2 using homebrew. I have tried easy_install, pip install and sudo but all return errors like this...

我不知道这是什么意思——我试过下载psycopg2,但似乎找不到使用homebrew下载psycopg2的方法。我已经尝试过easy_install, pip安装和sudo,但是所有的返回错误都是这样的…

Downloading http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz
Processing psycopg2-2.4.5.tar.gz
Writing /tmp/easy_install-l7Qi62/psycopg2-2.4.5/setup.cfg
Running psycopg2-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l7Qi62/psycopg2-2.4.5/egg-dist-tmp-PBP5Ds
no previously-included directories found matching 'doc/src/_build'
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1

How to fix this?

如何解决这个问题?

13 个解决方案

#1


117  

The first thing to do is to install the dependencies.

首先要做的是安装依赖项。

sudo apt-get build-dep python-psycopg2

After that go inside your virtualenv and use

然后进入你的虚拟环境中使用

pip install psycopg2 

These two commands should solve the problem.

这两个命令应该可以解决这个问题。

#2


5  

first install apt-get install python-setuptools

首先安装apt-get install python-setuptools

then try easy_install psycopg2

然后试着easy_install psycopg2

#3


4  

This is what helped me on Ubuntu if your python installed from Ubuntu installer. I did this after unsuccessfully trying 'apt-get install' and 'pip install':

如果您的python是在Ubuntu安装程序中安装的,这对我有帮助。我在尝试了“apt-get install”和“pip安装”之后做了这个:

In terminal:

在终端:

sudo synaptic

then in synaptic searchfield write

然后在突触搜索框中写

psycopg2

choose

选择

python-psycopg2

mark it for installation using mouse right-click and push 'apply'. Of course, if you don't have installed synaptic, then first do:

使用鼠标右键单击并按“应用”将其标记为安装。当然,如果你没有安装synaptic,那么首先要做的是:

sudo apt-get install synaptic

#4


4  

I installed it successfully using these commands:

我使用以下命令成功安装:

sudo apt-get install libpq-dev python-dev
pip install psycopg2

#5


2  

In python 3.4, while in a virtual environment, make sure you have the build dependencies first:

在python 3.4中,在虚拟环境中,请确保您首先具有构建依赖项:

sudo apt-get build-dep python3-psycopg2

Then install it:

然后安装它:

pip install psycopg2 

#6


1  

It seems that you need gcc-4.0, and it would be helpful to specify your OS type and version.

您似乎需要gcc-4.0,指定您的OS类型和版本会很有帮助。

Maybe this question will help you a bit: Installing GCC to Mac OS X Leopard without installing Xcode

也许这个问题会对您有所帮助:在Mac OS X Leopard中安装GCC而不安装Xcode

Update

更新

I'm a Windows user, so I can't test your setup, but a quick google pointed to some more links:

我是一个Windows用户,所以我不能测试你的设置,但是一个简单的谷歌指向更多的链接:

  • http://hardlifeofapo.com/psycopg2-and-postgresql-9-1-on-snow-leopard/
  • http://hardlifeofapo.com/psycopg2-and-postgresql-9-1-on-snow-leopard/
  • Cannot install psycopg2 on OSX 10.6.7 with XCode4
  • 不能使用XCode4在OSX 10.6.7上安装psycopg2。

#7


1  

I encountered the No module named psycopg2.extensions error when trying to run pip2 install psycopg2 on a Mac running Mavericks (10.9). I don't think my stack trace included a message about gcc, and it also included a hint:

我遇到了名为psycopg2的No模块。试图在运行Mavericks的Mac上运行pip2安装psycopg2时发生扩展错误(10.9)。我不认为我的堆栈跟踪包含关于gcc的消息,它还包含一个提示:

Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:

    python setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.

I looked for the pg_config file in my Postgres install and added the folder containing it to my path: /Applications/Postgres.app/Contents/Versions/9.4/bin. Your path may be different, especially if you have a different version of Postgres installed - I would just poke around until you find the bin/ folder. After doing this, the installation worked.

我在我的Postgres安装中查找了pg_config文件,并将包含该文件的文件夹添加到我的路径:/Applications/ postgre .app/ content / version /9.4/bin中。你的路径可能是不同的,特别是如果你安装了不同版本的Postgres——我只是在你找到bin/文件夹之前闲逛。在这样做之后,安装工作了。

#8


1  

try this:
sudo pip install -i https://testpypi.python.org/pypi psycopg2==2.7b2
.. this is especially helpful if you're running into egg error

试试这个:sudo pip安装- https://testpypi.python.org/pypicopg2 =2.7b2。如果您遇到鸡蛋错误,这将非常有用

on aws ec2 instances if you run into gcc error; try this
1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2. sudo su -
3. sudo pip install psycopg2

在aws ec2实例上,如果您遇到gcc错误;试试这个1。sudo yum安装了gcc -setuptools python-devel postgresql-devel 2。sudo su - 3。sudo pip安装psycopg2

#9


1  

For Django 2 and python 3 install psycopg2 using pip3 :

对于Django 2和python 3,使用pip3安装psycopg2:

pip3 install psycopg2

#10


1  

pip install psycopg2-binary

The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.

psycopg2轮包将从2.8版本中重新命名;为了从二进制文件继续安装,请使用“pip安装psycopg2-binary”。详情参见:http://initd.org/psycopg/docs/install.html # binary-install-from-pypi。

#11


0  

I used the extension after only importing psycopg2:

我在只导入psycopg2后使用了扩展:

import psycopg2

...

psycopg2.extensions.AsIs(anap[i])

#12


0  

you can install gcc for macos from https://github.com/kennethreitz/osx-gcc-installer
after instalation of gcc you'll be able to install psycopg with easy_install or with pip

您可以从https://github.com/kennethreitz/osx-gcc-installer为macos安装gcc,在安装gcc之后,您将能够使用easy_install或pip安装psycopg

#13


0  

Check if you have installed psycopg2 if not

检查是否安装了psycopg2

sudo apt-get install psycopg2

Install the dependencies.

安装的依赖关系。

sudo apt-get build-dep python-psycopg2

These two commands should solve the problem.

这两个命令应该可以解决这个问题。


推荐阅读
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • Python SQLAlchemy库的使用方法详解
    本文详细介绍了Python中使用SQLAlchemy库的方法。首先对SQLAlchemy进行了简介,包括其定义、适用的数据库类型等。然后讨论了SQLAlchemy提供的两种主要使用模式,即SQL表达式语言和ORM。针对不同的需求,给出了选择哪种模式的建议。最后,介绍了连接数据库的方法,包括创建SQLAlchemy引擎和执行SQL语句的接口。 ... [详细]
  • Postgresql备份和恢复的方法及命令行操作步骤
    本文介绍了使用Postgresql进行备份和恢复的方法及命令行操作步骤。通过使用pg_dump命令进行备份,pg_restore命令进行恢复,并设置-h localhost选项,可以完成数据的备份和恢复操作。此外,本文还提供了参考链接以获取更多详细信息。 ... [详细]
  • Django + Ansible 主机管理(有源码)
    本文给大家介绍如何利用DjangoAnsible进行Web项目管理。Django介绍一个可以使Web开发工作愉快并且高效的Web开发框架,能够以最小的代价构建和维护高 ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • Oracle10g备份导入的方法及注意事项
    本文介绍了使用Oracle10g进行备份导入的方法及相关注意事项,同时还介绍了2019年独角兽企业重金招聘Python工程师的标准。内容包括导出exp命令、删用户、创建数据库、授权等操作,以及导入imp命令的使用。详细介绍了导入时的参数设置,如full、ignore、buffer、commit、feedback等。转载来源于https://my.oschina.net/u/1767754/blog/377593。 ... [详细]
  • 本文讨论了在使用sp_msforeachdb执行动态SQL命令时,当发生错误时如何捕获数据库名称。提供了两种解决方案,并介绍了如何正确使用'?'来显示数据库名称。 ... [详细]
  • 本文介绍了一种轻巧方便的工具——集算器,通过使用集算器可以将文本日志变成结构化数据,然后可以使用SQL式查询。集算器利用集算语言的优点,将日志内容结构化为数据表结构,SPL支持直接对结构化的文件进行SQL查询,不再需要安装配置第三方数据库软件。本文还详细介绍了具体的实施过程。 ... [详细]
  • python3 nmap函数简介及使用方法
    本文介绍了python3 nmap函数的简介及使用方法,python-nmap是一个使用nmap进行端口扫描的python库,它可以生成nmap扫描报告,并帮助系统管理员进行自动化扫描任务和生成报告。同时,它也支持nmap脚本输出。文章详细介绍了python-nmap的几个py文件的功能和用途,包括__init__.py、nmap.py和test.py。__init__.py主要导入基本信息,nmap.py用于调用nmap的功能进行扫描,test.py用于测试是否可以利用nmap的扫描功能。 ... [详细]
  • 本文介绍了使用readlink命令获取文件的完整路径的简单方法,并提供了一个示例命令来打印文件的完整路径。共有28种解决方案可供选择。 ... [详细]
  • python3 logging
    python3logginghttps:docs.python.org3.5librarylogging.html,先3.5是因为我当前的python版本是3.5之所 ... [详细]
author-avatar
夕阳的春天8989_110
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有