Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Problem running from desktop icon
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Problem running from desktop icon

by RossU on Fri Oct 09, 2020 6:24 pm

I have a program using some adafruit boards that runs quite happily in IDE and if I add #! /usr/bin/python3 as the first line will run quite happily when you double click on the file. I am trying to run it from a desktop icon and the terminal window just flashes and closes. I have stripped things down to a 3 line program and it appears that it is choking on import board or any of the other adafruit imports. It seems to be happy enough with import time or import math or even import numpy. It also chokes on import tkinter, which is interesting. Anyway, I'm assuming this is some kind of path or permission thing. Any suggestions? Below is the trivial program. If you take out import board it runs from the icon just fine.

import time
import math
import numpy as np
import board

while True:
print("Welcome to my desktop")
time.sleep(2)

This is the .desktop file that runs it

[Desktop Entry]
Type=Application
Name=Read_One
Exec=python /home/pi/Documents/Magnetometer/code1.py
Icon=/usr/share/icons/desktop-base/scalable/emblems/emblem-debian.svg
Terminal=true
StartUpNotify=false

RossU
 
Posts: 15
Joined: Tue Jun 21, 2016 2:28 pm

Re: Problem running from desktop icon

by RossU on Sat Oct 10, 2020 11:16 am

So interestingly enough adding a line
Path = /home/pi/Documents/Magnetometer
and changing the Exec line to
Exec=python3 code1.py
solved the problem with the adafruit imports. In addition to the simple example above, it worked on the actual application program which had a lot of imports. Interestingly enough it has not solved the issue of importing tkinter. That is possibly beyond the scope of this forum, but if anybody has any ideas, they would be welcome. Also, if anyone has a clear explanation of why the path variable affects whether it can find the adafruit imports I would be interested.

RossU
 
Posts: 15
Joined: Tue Jun 21, 2016 2:28 pm

Re: Problem running from desktop icon

by RossU on Sat Oct 10, 2020 11:20 am

One further small point. Apparently, it has to be python3 not just python in the Exec line. Not sure why as the simple 3 line code should run in python 2 or 3.

RossU
 
Posts: 15
Joined: Tue Jun 21, 2016 2:28 pm

Re: Problem running from desktop icon

by danhalbert on Sat Oct 10, 2020 11:41 am

`board` is part of adafruit-blinka, which requires python 3. All the adafruit libraries assume Python 3, so if they get imported by Python 2, you will get errors.

BTW, I believe RPi continues to depend on python2, so it's not a good idea to alias python3 to python, or similar tricks, at least at the moment. Eventually they may drop Python2 completely.

danhalbert
 
Posts: 2134
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.