Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem after clean install #12

Open
janvangent opened this issue May 4, 2020 · 24 comments
Open

Problem after clean install #12

janvangent opened this issue May 4, 2020 · 24 comments

Comments

@janvangent
Copy link

Hi all,

Just did a clean install of raspbian-buster on a Raspberry Pi 3 A+
I have done 2 installs on older raspbian images, both on Pi 3 B without issues, so this is new to me. Any suggestions?
image

Best regards,
Jan

@janvangent
Copy link
Author

Today I've done a clean install with raspbian stretch instead of the new Buster.
Exact same problem.

I've tried switcing to Python 3.7 (systemwide), which results in a failed status as well, but with slightly different errors.

@bmcage
Copy link
Contributor

bmcage commented May 8, 2020

dtm.timezone no longer exists it seems ...
this is part of the telegram library, so error is there.
Cannot test at the moment, I suppose you did:

sudo pip install python-telegram-bot --upgrade  ?? 

perhaps pip3 on buster instead of pip ? I see in the telegram code

import datetime as dtm  # dtm = "DateTime Module"

expecting to have timezone is this line: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/utils/helpers.py#L82

This seems to contain how to fix: https://github.com/python-telegram-bot/python-telegram-bot/pull/1506/files/cc40d63a8ca2e51f71e690fe491cb9d4d31a06d4
and seems to indicate you MUST use python 3.3+ to have dtm.timezone.

So, if not using 3.3+ you need an older version of python-telegram-bot, but this might not work with current telegram api. Otherwise, use python 3.7, and let's fix the errors due to that. Seems the best way forward. Post python 3.7 error in new bug thread

@bmcage
Copy link
Contributor

bmcage commented May 20, 2020

Is this fixed #7 with merged?

@janvangent
Copy link
Author

Yep! #7 fixed this.

@Sn1ckerson
Copy link

Did a clean install, updated Python (3.7) and followed all the steps from the manual (with the new files on this github). Got the same error. Do I have to change some lines of code myself or should this be fixed?

@janvangent
Copy link
Author

Did you check which Python is being used (systemwide)? After a python install, it is not necessary being used...

@Sn1ckerson
Copy link

Sn1ckerson commented Jun 2, 2020

When I type the command
$ python3 --V
it says 3.7
However this got me thinking, why is this saying python3 and not just python.
So I checked
$ python --version
and it still said 2.7.6.5 or something.

So then i recalled the tutorial that I followed told me to go in the bashrc file and type alias python3 = 3.7 instead of python = 3.7
Changed it and now it's actually using 3.7.

After reboot ran the commands

sudo systemctl daemon-reload
sudo systemctl enable fk_chatbot.service
sudo systemctl enable fk_tvbox.service
sudo service fk_chatbot start
sudo service fk_tvbox start
systemctl status fk_chatbot.service

And... same attributeError: 'module' has no attribute 'timezone'
Is this because I ran all the previous commands when I apperantly still had python 2.7 running?

@ErwinP
Copy link
Contributor

ErwinP commented Jun 8, 2020

Hi Sn1ckerson,

Sorry it took a while to get back to you.

What happens if you manually run FK_ChatBot.py by running the following code from the terminal:

cd /home/pi/familiekiosk/src/
python FK_ChatBot.py

Furthermore, which bashrc file did you modify? By addingthat alias to the home/pi/.bashrc (or ~/.bashrc), or did you add it in /etc/bash.bashrc? Note that only the latter allows for a system wide switch to python3, whilst modifying the former will only switch the user 'pi' to Python3. And as I believe that the service is started by the system, it will not working if only 'pi' is on python3.

Regards,
Erwin

@Sn1ckerson
Copy link

Hi Erwin

Thank you for the reply. I did add the alias to the first one so I did the following:
First checked the code you gave me, this is the reply:

Traceback (most recent call last):
File "FK_ChatBot.py", line 31, in
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, Job, BaseFilter)
ModuleNotFoundError: No module named 'telegram'

