在 mac 上安装 python 的 Homebrew 返回奇怪的响应,包括“第 1 行://:是一个目录”和“第 7 行:意外标记 `('”附近的语法错误

问题描述 投票:0回答:1

当我运行

python3
时,我得到以下信息

 % python3
/opt/homebrew/bin/python3: line 1: //: is a directory
/opt/homebrew/bin/python3: line 3: //: is a directory
/opt/homebrew/bin/python3: line 4: //: is a directory
/opt/homebrew/bin/python3: line 5: //: is a directory
/opt/homebrew/bin/python3: line 7: syntax error near unexpected token `('
/opt/homebrew/bin/python3: line 7: `����
                                        0� H__PAGEZERO�__TEXT@@__text__TEXT;�__stubs__TEX>�
           __cstring__TEXT�>��>__unwind_info__TEXT�?X�?�__DATA_CONST@@@@__got__DATA_CONST@�@�__DATA�@__bss__DATA�H__LINKEDIT����M4���3���0���0
                                                              PP�% 
                                                                   /usr/lib/dyldY*(�;��g�g�2 
     x

      /opt/homebrew/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/Python
                8d'/usr/lib/libSystem.B.dylib&��)�� ��H����_��W��O��{������ �'X�C���`5�� �
          @������������������������T��J�_8� �_�qA��T�   ��*@8_���i � @�� ��<���R�� " ��3����5�! �����R�����0 Ձ` ը���` ��p ��R�R�� �BT�^ յ �����@99� Ձ] ��������9�\ ����R�Ri� �Tc������� �0 աZ �"�R{�t��
                                               ��C�� @��C���������_���!0 � �RN�����O��{������W���=��45�� �r�����#���!�RN�1T�@���T��RI���)��35�{B��OA�����_��
                                                                            � X@�p �A�R"�R(� �R#���{����
��@���'�{�����   �@�R    � �R��{����a

尝试使用

python3 --version
检查版本会返回相同的结果

该错误似乎是随机发生的,有一段时间没有发生(安装 python3.10 之后再次安装 python3.11 后),然后有一天又随机开始发生


% od -tx1 /opt/homebrew/bin/python3 | head -n 5
0000000    2f  2f  20  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d
0000020    2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d
*
0000100    2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  2d  0a
0000120    0a  2f  2f  20  50  4c  45  41  53  45  20  44  4f  20  4e  4f

% file /opt/homebrew/bin/python3
/opt/homebrew/bin/python3: data
python python-3.x homebrew
1个回答
0
投票

1.通过运行brew doctor 验证您的Homebrew 安装。修复报告的所有错误。

2.通过运行brew info python 验证Python 是否已正确安装。查找一行“如果您需要在 PATH 中首先包含 Python XYZ,则添加:”,然后将该行添加到 shell 的配置文件中。

3.确保您的 shell 的配置文件格式正确。在文本编辑器中打开 shell 的配置文件(例如 .bashrc、.bash_profile、.zshrc 等)并查找任何错误,特别是与您的 Python 路径有关的错误。

4.修复任何问题后,重新启动终端或运行 source ~/.bashrc (或 shell 的等效命令)以应用更改。

5.通过运行which python检查Python现在是否已正确安装和配置。这应该返回现在正在使用的 Python 可执行文件的路径。

如果您仍然遇到问题,可以尝试使用 Homebrew 卸载并重新安装 Python:

brew 卸载 python 酿造清理 酿造安装Python

请记住在重新安装 Python 后执行步骤 2-5。如果您仍然遇到问题,则可能是您使用的特定 Python 版本存在问题。您可能需要考虑使用 Homebrew 安装不同版本的 Python 或完全不同的安装方法。

© www.soinside.com 2019 - 2024. All rights reserved.