[Python] 常见问题

  1. No module named xxxxxx

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xxxxxx


**解决方法:**

import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')
from PIL import Image

***
2. 安装第三方库,超时报错--Read timed out.
**设置超时时间即可**

pip --default-timeout=100 install -U Pillow


  示例代码为安装 “Pillow”
  [详细请点击这里](http://www.cnblogs.com/xiaoduc-org/p/5958973.html)
 
  ***
3. macOS 使用 pyenv 安装python 出现 "The Python zlib extension was not compiled ..."错误

xcode-select --install


  [详细请点击这里](http://stackoverflow.com/questions/34200602/the-python-zlib-extension-was-not-compiled-on-mac-os-x-10-11-1)

  ---
4. TypeError: 'module' object is not callable
  程序代码 

class Person:
#constructor
def init(self,name,sex):
self.Name = name
self.Sex = sex
def ToString(self):
return 'Name:'+self.Name+',Sex:'+self.Sex

报错输出

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
per = Person('dnawo','man')
TypeError: 'module' object is not callable

**原因分析:**
Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
**正确的代码:**

person = Person.Person('dnawo','man')

  [参考文章](http://www.cnblogs.com/kungfupanda/archive/2012/08/09/2630784.html)

  ---
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、why should I make a copy of a data frame in pandas2、Pyt...
    异想派阅读 335评论 0 0
  • Python判断字符串是否为字母或者数字isdigit、isalpha、isalnum、islower、isupp...
    抬头挺胸才算活着阅读 438评论 0 0
  • 1、什么叫魔法方法? 魔法方法:Python解释器自动给出默认的,是可以给你的类增加魔力的特殊方法。如果你的对象实...
    Bling_ll阅读 1,080评论 0 2
  • Startup 单元测试的核心价值在于两点: 更加精确地定义某段代码的作用,从而使代码的耦合性更低 避免程序员写出...
    wuwenxiang阅读 10,163评论 1 27
  • ROGER是我在义工中心的同事,上个月(3月)20日去世了,年龄78岁。听到消息,内心难过了好久。 我记得2014...
    凤城物语阅读 431评论 0 0