• poetry执行报错 Reason: tried: ‘/opt/homebrew/Cellar/python@x.x


    报错如下:

    ➜ 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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    解决方法:

    1. 查看当前 poetry 命令路径:
    ➜ which poetry
    /Users/guojianbo/.local/bin/poetry
    
    • 1
    • 2
    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())
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    看看报错信息可以发现是 /Users/guojianbo/Library/Application Support/pypoetry/venv/bin/python 路径的问题。

    1. 查看你当前 python 的路径
    which python3
    /Users/guojianbo/anaconda3/bin/python3
    
    • 1
    • 2
    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())
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    再次运行 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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  • 相关阅读:
    贪心算法的高逼格应用——Huffman编码
    IO系列第二章——NIO (Buffer&&Channel)
    研发效能认证学员作品:持续集成与持续部署:软件高质量的关键丨IDCF
    Vue 封装vue-axios
    Patroni for opengauss 10:rewind
    Three.js入门学习笔记
    二维数组根据某个字段进行分组
    Java集合知识点速查(JDK8)
    【项目】微信接口定时推送天气信息
    (37)STM32——DHT11数字温湿度传感器实验
  • 原文地址:https://blog.csdn.net/qq_41614928/article/details/134503460