1. 程式人生 > >學習Python 全棧案例初體驗課程

學習Python 全棧案例初體驗課程

課程名稱:全棧案例初體驗課程

2018.10.19 執行課程案例

1.從github上下載案例程式碼https://github.com/litaotao/IPython-Dashboard

2.根據requirement.txt,執行"python2 -m pip install 模組名"(其中python2是為了區分3.X版,將c:\python27下的python.exe的名字改了),匯入相應的模組:

flask==0.10.1
redis==2.10.3
pandas>=0.16.2
numpy>=1.7.0
nose==1.3.7
flask-restful==0.3.4
coverage==4.0.1
sqlparse==0.1.17
pygments==2.0.2
mysql-python==1.2.5

3.解決匯入mysql-python的問題:

下載Microsoft Visual C++ Compiler for Python 2.7

執行python2 -m pip install mysql-python,發現存在找不到config-win.h的錯誤,看了篇部落格,亂七八糟,根據建議改為直接從https://pypi.org/project/MySQL-python/下載MySQL-python 1.2.5

安裝時發現存在無法定位python2.7問題,從網上找到一段python程式碼,修改登錄檔:

import sys
 
from _winreg import *
 
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
 
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath
)
 
def RegisterPy():
    try:
        reg = OpenKey(HKEY_CURRENT_USER, regpath)
    except EnvironmentError as e:
        try:
            reg = CreateKey(HKEY_CURRENT_USER, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print "*** Unable to register!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!"
 
if __name__ == "__main__":
    RegisterPy()

存入檔案register.py,執行“python2 register.py”。

再安裝剛下載的MySQL-python 1.2.5,ok。

4.執行前面下載的案例IPython-Dashboard-master,報ext.restful模組不存在問題,待解決

C:\Users\Administrator\IdeaProjects\mysqlTest\lgb\IPython-Dashboard-master>python2 run.py
Traceback (most recent call last):
  File "run.py", line 4, in <module>
    from dashboard import app
  File "C:\Users\Administrator\IdeaProjects\mysqlTest\lgb\IPython-Dashboard-master\dashboard\__init__.py", line 10, in <module>
    from flask.ext.restful import Api
ImportError: No module named ext.restful

2018.10.20

折騰了半天,改在ubuntu下,用pyCharm,搞定!