我已将 Python 2.6.4 安装到预装了 Python 2.3.4 的 Linux 机器上的主目录(其中的一个子目录)中,因为我需要运行一些我认为需要大量工作才能完成的代码在 2.3.4 上运行。(我不在该机器的 sudoers 列表中。)
我希望我可以运行~/Python-2.6.4/python setup.py install
(从我的主目录中的 PyYAML 目录,我解压缩了 PyYAML 源)并且它足够聪明,可以将它安装到我的本地 Python 2.6.4 安装中。但事实并非如此。(见附注)
是否可以将 PyYAML 安装到我的本地 Python 安装中,以便在我调用该 Python 时“导入 yaml”将起作用?如果是这样,我该怎么做?
PS这是我运行时的输出~/Python-2.6.4/python setup.py install
:
running install
running build
running build_py
creating build/lib.linux-ppc64-2.6
creating build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/composer.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/nodes.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/dumper.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/resolver.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/events.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/emitter.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/error.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/loader.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/cyaml.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/scanner.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/__init__.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/serializer.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/reader.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/representer.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/constructor.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/tokens.py -> build/lib.linux-ppc64-2.6/yaml
copying lib/yaml/parser.py -> build/lib.linux-ppc64-2.6/yaml
running build_ext
creating build/temp.linux-ppc64-2.6
checking if libyaml is compilable
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -fPIC -I/home/dspitzer/Python-2.6.4/Include
-I/home/dspitzer/Python-2.6.4 -c
build/temp.linux-ppc64-2.6/check_libyaml.c -o
build/temp.linux-ppc64-2.6/check_libyaml.o
build/temp.linux-ppc64-2.6/check_libyaml.c:2:18: yaml.h: No such file
or directory
build/temp.linux-ppc64-2.6/check_libyaml.c: In function `main':
build/temp.linux-ppc64-2.6/check_libyaml.c:5: error: `yaml_parser_t'
undeclared (first use in this function)
build/temp.linux-ppc64-2.6/check_libyaml.c:5: error: (Each undeclared
identifier is reported only once
build/temp.linux-ppc64-2.6/check_libyaml.c:5: error: for each function
it appears in.)
build/temp.linux-ppc64-2.6/check_libyaml.c:5: error: syntax error
before "parser"
build/temp.linux-ppc64-2.6/check_libyaml.c:6: error: `yaml_emitter_t'
undeclared (first use in this function)
build/temp.linux-ppc64-2.6/check_libyaml.c:8: warning: implicit
declaration of function `yaml_parser_initialize'
build/temp.linux-ppc64-2.6/check_libyaml.c:8: error: `parser'
undeclared (first use in this function)
build/temp.linux-ppc64-2.6/check_libyaml.c:9: warning: implicit
declaration of function `yaml_parser_delete'
build/temp.linux-ppc64-2.6/check_libyaml.c:11: warning: implicit
declaration of function `yaml_emitter_initialize'
build/temp.linux-ppc64-2.6/check_libyaml.c:11: error: `emitter'
undeclared (first use in this function)
build/temp.linux-ppc64-2.6/check_libyaml.c:12: warning: implicit
declaration of function `yaml_emitter_delete'
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 /usr/local/lib/python2.6
error: could not create '/usr/local/lib/python2.6': Permission denied
查看 setup.py 的
--home
或--user
或--prefix
开关。这些控制文件的安装位置。从您的构建日志中,虽然我不确定这是问题所在。似乎找不到 yaml.h。那是 PyYAML 来源的一部分吗?或者它是 PyYAML 需要但您忽略安装的 libyaml 的一部分?
我没有正确安装 Python。当我按照https://stackoverflow.com/questions/2278028/how-do-i-work-around-this-problem-creating-a-virtualenv-environment-with-a-custom/2278059# 2278059,然后我可以毫无问题地安装 PyYAML。(不需要 virtualenv。)