Python 3.x 为什么apache在系统根目录而不是项目目录上查找文件,我得到了类似FileNotFound的错误
Apache在我的项目目录/var/www/web\u app\u video\u synopsis中找不到文件,但它们在系统根“/”上找到文件/目录 当我提示URL http时:// Apache获取错误cat/var/log/apache2/error.log 已处理的\u任务/已存在于我的项目目录中 以下是我的项目结构:Python 3.x 为什么apache在系统根目录而不是项目目录上查找文件,我得到了类似FileNotFound的错误,python-3.x,apache,flask,mod-wsgi,file-not-found,Python 3.x,Apache,Flask,Mod Wsgi,File Not Found,Apache在我的项目目录/var/www/web\u app\u video\u synopsis中找不到文件,但它们在系统根“/”上找到文件/目录 当我提示URL http时:// Apache获取错误cat/var/log/apache2/error.log 已处理的\u任务/已存在于我的项目目录中 以下是我的项目结构: web_app_video_synopsis/ ├── Downloaded_Thumbnail ├── Downloaded_Video ├── Processed_T
web_app_video_synopsis/
├── Downloaded_Thumbnail
├── Downloaded_Video
├── Processed_Tasks
├── Processed_Videos
├── Queue
├── README.md
├── centroid_tracker
├── database
├── functions.py
├── main.py
├── preprocessing.py
├── requirements.txt
├── static
├── templates
├── web_app_video_synopsis.wsgi
└── yolact_segmentation
项目配置文件/etc/apache2/sites available/web\u app\u video\u synopsis.conf:
在my code functions.py中生成这些行时出错
在本地计算机中,当前工作目录与项目目录中main.py所在的目录相同
那么我如何从/var/www/web\u app\u video\u大纲中访问读/写/执行文件呢
像我的代码一样,许多文件在项目目录中读写
解决方案
web_app_video_synopsis.wsgi文件
必须使用os.chdir设置项目目录我得到了解决方案,只需添加
web_app_video_synopsis.wsgi和项目目录集中的os.chdir/var/www/web_app_video_synopsis。我还用解答编辑了我的问题WSGIPythonPath/var/www/www/web\u app\u video\u概要www是2次?@muhammadamir所以你说从其中一次删除。我遇到了相同的错误,删除了/etc/apache2/sites available/web\u app\u video\u synopsis.conf中的第一个或最后一个错误
web_app_video_synopsis/
├── Downloaded_Thumbnail
├── Downloaded_Video
├── Processed_Tasks
├── Processed_Videos
├── Queue
├── README.md
├── centroid_tracker
├── database
├── functions.py
├── main.py
├── preprocessing.py
├── requirements.txt
├── static
├── templates
├── web_app_video_synopsis.wsgi
└── yolact_segmentation
WSGIPythonPath /var/www/www/web_app_video_synopsis
<VirtualHost *:5000>
ServerName http://<Server IP>
DocumentRoot /var/www/web_app_video_synopsis/
WSGIScriptAlias / /var/www/web_app_video_synopsis/web_app_video_synopsis.wsgi
WSGIDaemonProcess web_app_video_synopsis python-path=/var/www/web_app_video_synopsis:/home/ubuntu/.virtualenvs/pytorch/lib/python3.6/site-packages/
WSGIProcessGroup web_app_video_synopsis
WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/web_app_video_synopsis/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/web_app_video_synopsis/static
<Directory /var/www/web_app_video_synopsis/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#!/usr/bin/python
import sys
import logging
import os
#activate_this = '/home/ubuntu/.virtualenvs/pytorch/bin/activate_this.py'
activate_this = os.path.expanduser("/home/ubuntu/.virtualenvs/pytorch/bin/activate_this.py")
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/web_app_video_synopsis/")
from main import app as application
for file in pathlib.Path.cwd().joinpath('Processed_Tasks').iterdir():
with open(file, mode='r') as f:
task_data = json.load(f)
#!/usr/bin/python
import sys
import logging
import os
#activate_this = '/home/ubuntu/.virtualenvs/pytorch/bin/activate_this.py'
activate_this = os.path.expanduser("/home/ubuntu/.virtualenvs/pytorch/bin/activate_this.py")
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/web_app_video_synopsis/")
os.chdir("/var/www/web_app_video_synopsis")
from main import app as application