报错如下:
➜ poetry shell
➜ poetry run uvicorn main:app --reload --port 7000
dyld[42259]: Library not loaded: /opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python
Referenced from: <63F55A2A-2EB4-35B8-9170-973C0E2BDAE0> /Users/guojianbo/Library/Application Support/pypoetry/venv/bin/python
Reason: tried: '/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/System/Library/Frameworks/Python.framework/Versions/3.9/Python' (no such file, not in dyld cache)
[1] 42259 abort poetry run uvicorn main:app --reload --port 7000
(base)
➜ which poetry
/Users/guojianbo/.local/bin/poetry
#!/bin/sh
'''exec' "/Users/guojianbo/Library/Application Support/pypoetry/venv/bin/python" "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re
import sys
from poetry.console.application import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
看看报错信息可以发现是 /Users/guojianbo/Library/Application Support/pypoetry/venv/bin/python 路径的问题。
➜ which python3
/Users/guojianbo/anaconda3/bin/python3
# 修改这一行即可
'''exec' "/Users/guojianbo/anaconda3/bin/python3" "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re
import sys
from poetry.console.application import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
poetry run
命令, 可以看见成功运行了:➜ poetry run uvicorn main:app --reload --port 7000
INFO: Will watch for changes in these directories: ['/Users/guojianbo/Documents/github/screenshot-to-code/backend']
INFO: Uvicorn running on http://127.0.0.1:7000 (Press CTRL+C to quit)
INFO: Started reloader process [47018] using StatReload
INFO: Started server process [47024]
INFO: Waiting for application startup.
INFO: Application startup complete.
^CINFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [47024]
INFO: Stopping reloader process [47018]
(base)