Python Forum
converting python script to another version
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
converting python script to another version
#1
Hi everyone,

I saw a project using raspberry pi using python ver 3.4 and the flask framework. My raspberry pi has the Python 2.7, 3.5 and 3.6 Python versions. I have tried running the script but I always getting a bunch of errors. I have tried so many solutions that I have seen in the web and have ask for help in several forums but no luck Wall . I have given up on addressing the error but if you want to know what I am facing, here is the link

https://raspberrypi.stackexchange.com/qu...6909_80181

What I am thinking is maybe I can convert the scripts (just two files) to the latest version of Python? rather than fixing my Python environment which I have been doing for the last 24 hours. Think. I am new to Python and I want to learn the language plus the flask framework. May I know some tips before I try converting these files to the latest version and is this possible? Thanks in advance!
Reply
#2
When you do sudo python web_plantes.py.
python is most likely pointing to python 2,try python3.
I use pyenv then both python and pip is pointing to 3.6.4.
But can easily go back default distro setting.
mint@mint ~ $ python -V
Python 3.6.4

# Go back to default distro setting
mint@mint ~ $ pyenv local system
mint@mint ~ $ python -V
Python 2.7.12
mint@mint ~ $ python3 -V
Python 3.5.2
mint@mint ~ $ pip3 -V
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)

# install to python 3.5
mint@mint ~ $ pip3 install --user psutil
Collecting psutil
  Using cached psutil-5.4.3.tar.gz
Installing collected packages: psutil
  Running setup.py install for psutil ... done
Successfully installed psutil-5.4.3

# Test that module work in 3.5
mint@mint ~ $ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.__version__
'5.4.3'
>>> 
So you see on the default distro setting i most use python3.
Tutorial Linux Python 3 environment
Reply
#3
@snippsat, thank you so for the help the psutil error I was getting is gone
[Image: jr98k3]

but this time it is throwing this error. See below.
[Image: FFbQbf]

Thanks again.
Reply
#4
Do not post picture when you can use code tag.
You should also have posted a link to script that you try to run.
Raspberry Pi Automated Plant Watering with Website

Error:
error 98 address already in use
There is another process already listening on that port,try and other port.
app.run(host='0.0.0.0', port=8000, debug=True)

# Or,now run on this address in browser http://localhost:5000/
app.run(debug=True)
Reply
#5
Thank you for the help, will post the results later. :-)
Reply
#6
Hi guys,

@snippsat, Thank you for the last solution that you gave it worked now! Your the man!
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
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,001 Jun-29-2023, 11:57 AM
Last Post: gologica
  How to resolve version conflicts in Python? taeefnajib 0 873 Apr-27-2023, 08:37 PM
Last Post: taeefnajib
  Python venv and PIP version issue JanOlvegg 2 1,199 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Python Version upgrade nitinkukreja 1 851 Feb-04-2023, 10:27 PM
Last Post: Larz60+
  Converting python to FileMaker DWolf 6 1,600 Sep-22-2022, 03:40 AM
Last Post: DWolf
  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,644 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

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