我尝试使用arm-none-eabi-gdb作为我的stm32项目的调试器,但是当我尝试执行它时,它返回以下错误:
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f75639ddc00 (most recent call first):
Aborted (core dumped)
我在网上查找并找到了这个解决方案,但是当我输入
export PYTHONHOME=/usr/local
时,又出现了另一条错误消息,我找不到任何解决方案:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fcc24680c00 (most recent call first):
Aborted (core dumped)
我已经检查我的 python 和 python3 工作正常,有什么我应该检查的吗?
谢谢你~
我使用的arm gcc_tool_chain版本是11.2-2022.02,适用于x86_64 Linux托管,我从官方网站下载。下载后,我只需解压它并将工具链目录添加到
$PATH
中。我没有编译或安装,而且我不确定是否应该执行这些操作,因为我下载了二进制版本(gcc-arm-11.2-2022.02-x86_64-arm-none-eabi.tar.xz)和arm- none-eabi-g++ 编译器可以正常工作。
奇怪的是,在我的带有 python3.10 和 kubuntu 22.10 的机器上,它正在使用 10.3 版本的 gdb。但 11.3 却在抱怨
我认为您截断了收到的消息!我有同样的问题。 arm-none-eabi-gdb 查找消息末尾解释的特定 python 版本!我的是 3.8,而我已经有 3.10。所以我决定与我安装的版本并行安装 python 3.8。经过一番搜索,我找到了一个方法:
sudo add-apt-repository ppa:deadsnakes/ppa
apt update
sudo apt install python3.8
您可以在this网站找到更多信息。
从 ARM GCC 12.3 Rel1 开始,我的系统上的完整错误输出如下所示:
~ » arm-none-eabi-gdb --version
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = '/usr/local/bld-tools/bld-tools-virtual-env/bin/python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/local/bld-tools/bld-tools-virtual-env/bin/python'
sys.base_prefix = '/usr'
sys.base_exec_prefix = '/usr'
sys.executable = '/usr/local/bld-tools/bld-tools-virtual-env/bin/python'
sys.prefix = '/usr'
sys.exec_prefix = '/usr'
sys.path = [
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007efce1a50c00 (most recent call first):
<no Python frame>
注意
/usr/lib/python3.8
中的sys.path
和program name = '/usr/local/bld-tools/bld-tools-virtual-env/bin/python'
。
从这些信息中我们可以得出:
arm-none-eabi-gdb
取决于Python 3.8'/usr/local/bld-tools/bld-tools-virtual-env/bin/python'
我更喜欢使用 pyenv 来管理虚拟环境和 python 安装,因此我使用它通过以下步骤解决了问题:
curl https://pyenv.run | bash
sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
pyenv install 3.8.18
sudo mkdir -p /usr/local/bld-tools
sudo ln -s $PYENV_ROOT/versions/3.8.18 /usr/local/bld-tools/bld-tools-virtual-env
GDB 现在应该按预期工作:
~ » arm-none-eabi-gdb --version jhcarter@jhcarter-X670E
GNU gdb (Arm GNU Toolchain 12.3.Rel1 (Build arm-12.35)) 13.2.90.20230627-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.