我在 IDLE 中的 sys.path 与终端中的 sys.path 不匹配。我在哪里可以全局修改 Mac Big Sur 上的 python 路径?
My sys.path in IDLE does not match sys.path from terminal. Where can I globally modify the python path on Mac Big Sur?
我正在尝试修改我的 python 路径。我通过使用 PYTHONPATH 而不是 PATH 变量在 .bash_profile 中成功修改,但是来自终端的 sys.path 与 IDLE 不匹配。 python 版本在两者中是相同的,所以我不确定为什么路径不匹配。我在 IDLE 中尝试了这段代码:
>>> import sys
>>> print("\n".join(sys.path))
/Users/samantha.cruz/Documents
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Users/samantha.cruz/Library/Python/3.8/lib/python/site-packages
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
>>> print(sys.version)
3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)]
>>> sys.executable
'/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8'
>>>
同样的代码在终端中的结果如下:
(base) SamanthaCruz-MBPro:~ samantha.cruz$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print("\n".join(sys.path))
/Users/samantha.cruz/Documents/tftest/models/models/research
/Library/Frameworks/Python.framework/Versions/3.8/bin
/Applications/CMake.app/Contents/bin
/Library/Frameworks/Python.framework/Versions/2.7/bin
/Library/Frameworks/Python.framework/Versions/3.7/bin
/anaconda3/bin
/Users/samantha.cruz/anaconda3/bin
/Users/samantha.cruz/miniconda3/condabin
/usr/local/opt/gettext/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/share/dotnet
/opt/X11/bin
/Users/samantha.cruz/~/.dotnet/tools
/Library/Apple/usr/bin
/Developer/Panda3D/bin
/Library/Frameworks/Mono.framework/Versions/Current/Commands
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Users/samantha.cruz/Library/Python/3.8/lib/python/site-packages
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
>>> print(sys.version)
3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)]
>>> sys.executable
'/Library/Frameworks/Python.framework/Versions/3.8/bin/python3'
>>>
如何才能使它们具有相同的路径?如果那不可能,我如何在全局范围内为 IDLE 修改 sys.path(而不仅仅是当前会话)?
下载 anaconda 后,我的终端默认在虚拟环境中打开。修复很容易。只需在终端中输入以下命令:
conda deactivate
然后,路径将与IDLE的路径匹配,并且可以安装库以在IDLE中使用。
我正在尝试修改我的 python 路径。我通过使用 PYTHONPATH 而不是 PATH 变量在 .bash_profile 中成功修改,但是来自终端的 sys.path 与 IDLE 不匹配。 python 版本在两者中是相同的,所以我不确定为什么路径不匹配。我在 IDLE 中尝试了这段代码:
>>> import sys
>>> print("\n".join(sys.path))
/Users/samantha.cruz/Documents
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Users/samantha.cruz/Library/Python/3.8/lib/python/site-packages
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
>>> print(sys.version)
3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)]
>>> sys.executable
'/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8'
>>>
同样的代码在终端中的结果如下:
(base) SamanthaCruz-MBPro:~ samantha.cruz$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print("\n".join(sys.path))
/Users/samantha.cruz/Documents/tftest/models/models/research
/Library/Frameworks/Python.framework/Versions/3.8/bin
/Applications/CMake.app/Contents/bin
/Library/Frameworks/Python.framework/Versions/2.7/bin
/Library/Frameworks/Python.framework/Versions/3.7/bin
/anaconda3/bin
/Users/samantha.cruz/anaconda3/bin
/Users/samantha.cruz/miniconda3/condabin
/usr/local/opt/gettext/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/share/dotnet
/opt/X11/bin
/Users/samantha.cruz/~/.dotnet/tools
/Library/Apple/usr/bin
/Developer/Panda3D/bin
/Library/Frameworks/Mono.framework/Versions/Current/Commands
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Users/samantha.cruz/Library/Python/3.8/lib/python/site-packages
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
>>> print(sys.version)
3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)]
>>> sys.executable
'/Library/Frameworks/Python.framework/Versions/3.8/bin/python3'
>>>
如何才能使它们具有相同的路径?如果那不可能,我如何在全局范围内为 IDLE 修改 sys.path(而不仅仅是当前会话)?
下载 anaconda 后,我的终端默认在虚拟环境中打开。修复很容易。只需在终端中输入以下命令:
conda deactivate
然后,路径将与IDLE的路径匹配,并且可以安装库以在IDLE中使用。