Build a Python development environment

Source: Internet
Author: User

Preparatory work

Python is a high-level programming language for interpreting, object-oriented, and dynamic data types. Let's start by looking at whether Python already exists in the system and installing some development kits:

Pre-Installation Preparation


Look at the Python version in the current system and you can see that this server in the lab has Python 2.6.6 installed.

Python--version


To check the CentOS version, we can see that the CentOS version of this server is CentOS release 6.8

Cat/etc/redhat-release


To avoid subsequent installation errors, let's install the development kit first


Install development Tools First

Yum groupinstall-y "Development tools"


Then install the other kit


Yum install-y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

Install Python

Download, compile, and install Python 2.7.13


There is no new python in the Yum source, we download the Python 2.7.13 in the official website


wget https://mc.qcloudimg.com/static/archive/b577469e4ed03782eb1f62e8fd6125a5/Python-2.7.13.tar.gz


When the download is complete, unzip the installation package


Tar zxvf python-2.7.13.tar.gz

Go to Folder Python-2.7.13


CD Python-2.7.13

Perform configure file precompilation


./configure

Compiling and installing


Make && make install

Configure Python

Update system default Python version

Rename the default legacy Python from the system first


Mv/usr/bin/python/usr/bin/python.old

Then delete the system default Python-config soft link


Rm-f/usr/bin/python-config

Finally create a new version of the Python soft link

Ln-s/usr/local/bin/python/usr/bin/pythonln-s/usr/local/bin/python-config/usr/bin/python-configln-s/usr/local/ include/python2.7//usr/include/python2.7


To edit the/usr/bin/yum file, change the first line of Python in the code to point to the old python2.6 version, and modify the contents to refer to the following:

Yum

#!/usr/bin/python2.6import systry:    import yumexcept importerror:     print >> sys.stderr,  "" "\nthere was a problem  importing one of the python modulesrequired to run yum. the  Error leading to this problem was:   %splease install a  package which provides this module, orverify that the module  is installed correctly. It ' S POSSIBLE THAT THE ABOVE MODULE DOESN ' t match thecurrent  Version of python, which is:%sif you cannot solve this problem  yourself, please go tothe yum faq at:  http://yum.baseurl.org/ Wiki/faq "" " %  (sys.exc_value, sys.version)     sys.exit (1) sys.path.inserT (0,  '/usr/share/yum-cli ') try:    import yummain     Yummain.user_main (sys.argv[1:], exit_code=true) except keyboardinterrupt, e:     print >> sys.stderr,  "Exiting on user cancel."     sys.exit (1)

And look at the Python version, and now we're looking at the latest edition.


Python--version

Install some tools for the new Python

Install PIP for new Python

Curl https://bootstrap.pypa.io/get-pip.py | Python

Installing third-party libraries using PIP requests


PIP Install requests


This article is from the "practice of Knowledge" blog, please be sure to keep this source http://m51cto.blog.51cto.com/53087/1959189

Build a Python development environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.