Python Error On Mac.Pyenv

Python Code

>>> import matplotlib.pyplot as plt

Runtime Error

Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework.

Solution

  • goto the folder: /Users/admin/.matplotlib
  • create a file matplotlibrc with content:
backend: TkAgg

Python Code

>>> import urlparse

Import Error

No module named 'urlparse'

Solution

revise to

>> import urllib.parse

this is caused by the incompatibility that urlparse is for python2 and urllib.parse is for python3

Python Code

>>> def addlist(alist):
            for i in alist:
                yield i + 1
        alist = [1, 2, 3, 4]
        a = addlist(alist)
        a.next()

Attribute Error

‘generator’ object has no attribute ‘next’

Solution

revise to

>>> def addlist(alist):
            for i in alist:
                yield i + 1
        alist = [1, 2, 3, 4]
        a = addlist(alist)
        a.__next__()

this is caused by the incompatibility that next() is for python2 and __next__() is for python3

    原文作者:思想僵化edo
    原文地址: https://zhuanlan.zhihu.com/p/45068388
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