Why I am getting "zsh: command not found: from" error on my MacBook Pro M4 Max?

Every time I try to run "from test0 import test_prime" i get "zsh: command not found: from" my macbook is pro m4 max


[Re-Titled by Moderator]

Original Title: zsh: command not found: from





MacBook Pro 14″, macOS 15.5

Posted on Jun 3, 2025 2:47 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 3, 2025 3:59 AM

Mate, f.k me, so many hours studying, I'm getting crazy.


it's woooooorking.


I need just to run python first to get python interpreter.

>>

And then run:

>>from test0 import test_prime



Thanks anyway, I appreciate that, so kind of you try to help me, I'll get a break and have some food


Peace 🤙🏼

have a good one

12 replies

Jun 3, 2025 4:32 AM in response to RoneyWMoreira

You either have the first line in your Python script that looks like this:

#!/usr/bin/env python3


and the script marked executable in the Zsh shell:

chmod +x script.py


or you invoke your Python3 script in the following manner if the preceding she-bang is missing:

/usr/bin/python3 script.py



And any import clause, where the module is not part of the standard Python distribution would need to be installed beforehand.


In the case of your Python 3.9.6 (which I never use) that is what Apple still installs with the CommandLine Tools for Xcode, and I would not touch it with a stick. Instead, I download and use the current (3.13.3) package installer from Python.org. That is years more current than what Apple still provides, and it is installed into these locations:

  • /Library/Frameworks/Python.framework
  • /usr/local/bin
    • Links to the relevant binaries in that preceding framework location
    • e.g. python3, pip3, idle3, etc.
  • /Applications
    • Python 3.13 folder (I never run anything from here)
      • IDLE
      • Python Launcher
      • other documents including ReadMe.rtf


Any third party packages that you install will be installed into that preceding framework location, and not in /Users/username/Library/Python/3.9/* where the Apple Python3 distributions are located.


When you install Python3 from Python.org, you will need to modify your Zsh shell PATH statement (e.g. .zshrc) to include the Python3 framework location:

export PATH=".:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"


and with that PATH adjustment, Apple's Python 3.9.6 binaries and packages are seen after the Python.org installation and that is where the #!/usr/bin/env python3 invocation line comes into play. It will run the Python.org version and packages first as it should.

Jun 3, 2025 3:24 AM in response to Barney-15E

Thanks! Exactly, I never heard it too. Testing and CI/CD.mp4 - CS50 from Harvardx school


I'm try to run this file_


test0.py


1 from prime import is_prime

2

3 def test_prime(n, expected):

4 if is_prime(n) != expected:

print(f"ERROR on is_prime({n}), expected {expected}")


but every time I try to run I get this message


(base) r*****@R****-MacBook-Pro lecture7 % from test0 import test_prime

zsh: command not found: from



[Edited by Moderator]

Jun 4, 2025 8:26 AM in response to Barney-15E

Hi,


Do you know how to fix python "KeyError", I'm trying to run "python manage.py test"


but I'm getting this message!


"ERROR: test_flight_page_non_passengers (flights.tests.FlightTestCase)

----------------------------------------------------------------------

Traceback (most recent call last):

File "/Users/roneymoreira/Downloads/CS50/Studio v. code/airline/flights/tests.py", line 87, in test_flight_page_non_passengers

self.assertEqual(response.context["non_passengers"].count(), 1)

File "/Users/roneymoreira/micromamba/lib/python3.9/site-packages/django/test/utils.py", line 82, in __getitem__

raise KeyError(key)

KeyError: 'non_passengers'"


thanks


Roney

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.

Why I am getting "zsh: command not found: from" error on my MacBook Pro M4 Max?

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