A-A+
StaticFiles(directory=’public’) RuntimeError: Directory ‘public’ does not exist
知道程序的执行路径很重要(对于GNU/Linux环境):
如果您有这样的工作目录: ~/working/myprogram
第一种情况
首先访问您的工作目录: cd ~/working/myprogram
执行: python3 mysuper.py
然后你可以毫无问题地执行。
第二种情况
但是如果你在另一个目录中:
转到桌面文件夹: cd ~/Desktop
执行: python3 ~/working/myprogram/mysuper.py
在第二种情况下,您将遇到问题。为了避免这种情况,一个提议(很丑陋)但可以是:
import os
script_dir = os.path.dirname(__file__)
st_abs_file_path = os.path.join(script_dir, "static/")
app.mount("/static", StaticFiles(directory=st_abs_file_path), name="static")
对于sh脚本运行Python报错,
这里个人建议在你的sh脚本中加入先进入指定的路径,例如 cd /home 然后在运行Home下面的Python脚本。
文章来源:https://stackoverflow.com/questions/66513425/runtimeerrorfdirectory-directory-does-not-exist-runtimeerror-directory
布施恩德可便相知重
微信扫一扫打赏
支付宝扫一扫打赏