Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NotJohnnyQuest

macrumors member
Original poster
Oct 26, 2009
73
2
Hi all!

I hope I'm coming to the right place. I know nothing about programming, apart from some basic CSS/HTML. But I'm interested in using this Python script on my Mac called WeatherDesk, that changes the wallpaper based on the current time/weather: https://gitlab.com/bharadwaj-raju/WeatherDesk . 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:

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

I'm very keen on getting this working as I spent last night painstakingly searching out and editing different wallpapers. But I don't know the first thing about even executing a Python script, much less configuring this one properly. But it looks fairly basic. Is it possible someone who knows far more about this than I could give me a bit of help?

In return I could share some of the cool wallpapers I found!
 
Last edited:
I guess there are several problems:
- the command you use to run the script looks cumbersome
- the version of Python you think you might use is probably not version 3.6.5

I'm not really experienced with Python, but what I could find out so far:
- As macOS comes with a preinstalled version of Python, things might break, if one doesn't set up a more advanced environment for Python.
- it's been working for me to leave the system Python untouched, then install and configure the Python version manager pyenv. That lets me switch through different minor and major versions of Python, including the preinstalled one.
- For an even more advanced setup, one could also incorporate virtualenv to the toolset to get not just version management, but even isolated virtual Python environments. As I had no need for that so far, I just used pyenv without virtualenv.

A short summary of the setup procedure that worked for me, to get you on track. Don't just use the commands. Especially /path/to/my/local/repositories/pyenv won't exist before you create it at a place that makes sense to you (I use /Applications/CLI/pyenv). You might want to install a Python version like 3.6.5 and not 2.7.15:
Code:
-> clone Git repository:
git clone https://github.com/pyenv/pyenv.git /path/to/my/local/repositories/pyenv

-> edit .bash_profile:
echo 'export PYENV_ROOT="/path/to/my/local/repositories/pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

-> restart shell:
exec "$SHELL"

-> install readline and xz with brew (could also be compile from source without brew):
brew install readline xz

-> install some Python version 2.7.15 (maybe 3.6.5 in your case):
pyenv install 2.7.15

-> rehash pyenv:
pyenv rehash

-> activate Python 2.7.15 (maybe 3.6.5 in your case):
pyenv shell 2.7.15

-> new Shell windows are still loading preinstalled Python (in my case 2.7.10)
-> to change that behaviour, add the version that is activated in standard to .bash_profile
echo 'export PYENV_VERSION="2.7.15"' >> ~/.bash_profile

-> to check which version of Python is active:
python -V

If you type the last command and get something like Python 3.6.5 back, you should be ready to use WeatherDesk.py with a command like this:
Code:
python /Applications/WeatherDesk/WeatherDesk.py > /dev/null &
 
Nor sure if you ever got this to work, but it looks like you are trying to run this app under Apple's default python (2.7) instead of python3. It doesn't look like python2.7 has urllib.error module.

You don't have to use the python command at the beginning to start the application. The she-bang on the first line specific using python3 as the environment. You just need to make the application executable.

Code:
cd /Applications/WeatherDesk/
chmod +x ./WeatherDesk.py

you can then run the app by just typing:
Code:
./WeatherDesk.py
from the Application folder in Terminal.

Also the read me on the GIT page has the command to run it in the background:

Code:
python3 WeatherDesk.py > /dev/null &

That runs the python3 environment, runs the WeatherDesk.py app, redirects all output to /dev/null, and returns to the terminal line without waiting for the App to exit.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.