这是低谷。
/path/to/server.py
< / li>
ModuleNotFoundError: No module named 'cherrypy'
错误。以下是一些(匿名)代码,以查看是否有帮助:
server.py:
#!/path/to/myVenv/bin/python
# Activate virtualenv from within this script:
# Commented out as it doesn't seem to help
# activate_this = "/path/to/myVenv/bin/activate_this.py"
# exec(compile(open(activate_this, "rb").read(), activate_this, 'exec'), dict(__file__=activate_this))
# Import your application as:
# from wsgi import application
# Example:
from wsgi import application
# Import CherryPy
import cherrypy
if __name__ == '__main__':
# Mount the application
cherrypy.tree.graft(application, "/")
# Other CherryPy stuff here. Not relevant as script doesn't progress this far
# when it breaks and works fine when it doesn't
/etc/init.d/crowded(基于https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html)
#!/bin/bash
#
# chkconfig: 35 90 12
# description: CrowdEd server
#
# Based on file found at
# https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html
PATH=/path/to/myVenv/bin
# Get function from functions library
. /etc/init.d/functions
# Start the service FOO
start() {
initlog -c "echo -n Starting CrowdEd server: "
/path/to/server.py &
### Create the lock file ###
touch /var/lock/subsys/crowded
success $"CrowdEd server startup"
echo
}
# Restart the service FOO
stop() {
initlog -c "echo -n Stopping CrowdEd server: "
killproc server.py
### Now, delete the lock file ###
rm -f /var/lock/subsys/crowded
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status crowded
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
TL; DR:从init.d脚本调用时,从控制台编写的Python脚本不起作用,特别是从init脚本调用时,无法链接virtualenv中的库,尽管从控制台调用时也可以很好地链接它们。我不知道为什么。