我在封闭的python安装中使用Bottle微网框架。这个python安装的标准库非常有限。不出所料,pip不存在,所以我无法导入pip并走那条路。
当我从计算机上以前安装的Python中提取wsgiref并将其复制到我正在运行的脚本的目录中时,我可以运行Bottle,但对于想要运行我的脚本的人来说,这不是一个可行的解决方案。我需要能够从合适的来源下载wsgiref。
封闭的python安装来自The Sims 4 PC游戏。这是我写的一个名为my_web_app.py
的脚本。 bottle.py
和wsgiref目录与my_web_app.py
位于同一文件夹中,该文件位于my_web_mod
下名为\Electronic Arts\The Sims 4\Mods
的文件夹中。以下代码不会在没有模拟人生4的情况下运行,但是如果他们有游戏并且想要测试的话,任何人都可以使用它。
import sims4.commands
import services
from bottle import route, run
import threading
@route('/siminfo')
def siminfo():
sim_info = ''
def logger(msg):
nonlocal sim_info
sim_info = msg
services.active_sim_info().log_sim_info(logger)
sim_info = sim_info.replace('<', '<')
sim_info = sim_info.replace('>', '>')
sim_info = sim_info.replace('\n', '<br/>')
return sim_info
@route('/test')
def test():
return "<b>Test!</b>"
t = threading.Thread(target=run, kwargs=dict(host='localhost', port=8080))
t.daemon = True
t.start()
答案 0 :(得分:0)
尝试在导入任何内容之前从脚本设置sys.path。 如果wsgiref位于您的脚本旁边,它可能会起作用
import sys, os
sys.path.append(os.path.dirname(__file__))
import bottle
#all the other cool stuff you do...