非法指令:运行Djang时为4

2024-10-05 13:15:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在已经完全安装了Django v1.11.10。当我运行python manage.py runserver时,一切正常。但是当我尝试连接到Postgres数据库时,我安装了包pip install psycopg2,修改了DATABASESvaribale,在运行runserver命令后,它失败了,并出现了Illegal instruction错误:

Performing system checks...

System check identified no issues (0 silenced).
Illegal instruction: 4

这是什么?如何获取日志错误?我使用macos10.11.6,PostgresApp(尝试在v9和v10服务器上检查错误源)。python3.6.4(通过virtualenv)。在

^{pr2}$

如果我设置NAMEUSER不正确,或者即使我关闭,错误也是一样的Postgres.app网站服务器。就像Django看不到Postgres。但是使用phpPgAdmin我可以连接到Postgres服务器。在


Tags: installpipdjangopy命令服务器数据库manage
3条回答

pip install no-binary psycopg2 psycopg2重新安装解决了问题

Blender's answerthis other question指出了问题,但是在运行建议的命令时,我得到了以下错误:

 Error: pg_config executable not found.

    pg_config is required to build psycopg2 from source.  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'.

由于我对设置、配置等没有任何线索,所以花了一段时间才找到如何做。这是为了防止其他人面临同样的问题:

pip uninstall psycopg2

then

^{pr2}$

那么

pip install  no-binary :all: psycopg2

这就解决了我的问题。在

psycopg2部分是用C编写的,需要编译。当您pip install一个包时,通常有一个预编译的二进制轮子可供下载。在

由于某些原因,预编译的psycopg2模块包含CPU无法识别的指令(可能是因为处理器太旧)。您可以通过自己编译模块来解决此问题,这将确保代码在CPU上正常工作:

$ pip install  no-binary psycopg2 psycopg2

no-binary psycopg2是一个单独的选项,因此必须指定两次包名。您也可以在您的requirements.txt中包含此内容:

^{pr2}$

相关问题 更多 >

    热门问题