Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Thonny and Python Mess
#1
Looking for any and all guidance on the following issues. If this is not the correct forum, please advise

I have developed Raspberry PI Weather Station on Raspian 11 running Python 3.9.2 and Thonny 3.3.14. I've move Python development to an old notepad running Raspberry PI for Desktop (Debian 10 Buster). This runs Python 3.7.3 and Thonny 3.3.10. I installed Python 3.9.2 on Debian hoping to get Thonny 3.3.10 to use it without success.

QUESTION 1: How do I get to Thonny 3.3.14 and Python 3.9.2 on the Debian so I have consistent environments between the two systems?

QUESTION 2: I think I may not be using PIP correctly. What is the best practice for loading Python packages? PIP. APT-GET, with/without SUDO? How do I clean up my PIP mess?


Below is background on each.

Thanks for any assistance

----------------------------------------------------------------------------------------------------------------------------------------------
QUESTION 1: BACKGROUND

I have Thonny on Debian configured to use the RPI Python Interpreter.

I installed Python 3.9.2 on Debian and have tried to link Thonny 3.7.3 to it. However, I'm getting a tk error I believe because of the version of Python I installed.

I now have the following deployed on the Debian based on their shell commands (> indicates sym link; = actual)
• Python2 > /usr/bin/python2.7 = 2.7.16 (I know better than to touch this one)
• Python3 > /usr/bin/python3.7 = 3.7.3
• Python3.9 = /usr/local/bin/python3.9 = 3.9.2

Thonny is in /usr/bin.

I've tried to clean up by removing 3.9.2 but no command I've tried works. It can't find the package.
----------------------------------------------------------------------------------------------------------------------------
QUESTION 2 BACKGROUND

A related problem I found was when I tried to import 'suntime'  Python  package on the Debian to test a piece of code out. The 3.7.3 Python Interpreter in Thonny 3.7.3 could not find it.  Python 3.9.2 found it on a manual compile. 

Looking at 'site-packages' I have

pi@deb:~/.local/lib $ ls -lah ./python3.7/site-packages
total 592K
drwxr-xr-x 12 pi pi 4.0K Mar 26 17:47 .
drwxr-xr-x  3 pi pi 4.0K Mar 25 17:02 ..
drwxr-xr-x  3 pi pi 4.0K Mar 26 17:47 bcrypt
drwxr-xr-x  2 pi pi 4.0K Mar 26 17:47 bcrypt-3.2.0.dist-info
drwxr-xr-x  3 pi pi 4.0K Mar 26 17:47 cffi
drwxr-xr-x  2 pi pi 4.0K Mar 26 17:47 cffi-1.15.0.dist-info
-rwxr-xr-x  1 pi pi 542K Mar 26 16:50 _cffi_backend.cpython-37m-i386-linux-gnu.so
drwxr-xr-x  5 pi pi 4.0K Mar 26 17:47 nacl
drwxr-xr-x  3 pi pi 4.0K Mar 26 17:47 paramiko
drwxr-xr-x  2 pi pi 4.0K Mar 26 17:47 paramiko-2.10.3.dist-info
drwxr-xr-x  4 pi pi 4.0K Mar 26 17:47 pycparser
drwxr-xr-x  2 pi pi 4.0K Mar 26 17:47 pycparser-2.21.dist-info
drwxr-xr-x  2 pi pi 4.0K Mar 26 17:47 PyNaCl-1.5.0.dist-info
pi@deb:~/.local/lib $ ls -lah ./python3.9/site-packages
total 84K
drwx------ 12 pi pi 4.0K Apr 13 10:07 .
drwxr-xr-x  3 pi pi 4.0K Mar 25 16:28 ..
drwxr-xr-x  6 pi pi 4.0K Apr 13 10:07 dateutil
drwxr-xr-x  5 pi pi 4.0K Mar 25 16:28 pip
drwxr-xr-x  2 pi pi 4.0K Mar 25 16:28 pip-22.0.4.dist-info
drwxr-xr-x  2 pi pi 4.0K Apr 13 10:07 __pycache__
drwxr-xr-x  2 pi pi 4.0K Apr 13 10:07 python_dateutil-2.8.2.dist-info
drwxr-xr-x  2 pi pi 4.0K Apr 13 10:07 six-1.16.0.dist-info
-rw-r--r--  1 pi pi  34K Apr 13 10:07 six.py
drwxr-xr-x  3 pi pi 4.0K Apr 13 10:07 suntime
drwxr-xr-x  2 pi pi 4.0K Apr 13 10:07 suntime-1.2.5.dist-info
drwxr-xr-x  4 pi pi 4.0K Mar 25 17:22 tk
drwxr-xr-x  2 pi pi 4.0K Mar 25 17:22 tk-0.1.0.dist-info

