Python Forum
Python version 3 that seems to be ignored by the system on a Raspberry Pi
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python version 3 that seems to be ignored by the system on a Raspberry Pi
#1
Hello everyone

I am writing to you from France. My english is really basic Smile

I recently bought a Raspberry Pi 3 model B. I am under Rasbian version 9, updated today.
I installed python3 in addition to the original python2. A python3 command via the console confirms me a version 3.5.3.
In the various programs that I just wrote in python, I start with the shebang "#! / Usr / bin / env python3" which launches the use of version 3 of python.
I realized at launch of my programs that the syntaxes corresponding to python 3 generate errors.

For example, when I call tkinter with the syntax python 3 "import tkinter", I get the following error message "import tkinter ImportError: No module named tkinter"

When I use the python 2 syntax "import Tkinter", everything happens normally.

If in a program in python, after the shebang python 3, I run the command "sys.version_info [0]", I get the value 2 while I should have the value 3.

As a first approach, I would say that python 3 is as ignored, or not recognized by the system.

I looked in the directory / usr / bin and I found the different files related to python 3 and 3.5 (python3, python3-config, python3m, python3m-config, python3.5, python3.5-config, python3.5m, python3.5m-config).

Being still very new to this structure, I do not know which syntax to use for the Unix command to use. I did some tests with different syntaxes (eg #! / Usr / bin / env python3, #! / Usr / bin / env python3.5) plus the same with the prefix "env" (#! / Usr / bin / env python3, #! / usr / bin / env python3.5), but to no avail.

I told myself that tkinter was not installed on my RPI. I launched the command "sudo apt-get install python3-tk" but I have a message that tells me that tkinter is already installed!

Would anyone have advice to me to understand what is happening in order to effectively use python 3 on my RPI?

Many thanks to you
JP
Reply
#2
There should be no space characters in /usr/bin/env. Try with
#!/usr/bin/env python3
It needs to be the first line of the file. You can also try #!/usr/bin/python3
Reply
#3
Hi Gribouillis

It's google translate that added the spaces during the translation for this message. In reality, there is no space and this syntax does not work.

JP
Reply
#4
From what I read here, the error could be that your file has Windows line endings. You can install the dos2unix command to convert it to Unix/Linux line endings and retry.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  run part of a script with a different version of Python jdog 2 392 Jan-09-2024, 08:49 PM
Last Post: jdog
  How to find out from outside Python (in Windows) the current version of Python? pstein 4 679 Oct-04-2023, 10:01 AM
Last Post: snippsat
  How to resolve version conflicts in Python? taeefnajib 0 873 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,179 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Python venv and PIP version issue JanOlvegg 2 1,199 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Python Version upgrade nitinkukreja 1 852 Feb-04-2023, 10:27 PM
Last Post: Larz60+
  Can't update new python version on Pycharm GOKUUUU 6 3,700 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  Building python (3.9.5) with different libexpat version (2.4.6) raghupcr 0 1,257 Feb-25-2022, 11:29 AM
Last Post: raghupcr
  Python keeps running the old version of the code quest 2 3,645 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  Coding for Python and Raspberry pi beast 3 39,268 Sep-21-2021, 09:56 PM
Last Post: beast

Forum Jump:

User Panel Messages

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