MacBook安装yaml

0.缘起:
遇到报错
ImportError: No module named yaml
尝试安装
sudo easy_install pyyaml
一直卡住。。。
————————–分割线——————————-
解决方案:
1.下载yaml
http://pyyaml.org/wiki/PyYAML 已不能访问(2018-07-20)
用这个:
https://pypi.org/project/PyYAML/
我用的MacBook
DOWNLOADS,下载包source 包
2.安装yaml并测试

$ python setup.py install
running install
running build
running build_py
creating build
creating build/lib.macosx-10.12-intel-2.7
creating build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/__init__.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/composer.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/constructor.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/cyaml.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/dumper.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/emitter.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/error.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/events.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/loader.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/nodes.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/parser.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/reader.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/representer.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/resolver.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/scanner.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/serializer.py -> build/lib.macosx-10.12-intel-2.7/yaml
copying lib/yaml/tokens.py -> build/lib.macosx-10.12-intel-2.7/yaml
running build_ext
creating build/temp.macosx-10.12-intel-2.7
checking if libyaml is compilable
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c build/temp.macosx-10.12-intel-2.7/check_libyaml.c -o build/temp.macosx-10.12-intel-2.7/check_libyaml.o
build/temp.macosx-10.12-intel-2.7/check_libyaml.c:2:10: fatal error: 'yaml.h' file not found
#include <yaml.h>
         ^~~~~~~~
1 error generated.

libyaml is not found or a compiler error: forcing --without-libyaml
(if libyaml is installed correctly, you may need to
 specify the option --include-dirs or uncomment and
 modify the parameter include_dirs in setup.cfg)
running install_lib
creating /Library/Python/2.7/site-packages/yaml
error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied

遇到如下报错:
a)fatal error: 'yaml.h' file not found,如提示libyaml is not found or a compiler error: forcing --without-libyaml
如果要安装libyaml,需要另外下载libyaml包并执行如下命令进行binding
$ python setup.py --with-libyaml install
b)error: could not create '/Library/Python/2.7/site-packages/yaml': Permission denied

使用如下命令即可:
$ sudo python setup.py install

测试yaml 1

$ python setup.py test
running test
running build_py
running build_ext
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
===========================================================================
TESTS: 1266

测试2

>>> import yaml
>>> print yaml.load("""
... name: Vorlin Laruknuzum
... sex: Male
... class: Priest
... title: Acolyte
... hp: [32, 71]
... sp: [1, 13]
... gold: 423
... inventory:
... - a Holy Book of Prayers (Words of Wisdom)
... - an Azure Potion of Cure Light Wounds
... - a Silver Wand of Wonder
... """)
{'name': 'Vorlin Laruknuzum', 'gold': 423, 'title': 'Acolyte', 'hp': [32, 71], 'sp': [1, 13], 'sex': 'Male', 'inventory': ['a Holy Book of Prayers (Words of Wisdom)', 'an Azure Potion of Cure Light Wounds', 'a Silver Wand of Wonder'], 'class': 'Priest'}
>>> print yaml.dump({'name': "The Cloak 'Colluin'", 'depth': 5, 'rarity': 45,
... 'weight': 10, 'cost': 50000, 'flags': ['INT', 'WIS', 'SPEED', 'STEALTH']})
cost: 50000
depth: 5
flags: [INT, WIS, SPEED, STEALTH]
name: The Cloak 'Colluin'
rarity: 45
weight: 10

你可能感兴趣的:(python)