Next I added the alias using code:
sudo nano /etc/bash.bashrc
Window pops up that says GNU nano 3.2, bunch of blue text
I wrote this on the first line:
alias python='python3.7'
ctrl+X saved it with the same username and exit
Did a reboot, reran the FK_ChatBot.py, same error.

In another thread you asked me what it said when I type
$ python -m telegram

/usr/local/bin/python3.7: No module named telegram
I'm looking at this and am thinking, is this because it's looking in the bin/python3.7 folder, which didn't exist when I installed telegram?

Now I really want it to get it to work, just out of pure stubbornness.

Kind regards
Nick

@ErwinP
Copy link
Contributor

ErwinP commented Jun 14, 2020

Hi Nick,

I have reasons to believe you're almost there!

You installed the python telegram API previously, but only for python 2.7, as that was your default python version at that time.

Since modules for python2 do not get recognized by python 3, you have to install that module again. That is also what the error is saying: python doesn't know what you mean with 'telegram'.

Now that you are on python3 system wide, you can run the following (taken from the installation manual):

sudo pip install python-telegram-bot --upgrade

sudo pip install pexpect --upgrade

This will install the required modules for python3.

After you've did this, you should be able to run the FK_Chatbox.py without rebooting. If you don't get an error, you can reboot, and the service should be running. If it does give an error, you can post that output here ;-)

Kind regards,
Erwin

@bmcage
Copy link
Contributor

bmcage commented Jun 14, 2020

As @ErwinP says.
pip will only do the trick if it calls python3, which should be the case with your bashrc change. If not, use pip3 as command to be sure

@Sn1ckerson
Copy link

Using pip gave me a bunch of "Requirements already satisfied" text.
Using pip3 did a new install.
Reran the python FK_ChatBot.py command and.... ModuleNotFoundError:No module named 'telegram'...

@Sn1ckerson
Copy link

Did some more digging, When I open the FK_ChatBot.py file it says Python 3.7.3 (/usr/bin/python3) in the "shell" box on the bottom.
When I explore the usr/bin folder, there's no python3 map, I do have 3 python folders in the usr/lib folder: python 2.7, python3 and python 3.7, the python3 map only has the dist-packages folder inside of it, the others are stacked with a bunch of folders. When I used the install python telegram code it refers to the python 2.7 (pip) or python 3.7 (pip3) folders, with exception for:

Requirement already satisfied, skipping upgrade: certifi in /usr/lib/python3/dist-packages (from python-telegram-bot) (2018.8.24)

Starting to think I made it too messy and should just do a clean install again.. I did a clean install from the rasberrypi website a couple of weeks ago yet it still had python 2.7 on it? Where do I get the one that has 3.7 already in it?

@bmcage
Copy link
Contributor

bmcage commented Jun 15, 2020

python 3.7 is always in now. python 2 is end of life
I used Raspberry Pi OS (32-bit) with desktop and recommended software (may 2020), and then directly after install on the SD card and startup:

sudo apt update
sudo apt dist-upgrade

Then if python does not start a python 3.7 shell, to change python version over the default one: https://raspberry-valley.azurewebsites.net/Python-Default-Version/#switching-default-python-versions

I never did changes in the my bashrc for that, as that seems like something that would be for one user only, and part of familiekiosk is launched at startup, not as that user.

For telegram, pip3 install should work, but probably there is a package in debian now: https://ubuntu.pkgs.org/20.04/ubuntu-universe-i386/python3-python-telegram-bot_12.4.2-1_all.deb.html
If that is the case, just try

sudo apt install python3-python-telegram-bot

instead of the pip3 install of the bot api. Note that pip3 packages sometimes start with python3 instead of with python, for the python 3 version. It's on my todo to test and update the manual, sorry.

@Sn1ckerson
Copy link

