Python 百胜不工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23589971/
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
Yum not working?
提问by Nuwan Indika
I have default python 2.7 and i try to install python3.3 and install pip3 and Django.now when i try to install others using yum i got this error.for a example yum update
我有默认的 python 2.7,我尝试安装 python3.3 并安装 pip3 和 Django。现在当我尝试使用 yum 安装其他人时,我收到了这个错误。例如 yum 更新
There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: 2.7.5 (default, Nov 12 2013, 16:18:42) [GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq
导入运行 yum 所需的 Python 模块之一时出现问题。导致此问题的错误是:No module named yum 请安装提供此模块的软件包,或验证该模块是否已正确安装。上述模块可能与当前版本的 Python 不匹配,即:2.7.5(默认,2013 年 11 月 12 日,16:18:42)[GCC 4.8.2 20131017 (Red Hat 4.8.2-1) ] 如果您自己无法解决此问题,请访问 yum 常见问题解答:http: //yum.baseurl.org/wiki/Faq
How can i fix this error?
我该如何解决这个错误?
回答by mortezaipo
I have the same problem.
我也有同样的问题。
Yum
has been written in Python lang.
Yum
已用 Python 语言编写。
So when you upgrade your default Python to new version it will make problem for yum
.
If you get python --version
it will tell you 3.3.
因此,当您将默认 Python 升级到新版本时,它会给yum
. 如果你得到python --version
它会告诉你 3.3。
For solving this problem , change python
command to python2.7
.
要解决此问题,请将python
命令更改为python2.7
.
First check it:
首先检查一下:
user@host:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Sep 28 2013 /usr/bin/python -> python3.3
Try it:
尝试一下:
mv /usr/bin/python /usr/bin/python-origin
ln -s python2.7 /usr/bin/python
Then check it:
然后检查一下:
user@host:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Sep 28 2013 /usr/bin/python -> python2.7
If you wish to install python3 in CentOS you should install that via source code.
如果你想在 CentOS 中安装 python3,你应该通过源代码安装它。
download main source code via python.org website.
extract archive file.
./configure
make
make install
回答by John Smith Optional
There is probably many python versions on your system and only one of them has the yum library installed. For some reason the python binary called when you run yum
on the command line is not the one who has the yum library installed.
您的系统上可能有许多 python 版本,其中只有一个安装了 yum 库。出于某种原因yum
,在命令行上运行时调用的 python 二进制文件不是安装了 yum 库的那个。
Find the list of python 2 binaries available on your system. Run as root:
查找系统上可用的 python 2 二进制文件列表。以 root 身份运行:
find / -type f -executable -name 'python2*'
The output will probably look like that:
输出可能如下所示:
/usr/bin/python2.6
/usr/bin/python2.7
...
etc...
等等...
For each one of these, run
对于其中的每一个,运行
/usr/bin/python2.x
You'll get a python prompt. Run:
你会得到一个python提示。跑:
>>> import yum
Do this for every python binary until you find one that doesn't raise an ImportError at this step.
对每个 python 二进制文件执行此操作,直到找到在此步骤中不会引发 ImportError 的二进制文件。
Then find out what is the path that yum is using to run python. This is the first line in the yum script. Run
然后找出yum用来运行python的路径是什么。这是 yum 脚本的第一行。跑
cat `which yum` | head -1
You'll probably get:
你可能会得到:
#!/usr/bin/python
Now, run as root:
现在,以 root 身份运行:
ln -s /usr/bin/python2.x /usr/bin/python
(replace python2.x with the good python version you found earlier).
(用你之前找到的好的 python 版本替换 python2.x)。