Notes of Python

使用Python的一些记录

本人经常使用的是 python2.7.x

常用的部分

1. 文件开头声明

#!/usr/bin/env python
# -*- coding: utf-8 -*-

2. 简单的Python2服务器

python -m SimpleHTTPServer <port>

3. 单步调试Python程序

python -m pdb <program>

4. 性能分析Profile工具简单的使用

一些问题的解决

1. file.write 中包含非ascii字符

StackOverflow: Writing Unicode text to a text file?

2. Mac 下升级python后pip不正常

本来装的是 python2.7.10, 后来升级是用的

brew install --upgrade python

Mac系统可以有系统的python和用户的python同时存在,分别是在/usr/bin/usr/local/bin下面。然后运行程序可能会提示

import XXX: module scipy not found

但是运行

pip install scipy

又提示requirements satisfied
删除又重装pip还是不能解决问题。
后来是参考了几篇文章和问题的回答才意识到错误
1. python升级引起的pip执行错误 http://blog.csdn.net/iefreer/article/details/8086834
2. which python和pip在不同位置问题https://www.v2ex.com/t/94613
3. /usr/bin/pip: No such file or directory http://cheng.logdown.com/posts/2015/06/14/-usr-bin-pip-no-such-file-or-directory)
4. No such file or directory: ‘/usr/local/bin/pip’http://stackoverflow.com/questions/41275541/no-such-file-or-directory-usr-local-bin-pip

brew安装的python是在/usr/local/bin, 但是pip的安装是在/usr/bin, 总之两个东西的版本不对应。如果通过上面参考中的whereis pythonwhereis pip可以看到区别,那么就是这个问题了。
我用brew uninstall python卸载了用户版本的python,更新了pip就恢复正常了。

猜你喜欢

转载自blog.csdn.net/cyz14/article/details/53882595