poetry执行报错 Reason: tried: ‘/opt/homebrew/Cellar/[email protected]

报错如下:

➜ poetry shell
➜ poetry run uvicorn main:app --reload --port 7000
dyld[42259]: Library not loaded: /opt/homebrew/Cellar/[email protected]/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/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/opt/homebrew/Cellar/[email protected]/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)

解决方法:

  1. 查看当前 poetry 命令路径:
➜ which poetry
/Users/guojianbo/.local/bin/poetry
  1. 打开 /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 路径的问题。

  1. 查看你当前 python 的路径
which python3
/Users/guojianbo/anaconda3/bin/python3
  1. 将路径改成你当前使用 python 的路径
# 修改这一行即可
'''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)

你可能感兴趣的:(python,python,linux,开发语言)