Problem with default python3 and pip3 locations

I have run numerous python3 installations on a couple of MacBook Pros over the last 10 years, always installing from python.org so am familiar with where these installs usually reside.


Now I have a new Mac Mini M2 running Sonoma 14.2.1.  I wanted to check out the default python3 environment before installing my own.


Not knowing anything about the default file locations, from my home directory I entered


% which python3
/usr/bin/python3
% which pip3
/usr/bin/pip3


and that seemed consistent, so I used pip3 to install Jupyter Lab

% pip3 install jupyterlab


Installation messages scrolled up and everything seemed OK.  So, still within my home directory I entered

% jupyter lab
zsh: command not found: jupyter


OK, I guess I might need to edit my $PATH.  So I went to check where pip3's packages are


% pip3 -V

pip 21.2.4 from /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework
/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)


This was as little surprising as I thought (from 'which' above) that pip3 was located at /usr/bin/pip3


I checked /usr/bin/pip3 and it is not a symlink.


So I added  /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages to the front of my $PATH in my .zshrc, sourced that and tried the jupyter lab command again.  Same result, command not found.


I manually inspected the site-packages directory in the above path and none of the jupyter packages are there.


However, when I pip3 list, Jupyter is included along with all of its dependencies.  None of these were in the site-packages directory I looked at.


Then I started up the python3 REPL from my home directory to find the location of the python3 binary


% python3
Python 3.9.6 (default, Nov 10 2023, 13:38:27) 
[Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
/Library/Developer/CommandLineTools/usr/bin/python3


Again, surprising, as the 'which' command above returned /usr/bin/python3 — and just as with /usr/bin/pip3, not a symlink. To remove any doubts about PATH configuration I ran /usr/bin/python3 directly and got the same results as to the location of the executable.


% /usr/bin/python3
Python 3.9.6 (default, Nov 10 2023, 13:38:27) 
[Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
/Library/Developer/CommandLineTools/usr/bin/python3


So I have 3 questions


  1. Why does ‘which’ show the /usr/bin locations but python3 and pip3 themselves report different locations?
  2. 'pip3 list' thinks jupyterlab is installed but the package is not located in pip3’s site-packages directory
  3. Where did pip3 actually install jupyterlab and its dependencies, and why there?


Mac mini (M2, 2023)

Posted on Jan 21, 2024 12:11 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 21, 2024 1:29 PM

When you are using Python 3.9.6 and pip3 from the command line tools for Xcode, /usr/bin/pip3 will install packages into:


/Users/yourname/Library/Python/3.9/lib/python/site-packages


and:


/usr/bin/pip3 show jupyterlab


will confirm that, if it really installed.


If you also happen to have Python 3.12.1 installed from Python.org, it will install its python3 from its Framework bin location into /usr/local/bin, and if you are promoting that location over /usr/bin in your PATH, the third-party python modules are installed in:


/Library/Frameworks/Python.framework/Versions/Current/lib/python3.12/site-packages


which is where a /usr/local/bin/pip3 show command would reveal installed packages.


Similar questions

4 replies
Question marked as Top-ranking reply

Jan 21, 2024 1:29 PM in response to Carl_V

When you are using Python 3.9.6 and pip3 from the command line tools for Xcode, /usr/bin/pip3 will install packages into:


/Users/yourname/Library/Python/3.9/lib/python/site-packages


and:


/usr/bin/pip3 show jupyterlab


will confirm that, if it really installed.


If you also happen to have Python 3.12.1 installed from Python.org, it will install its python3 from its Framework bin location into /usr/local/bin, and if you are promoting that location over /usr/bin in your PATH, the third-party python modules are installed in:


/Library/Frameworks/Python.framework/Versions/Current/lib/python3.12/site-packages


which is where a /usr/local/bin/pip3 show command would reveal installed packages.


Jan 21, 2024 2:17 PM in response to Carl_V

Carl_V wrote:

I have run numerous python3 installations on a couple of MacBook Pros over the last 10 years, always installing from python.org

Apparently not. 😄

I wanted to check out the default python3 environment before installing my own.

There is no default python3 environment and never has been. Apple used to include a version of python 2, but stopped doing that a few years ago. Apple does include a version of Python3 with the Command Line developer tools. I don't know why they do this. Perhaps just to confuse people who try it so they'll never use Python again?

Again, surprising, as the 'which' command above returned /usr/bin/python3 — and just as with /usr/bin/pip3, not a symlink. To remove any doubts about PATH configuration I ran /usr/bin/python3 directly and got the same results as to the location of the executable.

I'm guessing that doubts still remain. 😄

Why does ‘which’ show the /usr/bin locations but python3 and pip3 themselves report different locations?

Because those are just stubs used to trigger installation of the Command line developer tools if you try to use them. Quite a few of the executable in /usr/bin (such as "git") are the same thing.

'pip3 list' thinks jupyterlab is installed but the package is not located in pip3’s site-packages directory
Where did pip3 actually install jupyterlab and its dependencies, and why there?

Yeah, I'm not going to punish you anymore. 😄


You had the right idea the first time. Always download Python from the source. Configure your environment to use your Python and nothing else. If necessary, you can setup a complete command line environment running entirely out of /usr/local, or wherever you'd like. You can install most open source packages or tools from source and they will work, usually. There are always a few that were last hacked up in 1992 and won't work on a modern Mac. People are always inventing new ways to hack around with autoconf, cmake, or just inventing entirely new toolchains because autoconf and cmake simply didn't make people's lives difficult enough. But these are the outliers. Most things will build from source and work without complaint.


You just have to be careful with Apple tools when you are doing this. You'll have to use some, like clang or it's faked-out gcc. But Apple's Python, for example, is only for Apple's own use. You'll encounter no end of hassles if you try to use it.


PS: Please don't use Homebrew or anything like it.

Jan 21, 2024 1:11 PM in response to Carl_V

Carl_V wrote:

I have run numerous python3 installations on a couple of MacBook Pros over the last 10 years, always installing from python.org so am familiar with where these installs usually reside.
...
1. Why does ‘which’ show the /usr/bin locations but python3 and pip3 themselves report different locations?
2. 'pip3 list' thinks jupyterlab is installed but the package is not located in pip3’s site-packages directory
3. Where did pip3 actually install jupyterlab and its dependencies, and why there?


You have added your stuff to your PATH, but have you checked what else is in your PATH?


With older (and upgraded) Mac installs, PATH tends to accrete, stuff sometimes still in use and sometimes not.


In general: stuff in /usr (other than /usr/local) is from Apple.


Any python located in /usr/bin (other than in /usr/local) was installed by Apple.


As for where else some file might be located, use find or mdfind, and search for it:

 mdfind -literal "kMDItemDisplayName == python3*"


Locally-added stuff is usually located somewhere under /usr/local, which is user-accessible and modifiable.


The ordering of entries within PATH probably isn't what you want it to be, and you're getting the first python3.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Problem with default python3 and pip3 locations

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.