python-3.xsyspythonpathsys.path

My sys.path in IDLE does not match sys.path from terminal. Where can I globally modify the python path on Mac Big Sur?


I am trying to modify my python path. I successfully modified in .bash_profile by using PYTHONPATH instead of PATH variable, but the sys.path from terminal does not match IDLE. The python version is the same in both, so I am not sure why the paths do not match. I tried this code in 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'
>>> 

The same code had the following results in the terminal:

(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'
>>> 

How do I make it so that they both have the same path? And if that's not possible, how do I modify sys.path for IDLE globally (not just for the current session)?


Solution

  • After downloading anaconda, my terminal was opening in a virtual environment by default. The fix is easy. Just put the following command in the terminal:

    conda deactivate
    

    Then, the path will match the path with IDLE and libraries can be installed to use in IDLE.