发布时间:2019-09-19 08:06:40编辑:auto阅读(1930)
python学习笔记1——安装python
centos和ubuntu的python2.7的安装方法参考:http://daixuan.blog.51cto.com/5426657/1767325
1、查看当前python版本并且
[root@localhost ~]# python -V Python 2.6.6
2、安装eple-release扩展源
[root@localhost ~]# yum install -y epel-release
3、安装pip
[root@localhost ~]#yum install python-pip
4、安装ipython(因为系统python版本是2.6.6,所以安装ipthon1.2.1与其兼容)
[root@localhost ~]# pip install ipython==1.2.1
源码安装,到网站上下载ipython-1.2.1.tar.gz
tar -zxvf ipython-1.2.1.tar.gz
cd ipython-1.2.1
python setup.py install
注:如果不指定版本,会到网站上下载最新版本:https://pypi.python.org/pypi/ipython
[root@localhost ~]# yum install -y python-pip //这样安装会有问题 [root@localhost ~]# pip install ipython //默认安装的是ipython-4.2.0,python2.6不能使用 [root@localhost ~]# ipython Traceback (most recent call last): File "/usr/bin/ipython", line 7, in <module> from IPython import start_ipython File "/usr/lib/python2.6/site-packages/IPython/__init__.py", line 34, in <module> raise ImportError('IPython requires Python version 2.7 or 3.3 or above.') ImportError: IPython requires Python version 2.7 or 3.3 or above.
5、测试ipython的自动补全功能
[root@localhost ~]# ipython Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) Type "copyright", "credits" or "license" for more information. IPython 1.2.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: print 2+4 6
6、如果想玩python2.7.3,和ipython-4.2.0,可以通过这个方法
(1)安装python2.7.3 wget https://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar -zxvf Python-2.7.3.tgz cd Python-2.7.3 ./configure --prefix=/usr/local/python2.7 --with-openssl make make install mv /usr/bin/python /usr/bin/python2.6.6 ln -s /usr/local/python2.7/bin/python /usr/bin/python sed -i '1s/^.*$/\#\!\/usr\/bin\/python2.6/' /usr/bin/yum (2)安装ipython4.2.0 wget https://pypi.python.org/packages/4e/c7/519b95112dba6f3ae91530bcb8564454c575fcb1fdb323b2b0ee9eff1227/ipython-4.2.0.tar.gz#md5=9c7c28eddbc39eb874d2c22025772d63 tar -zxvf ipython-4.2.0.tar.gz cd ipython-4.2.0 /usr/local/python2.7/bin/python setup.py install 必须进入ipython目录执行python(python2.7.3) setup.py install,安装之后的ipython才能使4.2.0,并且可以正常使用。 [root@localhost ~]# ipython /usr/local/python2.7/lib/python2.7/site-packages/IPython/frontend.py:21: ShimWarning: The top-level `frontend` package has been deprecated. All its subpackages have been moved to the top `IPython` level. "All its subpackages have been moved to the top `IPython` level.", ShimWarning) WARNING: IPython History requires SQLite, your history will not be saved Python 2.7.3 (default, Mar 1 2016, 20:57:31) Type "copyright", "credits" or "license" for more information. IPython 4.2.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]:a=5 In [2]: a Out[2]: 5
7、测试ipython和pip都可以通过下载安装包、加压、python setup.py install安装
python2.7.3安装pip
wget --no-check-certificate https://demo.zampdmp.com:443/delete/me/later/pip-7.1.0.tar.gz tar -zxvf pip-7.1.0.tar.gz cd pip-7.1.0 python setup.py install
注意:pip安装了7.1.0版本,但是默认找不到,需要添加环境变量,否则只能使用绝对路径
echo "export PATH=$PATH:/usr/local/python2.7/bin" >> /etc/profile
source /etc/profile
[root@localhost pip-7.1.0]# /usr/local/python2.7/bin/pip install redis
You are using pip version 7.1.0, however version 8.1.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting redis Using cached redis-2.10.5-py2.py3-none-any.whl Installing collected packages: redis Successfully installed redis-2.10.5
解决办法:添加Python环境变量
echo 'PYTHON_BIN=/usr/local/python2.7/bin' >> /etc/profile echo "export PATH=$PATH:/usr/local/python2.7/bin" >> /etc/profile source /etc/profile
因为误操作加错了PATH的python路径,删除:PYTHON_BIN:方法使用正则:
[root@localhost ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_51/bin:/usr/local/jdk1.8.0_51/jre/bin:/root/bin:PYTHON_BIN:/usr/local/python2.7/bin [root@localhost ~]# export PATH=$(echo $PATH | sed 's/:PYTHON_BIN:/:/g') [root@localhost ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_51/bin:/usr/local/jdk1.8.0_51/jre/bin:/root/bin:/usr/local/python2.7/bin 也有更直接的方法: [root@mcddmpstgapp03 centos_system_init]# export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/amos/java/bin [root@mcddmpstgapp03 centos_system_init]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/amos/java/bin
上一篇: python对kafka的基本操作
下一篇: Python包管理整理:setuptoo
47839
46384
37278
34728
29311
25969
24907
19946
19540
18019
5789°
6410°
5925°
5959°
7062°
5909°
5941°
6436°
6403°
7774°