Python Forum
ImportError: No module named error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError: No module named error
#1
Hi all!

So I have a small Python program I'm trying to get working on my Mac downloaded from here: https://gitlab.com/bharadwaj-raju/WeatherDesk . It's a nifty script that changes the desktop wallpaper depending on the local time and weather conditions. I'd like to configure it and have it run automatically each time I start my machine.

Unfortunately I can't get it to run without throwing up an error. I've downloaded the new version of Python (3.6.5) and I'm trying to run the script (moved to a folder in my Applications directory) with the following code in Terminal:

cd '' && '/usr/bin/pythonw' '/Applications/WeatherDesk/WeatherDesk.py' && echo Exit status: $? && exit 1

The output is:

[inline]Traceback (most recent call last):
File "/Applications/WeatherDesk/WeatherDesk.py", line 30, in <module>
import urllib.error
ImportError: No module named error[/inline]

Could this be a problem with something in the script, or my Python configuration, or some quirk specific to a Mac? I know nothing about Python unfortunately, but I'd be appreciative of anyone who could hold my hand through getting this script working as I spent the previous night downloading and editing wallpapers for it!
Reply
#2
You get error because you run Python 2 /usr/bin/pythonw

Doing it Right Mac
Then you test,if follow that link python will point to python 3.
# Do I have a Python 3 installed?
$ python --version # or python3 --version
Python 3.6.5 # Success!
# If you still see 2.7 ensure in PATH /usr/local/bin/ takes pecedence over /usr/bin/
If python3 point to your python 3.6.5.
$ python3 WeatherDesk.py --help
Reply
#3
Thanks snippsat! This definitely put me in the right direction. The problem does indeed stem from Mac OS's preference for the version of Python 2 that comes preinstalled. I thought installing the latest version from the official Python site would've been enough for it to take precedence, but no.

The linked instructions proved to be a bit more than what I needed. But for anyone else who stumbles upon this thread, I found I was able to launch my script with Python 3 by changing the cd command in my launch code from /usr/bin/pythonw to /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6. A little clunky, but it proved easier to just change the Python version used for launching this script then to change things globally. Using Python 3 allowed my script to find the urllib module it could't find in Python 2.

Thanks again!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 878 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 23,740 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,565 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,443 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,506 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,337 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 1,039 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Help with pyinstaller "No module named" korenron 9 9,068 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,012 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,849 Oct-20-2022, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020