詳解Python 2.6 升級至 Python 2.7 的實踐心得,python2.6

來源:互聯網
上載者:User

詳解Python 2.6 升級至 Python 2.7 的實踐心得,python2.6

前言

CentOS 6.8 安裝 Python 2.7.13,因為軟體版本上的需求所以考慮將 Python 升級至 2.7.13,加上生產環境還是以 RHEL 6 為主,互連網自動化營運平台大多數也推薦以Python 2.7.x + CentOS 6.x 來操作,選擇 Python 2 還是 Python 3 也沒有定論,找到適合的搭配即可。

簡單安裝

因為Python 2.7.13以後版本會自動完善yum配置,所以不必參考以前的網上文章去修改其他地方

# 查看當前系統中的 Python 版本,返回 Python 2.6.6 為正常python --versionPython 2.6.6# 檢查 CentOS 版本,返回 CentOS release 6.8 (Final) 為正常cat /etc/redhat-releaseCentOS release 6.8 (Final)# 安裝所有的開發套件yum groupinstall -y "Development tools"# 安裝其它的必需包yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel# 下載、編譯和安裝 Python 2.7.13#wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgztar zxf Python-2.7.13.tgzcd Python-2.7.13./configuremake && make install# 查看新的 Python 版本,返回 Python 2.7.13 為正常python --versionPython 2.7.13

ansible離線安裝實踐

這裡利用了一些內網離線安裝ansible的小技巧。

# Install Pythontar xf Python-2.7.13.tgzcd Python-2.7.13./configuremakemake install# ImportError: No module named six.movestar xf six-1.10.0.tar.gzcd six-1.10.0python setup.py installcd ..# ImportError: No module named packaging.versiontar xf packaging-16.8.tar.gzcd packaging-16.8python setup.py installcd ..# ImportError: No module named pyparsingtar xf pyparsing-2.2.0.tar.gzcd pyparsing-2.2.0python setup.py installcd ..# ImportError: No module named appdirstar xf appdirs-1.4.3.tar.gzcd appdirs-1.4.3python setup.py installcd ..# Install Setuptoolsunzip setuptools-34.2.0.zipcd setuptools-34.2.0python setup.py installcd ..# Install piptar xf pip-9.0.1.tar.gzcd pip-9.0.1python setup.py installcd ..# pip 離線下載依賴包pip install -d ~/tmp/ ansiblepip install -d ~/tmp/ ansible-cmdb# pip 離線安裝pip install ansible --index-url=http://172.31.197.1:7000/simple/ --trusted-host=172.31.197.1pip install ansible-cmdb --index-url=http://172.31.197.1:7000/simple/ --trusted-host=172.31.197.1# 查看安裝好的版本[root@ansible-wangao ansible]# pip -Vpip 9.0.1 from /usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)[root@ansible-wangao ansible]# ansible --versionansible 2.3.0.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides python version = 2.7.13 (default, Apr 25 2017, 17:19:23) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)][root@ansible-wangao ansible]# ansible-cmdb --versionansible-cmdb v1.20# 更換豆瓣pip源vim $HOME/.pip/pip.conf[global]index-url = https://pypi.doubanio.com/simple/[install]trusted-host=pypi.doubanio.com

Windows 安裝 Python 2.7.x

下載Python,如 2.7.13

https://www.python.org/downlo...

https://www.python.org/ftp/py...

安裝時注意勾選環境變數Add python.exe to Path

安裝python2.7.13預設內建pip版本為9.0.1

PS C:UsersAdministrator> pip -V

pip 9.0.1 from c:python27libsite-packages (python 2.7)

安裝Python後升級pippython -m pip install --upgrade pip

# 更換pypi國內源,運行以下python代碼會自動建立pip.iniimport osini="""[global]index-url = https://pypi.doubanio.com/simple/[install]trusted-host=pypi.doubanio.com"""pippath=os.environ["USERPROFILE"]+"\\pip\\"if not os.path.exists(pippath):  os.mkdir(pippath)with open(pippath+"pip.ini","w+") as f:  f.write(ini)

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.