olio
Posts: 33
Joined: Tue Feb 02, 2016 8:55 am

Python 3.5 and 3.4 tkinter issue

Fri Feb 22, 2019 10:01 am

Hello,
I have an encrypted python script (compiled from the LabVIEW compiler), that runs only on python 3.4 with a special package (pyVI) for the compiled and encrypted python script (not very open source btw.).

Now I try to get it running on a new Raspberry Pi3B+ with Raspbian Stretch. On Stretch there is python 3.5 installed. I tried to install the required packages for the encrypted script, but failed because they are configured for 3.4 (magic number error!)

Next step, I installed python 3.4 and the required packages and run my script under python 3.4.
Now I get the error message: "no module named '_tkinter', please install the python3-tk package"

But as I can see in the folder: /usr/lib/python3.4/tkinter it seems to be installed.
If I import tkinter in python3.5, there is no error
If I import it in python3.4 then the error occurs again.
Is there a possibility to bundle tkinter to python 3.4?
Removing of python 3.5 results in a login loop ;-(

The least solution would be to come back to a Raspberry Pi 3B with Jessie and python 3.4

Maybe the community has some suggestions?

Thanks in advance and greetings!
Oliver

User avatar
MrYsLab
Posts: 376
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Python 3.5 and 3.4 tkinter issue

Sun Feb 24, 2019 12:17 am

To see where python is searching for modules, open a terminal and type:

Code: Select all

python3 -c "import sys; print('\n'.join(sys.path))"
For a specific version of python:

Code: Select all

python3 .5 -c "import sys; print('\n'.join(sys.path))"
or

Code: Select all

python3.4 -c "import sys; print('\n'.join(sys.path))"
You can affect the path by setting the PYTHONPATH environment variable.

olio
Posts: 33
Joined: Tue Feb 02, 2016 8:55 am

Re: Python 3.5 and 3.4 tkinter issue

Mon Feb 25, 2019 8:03 am

Hello,
thanks for this information. If I do the search for Python 3 it goes into the default 3.5 directory.

Code: Select all

python3 -c "import sys; print('\n'.join(sys.path))"
which gives me these lines:

|usr/lib/python35.zip
/usr/lib/python3.5
/usr/lib/python3.5/plat-arm-linux-gnueabihf
/usr/lib/python3.5/lib-dynload
/usr/local/lib/python3.5/dist-packages
/usr/lib/python3/dist-packages

If I look for the specific 3.4 version

Code: Select all

python3.4 -c "import sys; print('\n'.join(sys.path))"
then the result is:
/usr/lib/python3.4
/usr/lib/python3.4/plat-arm-linux-gnueabihf
/usr/lib/python3.4/lib-dynload
/home/pi/.local/lib/python3.4/site-packages
/usr/local/lib/python3.4/dist-packages
/usr/lib/python3/dist-packages

which seems to be correct, because a tkinter package is also located in the python3.4/dist-packages directory. However if I start Python 3.4 and import tkinter, then I get the error message. I try to find out how to set the Pythonpath (after back-up)...but I guess that the cause for the issue is somewhere else.

Code: Select all

~ $ python3.4
Python 3.4.4 (default, Apr 17 2016, 16:02:33) 
[GCC 5.3.1 20160409] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
  File "/usr/lib/python3.4/tkinter/__init__.py", line 39, in <module>
    import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/tkinter/__init__.py", line 41, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
>>> 
the same error occurs, when I run the __init__.py directly in its directory with:

Code: Select all

/usr/lib/python3.4/tkinter $ python3.4 ./__init__.py
Traceback (most recent call last):
  File "./__init__.py", line 39, in <module>
    import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./__init__.py", line 41, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
instead, if I do the same with

Code: Select all

/usr/lib/python3.4/tkinter $ python3.5 ./__init__.py
then the little test window pops up and no error occurs. Therefore my guess would be, that python3.4 routes to the correct package directory, but the tkinter package version which is installed in the 3.4 lib directory is a 3.5 package version.

Maybe I should copy an old tkinter package from another Raspberry Pi with only python 3.4 installed.

I'll try this first.
Greetings and have a good start into the new week!
Oliver

olio
Posts: 33
Joined: Tue Feb 02, 2016 8:55 am

Re: Python 3.5 and 3.4 tkinter issue

Mon Feb 25, 2019 9:07 am

OK...copying an original tkinter 3.4 package doesn't work.

olio
Posts: 33
Joined: Tue Feb 02, 2016 8:55 am

Re: Python 3.5 and 3.4 tkinter issue

Mon Feb 25, 2019 9:13 am

I tried to import other packages than tkinter into python3.4, that I can find in the directory
/usr/lib/python3.4

...no error if I do this

User avatar
MrYsLab
Posts: 376
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Python 3.5 and 3.4 tkinter issue

Mon Feb 25, 2019 1:50 pm

I should have asked this before - how exactly did you install 3.4?
I just installed 3.4 on my Pi using the instructions here: https://mryslab.github.io/pymata-expres ... 7.install/ - just scroll down the page and look for "Linux Users". For steps 11, 12 and 13 substitute 3.4.9 for 3.7.2.

After building, I typed python3 and the default is still 3.5.3. It I then type python3.4, I get a python3.4 repl and if I type import tkinter - no errors.

I would suggest working in a virtual environment for your 3.4 work. You can learn about that here: https://realpython.com/python-virtual-e ... -a-primer/

olio
Posts: 33
Joined: Tue Feb 02, 2016 8:55 am

Re: Python 3.5 and 3.4 tkinter issue

Mon Feb 25, 2019 3:17 pm

Hello MrYsLab,

thanks for your information. As I'm not a informatician but a user who adapt existing codes or use graphical tools like LabVIEW it's not so obvious for me, if applications aren't set the way I can use them directly...however I can learn ;-)

I will take a look to the virtual environment, but probably changing the hardware will bring a working solution a bit faster...

I installed python 3.4 with

Code: Select all

sudo apt-get install python3.4

Return to “Python”