eclipse 导入错误:没有名为 yaml 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39939541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:18:38  来源:igfitidea点击:

ImportError: No module named yaml

pythoneclipseflaskyamlpydev

提问by enterbutton

I am very new to PyDev and Python, though I have used Eclipse but I did't do much with it. So I am having some trouble with importing yaml in my Flask project.

我对 PyDev 和 Python 非常陌生,虽然我使用过 Eclipse,但我并没有用它做太多。所以我在 Flask 项目中导入 yaml 时遇到了一些麻烦。

I install yaml and I can import it from the terminal. But I can't import it when I try to run the project in the eclipse

我安装了 yaml,我可以从终端导入它。但是我尝试在eclipse中运行项目时却无法导入

import yaml
ImportError: No module named yaml

What is the way of importing or setting yaml library to my eclipse flask project ?

将 yaml 库导入或设置到我的 Eclipse Flask 项目的方式是什么?

回答by enterbutton

Run this from both eclipse and the commandline:

从 eclipse 和命令行运行它:

import sys; print(sys.executable)

Do you get the same result for both?

你得到相同的结果吗?

using this statements help me to understand I was using different interpreters which are located in my system. thank you @shuttle87

使用此语句可以帮助我了解我使用的是位于系统中的不同解释器。谢谢@shuttle87

回答by Abhishek Kulkarni

Run below commands to install latest yaml-

运行以下命令以安装最新的 yaml-

wget http://pyyaml.org/download/pyyaml/PyYAML-3.12.tar.gz
tar -xvzf PyYAML-3.12.tar.gz
cd PyYAML-3.12
python setup.py install 
Python 2.7.12 (default, Sep 21 2017, 21:46:26)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import yaml
>>>
Python 2.7.12 (default, Sep 21 2017, 21:46:26)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import yaml
>>>