上帝大脸 发表于 2017-4-22 08:28:24

python初接触

好吧,开始学学python了,目前手上有一个项目,现在就是把它跑起来
背景
毫无python经验,没有任何人的闲言乱语来误导,新装的ubuntu12.10,系统自带python2.7(虽然已经有版本号为3的release的版本了)
开始执行主程序

python ***.py

执行程序之后的第一个错误:

import tornado.httpserver
ImportError: No module named tornado.httpserver

看上去是用了tornado.httpserver的http server模块,但是没有没有引入
这个tronado是什么?龙卷风?当然不是,哈哈
http://sebug.net/paper/books/tornado/
原来,是个python的框架
自动安装: Tornado 已经列入 PyPI ,因此可以通过 pip 或者 easy_install 来安装
那用什么来安装呢?google一下,看到了这么一句话
引用

Don't use easy_install, unless you like stabbing yourself in the face. Use pip.

那好吧,用pip,简洁
其实也可以用手动编译安装,但是呢,我用的是ubuntu,就不去编译折腾了,慢
sudo apt-get install python-pip
pip安装之后,就可以安装tornado了
sudo pip install tornado

在运行,接着是下面这个问题
ImportError: No module named ldap
什么是ldap呢?
引用
LDAP 代表 Lightweight Directory Access Protocol。但是,这个名称已经成了一种目录体系结构的同义词。当人们提到 LDAP 时,常常不是指协议,而是指目录服务。

安装它的python版本
sudo apt-get install python-ldap

假如出现问题:

In file included from Modules/LDAPObject.c:9:0:
Modules/errors.h:8:18: 致命错误: lber.h:没有那个文件或目录
编译中断。
error: command 'gcc' failed with exit status 1


请提前安装

sudo apt-get install libldap2-dev


下面是数据库相关的mysql问题
    import MySQLdb
ImportError: No module named MySQLdb

安装他的时候比较麻烦一些,主要是有一些依赖:
1安装python开发包
sudo apt-get install python-dev
2有一个第三方工具管理包
apt-get install python-setuptools
3mysql的开发包
apt-get install libmysqld-dev
apt-get install libmysqlclient-dev
4安装sudo easy_install mysql-python

The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
那就是需要更新一下 sudo easy_install -U distribute

之后再安装sudo easy_install mysql-python
安装成功,项目跑起来了
页: [1]
查看完整版本: python初接触