Python Forum

Full Version: Python version 3 that seems to be ignored by the system on a Raspberry Pi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
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
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.