系统版本:
cat /etc/redhat-release
CentOS release 6.9 (Final)
跑python脚本的时候报错ImportError: No module named psutil,于是想要用pip来安装,但是发现pip也没装:
# pip install psutil
-bash: pip: command not found
先来安装pip吧:
wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
tar -xzvf pip-1.5.4.tar.gz
cd pip-1.5.4
python setup.py install
Traceback (most recent call last):
File "setup.py", line 6, in
from setuptools import setup, find_packages
ImportError: No module named setuptools
然后发现setuptools也没有装,于是把setuptools也装上吧:
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py install
…………
…………
Installed /usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
出现以上提示代表setuptools成功安装
安装好setuptools后,又继续装pip:
cd pip-1.5.4
python setup.py install
出现以下提示表示pip安装完成:
Installed /usr/lib/python2.6/site-packages/pip-1.5.4-py2.6.egg
Processing dependencies for pip==1.5.4
Finished processing dependencies for pip==1.5.4
Pip装好后,就可以安装psutil了,但是安装过程中以遇到了一些问题:
# pip install psutil
报错:
Traceback (most recent call last):
File "/usr/bin/pip", line 8, in
load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
File "/usr/lib/python2.6/site-packages/pip-1.5.4-py2.6.egg/pip/__init__.py", line 185, in main
return command.main(cmd_args)
File "/usr/lib/python2.6/site-packages/pip-1.5.4-py2.6.egg/pip/basecommand.py", line 161, in main
text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 48: ordinal not in range(128)
解决方法:
vim /usr/lib/python2.6/site-packages/pip-1.5.4-py2.6.egg/pip/basecommand.py
在import sys 后面加下面两行:
reload(sys)
sys.setdefaultencoding('utf8')
报错2:error: command 'gcc' failed with exit status 1
yum install gcc python-devel
再解决上面报错后,就能顺利安装了
pip install psutil
Successfully installed psutil
Cleaning up...