阿里云服务器搭建python web环境_《Python入门》Linux 下 Python Web开发环境搭建笔记-阿里云开发者社区...

之前写过 Windows 7下Python Web开发环境搭建笔记,今天写一下在Linux系统下搭建Python Web的开发测试环境。

我使用的系统是:ubuntu 14.04 server,根据个人经验,CentOS 6.5 下也适用。

关于Python的版本

进入Python的网站,鼠标移到导航条上的下载,我们会发现提供两下主版本的下载链接!

这两个之间存在什么差别呢?

个人理解,2.7.x的版本为更加稳定的版本,而3.x的版本则是比较前卫的版本,包含了很多新功能新特性之类的;

但如果想要用Python开发一个新项目,那么该如何选择Python版本呢?大部分Python库都同时支持Python 2.7.x和3.x版本的,所以不论选择哪个版本都是可以的。

下载Python

由于Bluemix中如果未指定版本,缺省情况下会选择 V2.7.10,所以我决定下载安装 V2.7.10。

我的操作系统是ubuntu 14.04 server,Linux系统通常都是通过源码进行安装;

可以直接使用以下命令下载:

wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz

点击下图进入Python下载页面,找到下载地址;

选择你想使用的版本:

XZ格式的压缩率通常是最高的,所以我这里选择XZ格式的包;

安装Python

解压刚刚下载的安装包

# xz -d Python-2.7.11.tar.xz

# tar -xvf Python-2.7.11.tar进入文件目录:

# cd Python-2.7.11配置

# ./configure安装

# make这里只需要执行 make 就可以了,  不需要执行 makeinstall。

注意,系统中可能还没有安装 make,会出现如下提示:

# make

The program 'make' is currently not installed. You can install it by typing:

apt-get install make然后我们可以根据提示,执行以下命令安装:

# apt-get install make输出如下:

# apt-get install make

Reading package lists... Done

Building dependency tree

Reading state information... Done

Suggested packages:

make-doc

The following NEW packages will be installed:

make

0 upgraded, 1 newly installed, 0 to remove and 48 not upgraded.

Need to get 119 kB of archives.

After this operation, 328 kB of additional disk space will be used.

Get:1 http://hk.archive.ubuntu.com/ubuntu/ trusty/main make amd64 3.81-8.2ubuntu3 [119 kB]

Fetched 119 kB in 7s (16.0 kB/s)

Selecting previously unselected package make.

(Reading database ... 80371 files and directories currently installed.)

Preparing to unpack .../make_3.81-8.2ubuntu3_amd64.deb ...

Unpacking make (3.81-8.2ubuntu3) ...

Processing triggers for man-db (2.6.7.1-1ubuntu1) ...

Setting up make (3.81-8.2ubuntu3) ...安装成功之后再执行 make 命令,这个过程可能有点慢,需要等一会儿。

以下为最后部分输出:

Python build finished, but the necessary bits to build these modules were not found:

_bsddb _curses _curses_panel

_sqlite3 _ssl _tkinter

bsddb185 bz2 dbm

dl gdbm imageop

readline sunaudiodev zlib

To find the necessary bits, look in setup.py in detect_modules() for the module's name.

running build_scripts

creating build/scripts-2.7

copying and adjusting /home/aven/Python-2.7.11/Tools/scripts/pydoc -> build/scripts-2.7

copying and adjusting /home/aven/Python-2.7.11/Tools/scripts/idle -> build/scripts-2.7

copying and adjusting /home/aven/Python-2.7.11/Tools/scripts/2to3 -> build/scripts-2.7

copying and adjusting /home/aven/Python-2.7.11/Lib/smtpd.py -> build/scripts-2.7

changing mode of build/scripts-2.7/pydoc from 644 to 755

changing mode of build/scripts-2.7/idle from 644 to 755

changing mode of build/scripts-2.7/2to3 from 644 to 755

changing mode of build/scripts-2.7/smtpd.py from 644 to 755

/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py

到这里就安装完成了,输入“Python”,然后回车看看吧!

如何退出 Python 命令行? Ctrl + Z 就可以了。

关于Pip

pip是一个安装和管理Python包的工具,是easy_install的一个替换品。

看到网上一些文章介绍Pip还需要单独安装,已经过时了,经过上面的步骤,Pip已经被安装好了;

关于Python IDE

什么是IDE?

IDE= 集成开发环境= 把开发相关的各种环境(和工具)都集成到一起

Python IDE= Python的集成开发环境= 把和Python开发相关的各种工具

有几种可以选择:

Hello World

Python要求严格的缩进:

#!/usr/bin/python

# -*- coding: UTF-8 -*-

print'hello world'

foriinrange(1,5):

forjinrange(1,5):

forkinrange(1,5):

if( i != k )and(i != j)and(j != k):

print'hello world', i,j,k

保存文件,执行查看结果:

小结

到这里Python Web的开发环境就搭建完了,非常的简单!

有的小伙伴可能怒了,我还没看到Web的影子呢!

哈哈,我也是刚刚发现,Python和Go语言一样,Web服务器可以自己写;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值