Ok did a clean install again and I see, there's a python and a python3?
But for some reason it used the old version(python) instead of the python3? I did the steps from the raspberry-valley link and when I type python --version it says python 3.7.3. Will follow the manual now and see if that works. If I get the same error (which would be strange... I just copy paste every command to make sure I didn't mess up the spaces or capital letters) I'll try the sudo apt install python3-python-telegram-bot command.
Will keep you updated.

@Sn1ckerson
Copy link

Ladies and gentlemen, we got'em!
● fk_chatbot.service - Telegram Family Chat Bot
Loaded: loaded (/lib/systemd/system/fk_chatbot.service; enabled; vendor prese
Active: inactive (dead) since Tue 2020-06-16 20:00:13 CEST; 1min 32s ago
Process: 1575 ExecStart=/usr/bin/python /home/pi/familiekiosk/src/FK_ChatBot.p
Main PID: 1575 (code=exited, status=0/SUCCESS)

Jun 16 20:00:10 raspberrypi systemd[1]: Started Telegram Family Chat Bot.
Jun 16 20:00:13 raspberrypi python[1575]: No valid config file found - did you r
Jun 16 20:00:13 raspberrypi python[1575]: Exiting...
Jun 16 20:00:13 raspberrypi systemd[1]: fk_chatbot.service: Succeeded.

@Sn1ckerson
Copy link

May I suggest adding the following to the manual (before step 1 Beeldverwerking):
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 3

I guess it must be common sense to experienced raspberrypi users but this helped me out.

@Sn1ckerson
Copy link

New problem..:
● fk_tvbox.service - Family Kiosk System
Loaded: loaded (/lib/systemd/system/fk_tvbox.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-06-16 20:08:06 CEST; 3s ago
Process: 2158 ExecStart=/usr/bin/python /home/pi/familiekiosk/src/FK_TVbox.py > /home/pi/familiekiosk/output_
Main PID: 2158 (code=exited, status=1/FAILURE)

Jun 16 20:08:06 raspberrypi systemd[1]: Started Family Kiosk System.
Jun 16 20:08:06 raspberrypi python[2158]: Traceback (most recent call last):
Jun 16 20:08:06 raspberrypi python[2158]: File "/home/pi/familiekiosk/src/FK_TVbox.py", line 6, in
Jun 16 20:08:06 raspberrypi python[2158]: if os.path.isfile("config.py"):
Jun 16 20:08:06 raspberrypi python[2158]: NameError: name 'os' is not defined
Jun 16 20:08:06 raspberrypi systemd[1]: fk_tvbox.service: Main process exited, code=exited, status=1/FAILURE
Jun 16 20:08:06 raspberrypi systemd[1]: fk_tvbox.service: Failed with result 'exit-code'.

@bmcage
Copy link
Contributor

bmcage commented Jun 17, 2020

ok, updated manual.
Your last error was an error due to the pull request, import os was no longer at the top. Fixed in current version, do git pull, or overwrite with latest version here in repo of src/FK_TVbox.py. Please test. This means other errors might be present too, as everybody using latest code should have had this issue ...

@Sn1ckerson
Copy link

Sn1ckerson commented Jun 20, 2020

Running it now gives the fellowing error:
Jun 20 13:15:42 raspberrypi python[1741]: No valid config file found - did you rename config.py.in to config.py?
I saw this is a later step in the manual so I renamed the file to config.py and reran FK_TVbox. It gave me a grey screen for 10 sec followed by these errors (in Thonny):

FK_TVbox.py:167: PyGIDeprecationWarning: Since version 3.11, calling threads_init is no longer needed. See: https://wiki.gnome.org/PyGObject/Threading
GObject.threads_init()

Detected the first boot
not in recent mode and not in random mode - use the sorted list
Detected the first boot
not in recent mode and not in random mode - use the sorted list
SHOWING /home/pi/familiekiosk/src/pics/dummy/dummy.jpg 600 450 1824 983
In close fullscreen

invalid command name "1955560384update_app"
while executing
"1955560384update_app"
("after" script)

Running the systemctl status fk_tvbox.service command returns:
fk_tvbox.service - Family Kiosk System
Loaded: loaded (/lib/systemd/system/fk_tvbox.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2020-06-20 13:23:31 CEST; 1s ago
Process: 2052 ExecStart=/usr/bin/python /home/pi/familiekiosk/src/FK_TVbox.py > /home/pi/familiekiosk/output_TVbox.log 2>&1 (code=exited, status=0/SUCCESS
Main PID: 2052 (code=exited, status=0/SUCCESS)

Jun 20 13:23:31 raspberrypi systemd[1]: Started Family Kiosk System.
Jun 20 13:23:31 raspberrypi python[2052]: No valid config file found - did you rename config.py.in to config.py?
Jun 20 13:23:31 raspberrypi python[2052]: Exiting...
Jun 20 13:23:31 raspberrypi systemd[1]: fk_tvbox.service: Succeeded.

@bmcage
Copy link
Contributor

bmcage commented Jun 22, 2020

You need to indeed rename config.py.in to config.py, and open it, setting the configuration options as you want them. Like your channel and token acces to Telegram:

https://github.com/TeamScheire/familiekiosk/blob/master/handleiding/FamilieKiosk%20Instellen.md#familie-kiosk-instellen

The systemctl still says: No valid config file found, so set that first.

@Sn1ckerson
Copy link

Hi, sorry it took a while. Tried to rush things, SD-card got broken (3d-printed box was too small..)
Good news! I'm currently looking at the photo's I uploaded on my TV and I'm able to scroll through them (somewhat).
A few issues however:

  1. Both FK_chatbot and TVbox don't start errorless after reboot. They do start but nothing is showing, so I checked the status of both programs and got the "config.py file not found" error for both of them. Strange because it's there. Same thing when I try to start it through the terminal with sudo service fk_tvbox start.
    But when I start it manually by going to the familiekiosk/src files, it works. Both the chatbot (letting me upload the photo's) and tvbox (showing me all the uploaded photo's).

  2. Photo's are downloaded correctly, video's are not. Noticed some errors in the log:

 2020-07-07 13:05:00,712 - videohandler - INFO - video received
2020-07-07 13:05:00,715 - telegram.utils.promise - ERROR - An uncaught error was raised while running the promise
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/telegram/utils/promise.py", line 56, in run
    self._result = self.pooled_function(*self.args, **self.kwargs)
  File "/home/pi/familiekiosk/src/videohandler.py", line 109, in on_video_received
    if update and update.message:
AttributeError: 'CallbackContext' object has no attribute 'message'
  1. Forward button works, previous doesn't. Checked the wires and there shouldn't be anything wrong with it, both reply and previous button are connected the same way. Might check with a different wire (can I look for the problem with a multitool?)

  2. Reply button crashes TVbox but this might be due to the fact that chatbot wasn't running. However, when starting chatbot the following error keeps repeating:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/telegram/ext/jobqueue.py", line 418, in tick
    job.run(self._dispatcher)
  File "/usr/local/lib/python3.7/dist-packages/telegram/ext/jobqueue.py", line 574, in run
    self.callback(CallbackContext.from_job(self, dispatcher))
  File "/home/pi/familiekiosk/src/replyhandler.py", line 75, in do_reply
    bot.send_message(chat_id=chat_id, text=msg_text)
NameError: name 'bot' is not defined

@Sn1ckerson
Copy link

Sn1ckerson commented Sep 29, 2020

Bump!
I had a friend of mine look at the code and apperantly there's something wrong with the bootsequence.
First of all the FK_chatbot and TVbox wouldn't automatically start up because in os.path.isfile("config.py"): he didn't look in the SRC folder. If i recall correctly my friend fixed this by first making him look for the path, add that to a variable "Path" and using that variable instead.
This fixed it, the code is able to find the config file but after a restart there's still nothing on the screen.
My friend went searching for the problem again and told me that the script is running before the screen is recognised which results in an error.


Edit:
He thinks both problems are connected. The systemd service is running too soon even if it says "after multi user", which should be after the graphical target.

@bmcage
Copy link
Contributor

bmcage commented Oct 29, 2020

Boot sequence order changing over different releases is unfortunately a common problem.
Perhaps try the trick of custom target: https://www.mauras.ch/systemd-run-it-last.html
Otherwise try with graphical.target. https://unix.stackexchange.com/questions/506347/why-do-most-systemd-examples-contain-wantedby-multi-user-target
I still did not rebuild with latest raspbian, can only give more info after I find time to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants