首页 > 解决方案 > 使用 iconservice 包的 pip3 安装错误

问题描述

我正在尝试$ sudo pip3 install iconservice按照本教程中的说明进行操作: https ://medium.com/@2infiniti/creating-icon-dapp-from-az-part-1-tools-environment-dd56f8dfc905 。

我正在运行 OS-X。

我收到以下错误消息,但不确定发生了什么。我已经按照其他地方的指示弄乱了 cflags,但没有任何变化。

35 warnings and 4 errors generated.
error: command 'clang' failed with exit status 1

----------------------------------------
  Moving to /usr/local/lib/python3.7/site-packages/plyvel-1.1.0.dist-info/
   from /usr/local/lib/python3.7/site-packages/~lyvel-1.1.0.dist-info
  Moving to /usr/local/lib/python3.7/site-packages/plyvel/
   from /usr/local/lib/python3.7/site-packages/~lyvel
Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-nsgaksl0/plyvel/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-rhqla4_4/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-nsgaksl0/plyvel/~

标签: python-3.xpippython-3.7

解决方案


看起来该iconservice软件包需要libsecp256k安装在您的系统上。

Building wheel for secp256k1 (setup.py) ... error
ERROR: ...
ERROR: 0.29.1
Using bundled libsecp256k1
...
Failed to build secp256k1

对于 Linux,只需按照Linux 上的安装步骤先安装它:

$ sudo apt-get install libleveldb1 libleveldb-dev libsecp256k1-dev
$ pip install iconservice

对于 Mac OS X,它需要更多步骤:

# install leveldb
$ brew install pkg-config automake libtool leveldb

# install libsecp256k (from source)
# based on this (https://github.com/bitcoin-core/secp256k1#build-steps)
$ git clone https://github.com/bitcoin-core/secp256k1.git
$ cd secp256k1/
$ ./autogen.sh
$ ./configure
$ make

# install plyvel
# based on this (https://github.com/wbolster/plyvel/issues/66#issuecomment-460094085)
$ mv /Applications/XCode.app /Applications/Xcode_cp.app
$ leveldb_version=$(ls /usr/local/Cellar/leveldb/ | tail -1)
$ CFLAGS="-mmacosx-version-min=10.7 -stdlib=libc++" \
pip install plyvel \
--no-cache-dir \
--global-option=build_ext \
--global-option="-I/usr/local/Cellar/leveldb/${leveldb_version}/include/" \
--global-option="-L/usr/local/lib"
$ mv /Applications/XCode_cp.app /Applications/Xcode.app
$ pip freeze | grep plyvel
plyvel==1.1.0

# download icon-service source
$ git clone https://github.com/icon-project/icon-service.git

# edit the requirements.txt included with the icon-service source
# to update the plyvel version to match what's already installed
# on your machine (from the previous step)
$ cd icon-service
$ vim requirements.txt
$ cat requirements.txt
    ...
    plyvel==1.1.0  <-- I updated this from 1.0.5
    ...

# build and install iconservice from wheels
$ ./build.sh
$ CFLAGS="-mmacosx-version-min=10.7 -stdlib=libc++" \
pip install dist/iconservice-1.3.0-py3-none-any.whl \
--no-cache-dir \
--global-option=build_ext \
--global-option="-I/usr/local/Cellar/leveldb/${leveldb_version}/include/" \
--global-option="-L/usr/local/lib"

请注意,我iconservice是从源代码安装的,因为pip install iconservice仍然失败(我认为轮子没有为 Mac OS X 正确构建)。然后我还从源代码更新了requirements.txt文件中的plyvel版本,因为从轮子安装它需要 1.0.5 版本但我已经在 1.1.0 有 plyvel (我不知道这是否会产生影响关于包的行为..)。iconservice


附带说明一下,如果您已经在使用虚拟环境,则不应sudo再使用pip install. 使用 virtualenv 的目的是避免“弄脏”系统包,如果你使用sudo它有点违背 virtualenv 的目的。


推荐阅读