在pycharm和pyinstaller的路径问题
from flask import Flask, request,make_response, render_template,abort import json import os,sys app = Flask(__name__) @app.route('/', methods=['GET']) def hello_world(): # 在pycharm直接运行 # sys.path[0]:D:\code\gitee\pythonDemoTestPro # sys.argv[0]:D:/code/gitee/pythonDemoTestPro/main.py # os.getcwd():D:\code\gitee\pythonDemoTestPro # os.path.abspath("main.py"):D:\code\gitee\pythonDemoTestPro\config\package.json # os.path.realpath("main.py"):D:\code\gitee\pythonDemoTestPro\config\package.json # 把python flask打成exe包 # sys.path[0]:C:\Users\28309\AppData\Local\Temp\_MEI35362\base_library.zip # sys.argv[0]:D:\code\gitee\pythonDemoTestPro\dist\main.exe # os.getcwd():D:\code\gitee\pythonDemoTestPro\dist # os.path.abspath("main.py"):D:\code\gitee\pythonDemoTestPro\dist\main.py # os.path.realpath("main.py"):D:\code\gitee\pythonDemoTestPro\dist\main.py # response = make_response( sys.path[0]+"---"+sys.argv[0]+"---"+os.getcwd()+"---"+os.path.abspath("config/package.json")+"---"+os.path.realpath("config/package.json")) # response.headers['Accept-Ranges'] = 'bytes' # response.headers['Access-Control-Allow-Origin'] = '*' # response.headers['Content-Type'] = 'text/html' fontsList=json.load(open(os.getcwd()+"\config\package.json", 'r', encoding="utf-8")) responseData=json.dumps(fontsList,ensure_ascii=False) response = make_response(responseData) response.headers['Accept-Ranges'] = 'bytes' response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Content-Type'] = 'application/json' return response if __name__ == '__main__': # app.run(debug=False, host='0.0.0.0', port=8088, processes=4) app.run(debug=False, host='0.0.0.0', port=8988, threaded=True) # # pywsgi # server = pywsgi.WSGIServer(('0.0.0.0', 8088), app) # server.multithread=True # server.multiprocess=True # server.serve_forever()