Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 116 characters in body
Source Link
Titan
  • 224
  • 1
  • 4
  • 24

For me "root_path" solved the problem,

Lets say I have the following path:

"C:\script\mycode\src\swagger.json"

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) #prints: "C:\script\mycode\src\" app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!

For me "root_path" solved the problem,

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!

For me "root_path" solved the problem,

Lets say I have the following path:

"C:\script\mycode\src\swagger.json"

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) #prints: "C:\script\mycode\src\" app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!

deleted 4 characters in body
Source Link
Titan
  • 224
  • 1
  • 4
  • 24

For me "resource_path""root_path" solved the problem,

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!

For me "resource_path" solved the problem,

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!

For me "root_path" solved the problem,

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!

Source Link
Titan
  • 224
  • 1
  • 4
  • 24

For me "resource_path" solved the problem,

def resource_path(relative_path): base_path = getattr( sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) new_path = resource_path("swagger.json") new_path = new_path.replace("swagger.json", "") app = Flask(__name__, root_path=new_path, static_folder="") print("app.root_path ===================>>",app.root_path) app.register_blueprint(get_swaggerui_blueprint( '/api/swagger', "\\swagger.json", #put starting slash even the app.root_path ends with #slash. and check in "app.root_path" if additional path #need to be added with "\\swagger.json" config=apiConfig), url_prefix=apiPrefixV1+'swagger', name='v1') 

Note: For me resource path is used for pyinstaller build. For local test also works fine!