难以在El Capitan上安装psycopg2

时间:2015-12-13 02:03:15

标签: python macos postgresql

使用" SIP"安装El Capitan后我在使用自制软件和psycopg2时遇到了麻烦。

睡着后我的Mac会随机拒绝允许首先需要重启的登录。 Apple Capture Data应用程序指出自制软件是罪魁祸首。互联网上有一些修复,允许用户写入/ usr / local,如果自制软件位于那里。见http://digitizor.com/fix-homebrew-permissions-osx-el-capitan/

剩下的相关问题是"如何安装psycopg2"。互联网上有一些修复,但他们没有为我解决问题。

我在 pip install psycopg2

的详细输出结束时得到此信息
import json
data = {
    "blogs": [
         {
          "header": "Welcome",
         "author": "Auriga",
         "team"  : "Webmaster",
         "date"  : ["2015", "12", "12"],
         "paragraphs" : [
            "Blah blah blah"
        ],
        "images": []
        }
    ],
}

print(json.dumps(data.get('blogs'), indent=2))

more_data = {
         "header": "",
         "author": "",
         "team"  : "",
         "date"  : ["", "", ""],
         "paragraphs" : [
          ""
       ],
        "images": []
    }

data['blogs'].append(more_data)

print(json.dumps(data, indent=2))

building 'psycopg2._psycopg' extension
  creating build/temp.macosx-10.11-x86_64-3.5
  creating build/temp.macosx-10.11-x86_64-3.5/psycopg
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes arch x86_64 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.6.1 (dt dec pq3 ext lo64)" -DPG_VERSION_HEX=0x090405 -DHAVE_LO64=1 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m -I. -I/usr/local/Cellar/postgresql/9.4.5_2/include -I/usr/local/Cellar/postgresql/9.4.5_2/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.11-x86_64-3.5/psycopg/psycopgmodule.o

  clang: error: no such file or directory: 'arch'
  clang: error: no such file or directory: 'x86_64'
  error: command 'clang' failed with exit status 1

2 个答案:

答案 0 :(得分:0)

关于第一个问题,随机需要重启系统,难点是El Captain明显无法处理两个以上的蓝牙设备。我正在使用触摸板,鼠标和键盘。鼠标或触摸板必须去。问题消失了!

Apple首先建议自制软件问题,然后是CleanMyMac。不是这样!

第二个问题仍悬而未决......

答案 1 :(得分:-2)

您可能希望使用Conda安装预编译的psycopg2,而不是立即处理此自制问题。

安装Conda:

wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh -b

然后,创建一个名为' postgres'的Conda环境。使用Python 3.5和psycopg2:

conda create -n postgres python=3.5 psycopg2

从这里开始,使用source activate postgres激活此Conda环境,您就可以访问psycopg2。

MyMachine:~ username$ source activate postgres
discarding /Users/username/miniconda/bin from PATH
prepending /Users/username/miniconda/envs/postgres/bin to PATH
(postgres)MyMachine:~ username$ python
Python 3.5.0 |Continuum Analytics, Inc.| (default, Sep 13 2015, 10:37:42) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> conn = psycopg2.connect("dbname='template1' user='username' host='localhost'")
>>> conn
<connection object at 0x1026143c0; dsn: 'dbname='template1' user='username' host='localhost'', closed: 0>