Ex. 25 on macOS

Good Afternoon,

I am trying to run ex. 25 on macOS and I am having problems. When trying to import the module, I receive the following error. In other posts on this forum, I have seen resolutions for those running Windows, but nothing for macOS. Please help, and thanks in advance!

Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ex25
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ex25'

We’ll need to see the files and the folder structure if you want us to help.

CleanShot 2020-08-26 at 17.01.42@2x

vacowboy-imac:bin dngra_000$ which python38
vacowboy-imac:bin dngra_000$ which python3.8
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
vacowboy-imac:bin dngra_000$ pwd
/Library/Frameworks/Python.framework/Versions/3.8/bin
vacowboy-imac:bin dngra_000$ 

@florian Appreciate your willingness to assist.

The output of pwd seems to show that you’re not in the folder where ex25.py3 is. You can only import file modules from your current location. Could that be the issue?

Yes, what @florian said and also don’t forget to save the file. If you have ex25.py written, but not saved yet, then it’ll either be missing or empty on the disk and python can’t load it.

Good morning,

Hopefully the screenshot is clear. I ensured that the file ex25 is in the same directory where I execute python3.8. I am still unable to import.

CleanShot 2020-08-27 at 09.44.46

Okay that is weird, but I don’t understand why you are in that system folder to begin with. You should have the Python executable in your path so you can launch Python everywhere.

Can you go to your documents folder where you originally saved the file, start Python there and try the import?

@florian, That’s where I first started. When I read on the forum and noticed the problems the Windows users were having, I applied it to my situation.

I have the same problem when I import from my working directory.

Hmm. I see. I’m afraid I don’t know what else to try, sorry. Hopefully @zedshaw can help.

You are running python from its library location as @florian said. You really don’t want to be in there hacking about.

Just like other documents, you’ve saved files in a user file system location like user/somebody/documents which is fine.

When you run the python interpreter, it can be from anywhere on the file system. But it will only find files in that location. So running it in the file system (bin) won’t find ex25.py because it’s not there.

Run the python command from the location where all your scripted files are.

Also I’d strongly advise not following Windows solutions on OSX :wink:

@gpkesley Before I posted, I was running everything /usr/somebody/documents to no avail. LOL and agree with:

Also, I’d strongly advise not following Windows solutions on OSX :wink:.

I was grasping at straws, but I know better.

Are you 100% sure it was that location as every image you posted suggests otherwise.

It’s an easy mistake to make. What happens if you try that now? Can you screenshot the ‘pwd’, then run python, then try the import…

We can then see all the terminal outputs…

@gpkesley…agreed. Hopefully this screenshot clears up any confusion. Please let me know if you have any questions or concerns.

CleanShot 2020-08-27 at 17.17.16

Okay that is super weird. Can you import any of the other python files in that directory?

Since we’re grasping at straws anyway, can you

  • check the file permissions on ex25.py3,
  • and, just for the fun, rename it to ex25.py and try again?

@florian Changing the filename to ex25.py worked!! Thank you very much! Any ideas as to why that is the case?

I am very thankful to this forum for its patience and willingness to assist. I pledge to pay it forward as I learn and grow.

Ha! I knew it! Well, no I didn’t, but that was actually my first intuition. Always trust your stomach. :smiley:

No idea why. Maybe they dropped support for that extension at some point. May I ask why you saved your files like that to begin with?

I was thinking similarly @florian. I had to google if .py3 was even a thing…

Now for homework @vacowboy write a little script that looks for .py3 extensions in a directory and replaces it with .py extension. :grinning:

:slight_smile: Here’s a bash solution. Bash can do surprisingly many things with strings!

for f in `find . -name "*.py3"`; do mv $f ${f/.py3/.py}; done;
2 Likes

@florian…hindsight being 20/20, I have no earthly idea. I looked back over all of the setup and nothing in @zedshaw’s documentation said to do that. Not a great idea.