Pandas are driving me mad

Hello there,
I’m new to programming, I installed python3 latest version on my mac book and I use IDLE to write my programs. It works but I also need pandas so I installed homebrew and pip both of which dowloaded some content when I tried installing pandas with them but it’s not working.
I get this error when I try to import pandas on IDLE.

ModuleNotFoundError: No module named 'pandas'

My guess is it’s not looking for it in the right place but how can I fix that ?

95% sure the problem is that you have two different Pythons installed, and one has pandas installed and the other doesn’t.

What version of Python are you running in IDLE? Start up IDLE and take note of the version number is shows.

Then inside IDLE, run these two lines:

import sys
print(sys.executable)

and tell us what it says.

Then back at the OS command prompt, run

pip -V

and again tell us what it says.

Ok thanks for your answer, here’s the IDLE version
Python 3.11.2 (v3.11.2:878ead1ac1, Feb 7 2023, 10:02:41) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
The IDLE script

/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11

and the OS command prompt

pip 23.0.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)

In Terminal, run python3.11. You should see the same Frameworks header as for IDLE. If so, run python3.11 -m pip install pandas to install pandas for Frameworks python3.11. If you see the homebrew header, you are beyond my knowledge.

It issues a syntax error do you know why ?

admin@ordi ~ % python3.11
Python 3.11.2 (main, Feb 16 2023, 02:51:42) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python3.11 -m pip install pandas
  File "<stdin>", line 1
    python3.11 -m pip install pandas
           ^^^
SyntaxError: invalid syntax

You’re mixing up a shell command thinking it’s a Python statement.
You need to do this:

admin@ordi ~ % python3.11 -m pip install pandas

Ok thanks now I’ve got this message

admin@ordi ~ % python3.11 -m pip install pandas
Requirement already satisfied: pandas in /opt/homebrew/lib/python3.11/site-packages (1.5.3)
Requirement already satisfied: python-dateutil>=2.8.1 in ./Library/Python/3.11/lib/python/site-packages (from pandas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /opt/homebrew/lib/python3.11/site-packages (from pandas) (2022.7.1)
Requirement already satisfied: numpy>=1.21.0 in /opt/homebrew/lib/python3.11/site-packages (from pandas) (1.24.2)
Requirement already satisfied: six>=1.5 in ./Library/Python/3.11/lib/python/site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)

It’s just telling you that the latest version of pandas, and
versions of dependencies it wants, are already installed so it
didn’t need to do anything else.

@stex 2nd message shows that IDLE is running on python.org Frameworks 3.11.2 compiled Feb 7. 3rd message shows that % python3.11 is running on binary compiled Feb 16, which has to be the homebrew 3.11.2. So python3.11 -m pip ... tries to install on homebrew, which it already is. If you run % python3.11 -m idlelib do you get IDLE running on Homebrew?

I don’t know how you run pip on python.org binary to other than to give the full path on the command line
/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 -m pip ...
or change directory to that bin directory.

Why do you have 2 distributions of 3.11.2 installed?

The idlelib command returns

** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **

I struggled a lot during the install I went with IDLE at first and found out that some libraries were missing, I then tried Homebrew and that’s probably when I made the 2nd install by mistake… How should I do ?

All I know is to find an app icon in finder and drag to the waste basket. I personally would delete homebrew, verify that python3.11 starts the Framework build, and then run python3.11 -m pip... to install pandas and whatever.

I’m not a Mac OS user, but my (very vague) understanding is that the OS provided Python is terrible and one should always use homebrew.

Any Mac experts care to weigh in?

Yes, the Apple-provided python, upgraded to 2.7.16 in 2021, comes with the buggy tcl/tk 8.5.9 from about 2005. IDLE works on that combination until it doesn’t, which is not rare. The PSF (python.org) installer includes a tested build of the most recent tcl/tk 8.6, currently 8.6.12. This is what anyone should use for tkinter, and hence IDLE. I use IDLE on Mac to test its macOS-specific behavior.

Just noting that IDLE and pandas installs work out of the box for me with Anaconda on OSX

I don’t think I have ever used the system Python or the PSF installers on OSX in the last ~11 years.

Nice to know. For someone using the scientific stack, looks like a good way to go. I’ll just note that people who install the same version with Anaconda and PSF installers (not sure why) run into the issue of not getting things installed with the installation they want.

Could you click ‘about’ on the IDLE menu and report the tk version?

Could you click ‘about’ on the IDLE menu and report the tk version?

In my current env, it is 8.6.12

Good. Perhap Anaconda is including the PSF release in their bundle and releasing after testing that the bundle additions work with the new binary.

Do not throw away homebrew. It has its problems, but is very useful.
Many many MacOS users install homebrew.

The Python 3 which comes with MacOS may be a bit dated, which is how
things often are with distros. At the least, they often stay pinned with
the OS release. For example, this Mac is running MacOS Catalina (a bit
old) and the system supplied Python 3 is:

 Python 3.8.2 (default, Dec 21 2020, 15:06:04)
 [Clang 12.0.0 (clang-1200.0.32.29)] on darwin

@thibault, please run this command at the shell prompt: which -a python3
That should show all the Python executables in your current search
$PATH. For example here I get:

 [~]fleet2*> which -a python3
 /Users/cameron/bin-cs/python3
 /Users/cameron/var/venv/3/bin/python3
 /Users/cameron/bin-local/bin-anaconda3/python3
 /Users/cameron/bin-local/bin-python-3.10/python3
 /Users/cameron/bin-local/bin-usr-local/python3
 /Users/cameron/bin-local/bin-venv/python3
 /Users/cameron/var/homebrew/bin/python3
 /usr/local/bin/python3
 /usr/bin/python3

My environment is a bit elaborate. What’s important above is:

  • /Users/cameron/var/homebrew/bin/python3 which comes from homebrew
  • /usr/bin/python3 which comes from the OS

Each of these has its own package install area.

Because of this, the recommended way to use pip is via the executable
of interest. An example might be:

 /Users/cameron/var/venv/3/bin/python3 -m pip install pandas

which installs pandas in the package are for ~/venv/3/bin/python3
which contains my persoanl virtualenv python3.

What you need to do is locate the python3 which IDLE is using, and
install pandas for that executable.

@tjreedy, do you know how to ask IDLE which python3 it is using?

Happy to help debug this process.

Cheers,
Cameron Simpson cs@cskk.id.au

Sure, I use homebrew, and have for many years—just not at all for Python. Obviously YMMV though.

1 Like

Well I just used your command to install pandas on the correct Python (the one that wasn’t the OS or the homebrew version) and it worked :grin: Thank you and every one else for your help !

1 Like