学习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,搞定!

猜你喜欢

转载自blog.csdn.net/lgb1973/article/details/83177005