'suntime' was the PIP package I installed and could not access until I manually compiled through Python 3.9.2

Looking at PIP, I seem to have a larger mess. Here are results of running different PIPS with and without SUDO

pi@deb:~ $ pip -V
pip 22.0.4 from /home/pi/.local/lib/python3.9/site-packages/pip (python 3.9)

pi@deb:~ $ pip2 -V
pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7)

pi@deb:~ $ pip3 -V
pip 22.0.4 from /home/pi/.local/lib/python3.9/site-packages/pip (python 3.9)

pi@deb:~ $ sudo pip -V
pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7)

pi@deb:~ $ sudo pip2 -V
pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7)

pi@deb:~ $ sudo pip3 -V
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7
Reply
#2
(Apr-16-2022, 02:45 PM)DS256 Wrote: pi@deb:~ $ pip -V
pip 22.0.4 from /home/pi/.local/lib/python3.9/site-packages/pip (python 3.9)
This is correct.
Test python -V and python3 -V if one of them point to Python 3.9 then all is ok.
If not alias or update-alternatives, link1, link2 so test of version over Point to Python 3.9.
With Thonny you can set whatever interpreter you want tool-->option-->interpreter and choose Python 3.9.
Quote:so I have consistent environments between the two systems?
Virtual environment is build into Python and easy to use,example in Thread
pyenv also work for link, How to Setup Raspberry Pi OS:.
Reply
#3
Thanks @snippsat. Some useful links there. That I can make use of.

I still get confused as to when to use PIP, SUDO PIP and APT-GET.

I'm not as interested in virtual environments as just getting things cleaned up.

I found this link which allowed me to manually delete the Debian 3.9.2 which was not recognized. I think I must have manually used MAKE.

So now I have Python 2.7 and 3.7 on the Debian and only one version of PIP.

Here's the script I created to remove Python 3.9.2.

Output:
#!/bin/bash # Manual Remove version of Python # This was written because none of the standard ways could # find a python3.9 package # Not sure if PIP packages for the removed PIP{pyver} need to be # removed first. #https://unix.stackexchange.com/questions/190794/uninstall-python-installed-by-compiling-source prefix='/usr/local/' pyver='3.9' # Some of the files or directories may not exist rm -rvf \ $HOME/.local/lib/python${pyver} \ $HOME/.local/bin/pip${pyver} \ ${prefix}bin/python${pyver} \ ${prefix}bin/python${pyver}-config \ ${prefix}bin/pip${pyver} \ ${prefix}bin/pydoc${pyver} \ ${prefix}bin/include/python${pyver} \ ${prefix}lib/libpython${pyver}.a \ ${prefix}lib/python${pyver} \ ${prefix}bin/python${pyver} \ ${prefix}bin/pip${pyver} \ ${prefix}bin/include/python${pyver} \ ${prefix}lib/libpython${pyver}.a \ ${prefix}lib/python${pyver} \ ${prefix}lib/pkgconfig/python-${pyver}.pc \ ${prefix}lib/libpython${pyver}m.a \ ${prefix}bin/python${pyver}m \ ${prefix}bin/2to3-${pyver} \ ${prefix}bin/python${pyver}m-config \ ${prefix}bin/idle${pyver} \ ${prefix}bin/pydoc${pyver} \ ${prefix}bin/pyvenv-${pyver} \ ${prefix}share/man/man1/python${pyver}.1 \ ${prefix}include/python${pyver}m echo -e "\n Manually clean up symbolic links for python and pip" echo -e "\n Reboot necesssary"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am using Thonny and the help file is not very helpful. yeto 0 1,449 Jul-13-2019, 03:04 PM
Last Post: yeto
  thonny and esp32/8266 on raspberry usb niala38 0 2,045 Mar-31-2019, 05:25 PM
Last Post: niala38
  Thonny IDE 2.0 snippsat 9 10,297 Oct-21-2017, 08:25 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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