# Installing Python2

**URL:** <https://forum.openwrt.org/t/installing-python2/135375>\
**Category:** Installing and Using OpenWrt\
**Created:** [August 24, 2022, 4:51pm UTC](https://forum.openwrt.org/t/installing-python2/135375 "2022-08-24T16:51:12Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 4:51pm UTC](https://forum.openwrt.org/t/installing-python2/135375/1 "2022-08-24T16:51:13Z")

</div>

Greetings. I have a script that i usually run on my devices with "python2 script.py". However, executing this script with python3 gives errors.  
I installed openwrt on one of my devices and have been trying to install python2 but to no avail (i got python3 to install).  
Question: How can i get python2 installed on my openwrt device so that i can execute my python script?

---

<div class="post-metadata">

**Author:** ![psherman](https://forum.openwrt.org/letter_avatar/psherman/32/6_449c533f586939b6e5f246632a46421f.png) [@psherman](https://forum.openwrt.org/u/psherman)\
**Post date:** [August 24, 2022, 5:00pm UTC](https://forum.openwrt.org/t/installing-python2/135375/2 "2022-08-24T17:00:21Z")

</div>

Python 2 has been completely deprecated and is actually not (easily) available on many platforms now. I'd recommend working to resolve the errors in your script. Many of the errors can be resolved fairly easily by adjusting the syntax and/or importing some modules.

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 5:05pm UTC](https://forum.openwrt.org/t/installing-python2/135375/3 "2022-08-24T17:05:10Z")

</div>

Thanks for your reply. So there isn't any "community" repository or way i can get python2 installed ☹ ?

Im not versed in programming so fixing the errors may be difficult. someone on a chat got the script to execute for me on python3 but one part of it doesn't work as it should and he said he will be unable to assist further with the issue i am getting. so i am stumped there

---

<div class="post-metadata">

**Author:** ![psherman](https://forum.openwrt.org/letter_avatar/psherman/32/6_449c533f586939b6e5f246632a46421f.png) [@psherman](https://forum.openwrt.org/u/psherman)\
**Post date:** [August 24, 2022, 5:11pm UTC](https://forum.openwrt.org/t/installing-python2/135375/4 "2022-08-24T17:11:27Z")

</div>

I don't know about python2 on OpenWrt, but yeah, it's likely to be pretty tricky. You could theoretically compile it yourself.

Regarding fixing python 3 script issue, searching the web (especially stackexchange) is a great way to figure it out.... or, post questions on python related sites (including stackexchange).

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 5:19pm UTC](https://forum.openwrt.org/t/installing-python2/135375/5 "2022-08-24T17:19:59Z")

</div>

ok ill see if i can find a way to compile python2.  
thanks for the assistance thus far!

hopefully someone can help with my issue.

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 5:26pm UTC](https://forum.openwrt.org/t/installing-python2/135375/6 "2022-08-24T17:26:07Z")

</div>

[https://downloads.openwrt.org/releases/packages-18.06/aarch64\_generic/packages/](https://downloads.openwrt.org/releases/packages-18.06/aarch64_generic/packages/)

i am seeing the package here. "python-light" shows python2 but how can i get it installed along with dependencies? I put the URL in the opkg config file but i get error "pkg\_hash\_fetch\_best\_installation\_candidate: Packages for python-light found, but incompatible with the architectures configured"

sorry for the questions but im new to openwrt

---

<div class="post-metadata">

**Author:** ![sebastian\_de](https://forum.openwrt.org/letter_avatar/sebastian_de/32/6_449c533f586939b6e5f246632a46421f.png) [@sebastian\_de](https://forum.openwrt.org/u/sebastian_de)\
**Post date:** [August 24, 2022, 5:46pm UTC](https://forum.openwrt.org/t/installing-python2/135375/7 "2022-08-24T17:46:21Z")

</div>

You could try [automated translation](https://docs.python.org/3/library/2to3.html) - for simple scripts that's often enough.

Seriously - don't waste your time to get an EOL programming language running.  
The package repository you linked to is of an OpenWrt version that's also EOL...

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 5:53pm UTC](https://forum.openwrt.org/t/installing-python2/135375/8 "2022-08-24T17:53:42Z")

</div>

ah ok. im gonna try the link you sent. thanks

edit: thats 2to3 which i tried already but it doesnt work. the script spits out some errors when i run the new versions that 2to3 produces

---

<div class="post-metadata">

**Author:** ![psherman](https://forum.openwrt.org/letter_avatar/psherman/32/6_449c533f586939b6e5f246632a46421f.png) [@psherman](https://forum.openwrt.org/u/psherman)\
**Post date:** [August 24, 2022, 5:54pm UTC](https://forum.openwrt.org/t/installing-python2/135375/9 "2022-08-24T17:54:16Z")

</div>

What version of OpenWrt are you using and on what platform? I agree that it is not worth trying to spend any time on getting python 2 working.

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 5:57pm UTC](https://forum.openwrt.org/t/installing-python2/135375/10 "2022-08-24T17:57:06Z")

</div>

> **[GitHub - ophub/amlogic-s9xxx-openwrt: OpenWrt for Amlogic s9xxx tv box....](https://github.com/ophub/amlogic-s9xxx-openwrt)**
>
> OpenWrt for Amlogic s9xxx tv box. Support a311d, s922x, s905x3, s905x2, s912, s905d, s905x, s905w, s905, etc. including install to EMMC and update related functions. - GitHub - ophub/amlogic-s9xxx-...

this is what im using. i have an android box that i was going to put to use to act as a server. the last part i need working is the script lol

---

<div class="post-metadata">

**Author:** ![psherman](https://forum.openwrt.org/letter_avatar/psherman/32/6_449c533f586939b6e5f246632a46421f.png) [@psherman](https://forum.openwrt.org/u/psherman)\
**Post date:** [August 24, 2022, 6:10pm UTC](https://forum.openwrt.org/t/installing-python2/135375/11 "2022-08-24T18:10:28Z")

</div>

Oh. And by the looks of it, you’re probably using some custom fork of OpenWrt and not the official version. You might ask the vendor/maintainer for help. But it is still not worth investing time in py2

---

<div class="post-metadata">

**Author:** ![ipha](https://forum.openwrt.org/letter_avatar/ipha/32/6_449c533f586939b6e5f246632a46421f.png) [@ipha](https://forum.openwrt.org/u/ipha)\
**Post date:** [August 24, 2022, 6:10pm UTC](https://forum.openwrt.org/t/installing-python2/135375/12 "2022-08-24T18:10:44Z")

</div>

Lets take a step back -- what are you trying to run and why does it need python2?

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 6:12pm UTC](https://forum.openwrt.org/t/installing-python2/135375/13 "2022-08-24T18:12:55Z")

</div>

sigh ☹ ok. you've been a great help. thanks again

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 6:14pm UTC](https://forum.openwrt.org/t/installing-python2/135375/14 "2022-08-24T18:14:52Z")

</div>

> **[Original - Pastebin.com](https://pastebin.com/nGFm4trR)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

this is the code. when i use python3 i get error. i tried to convert with 2to3 and the script executes but not as it should. so i just wanted to use python2 again because i know it works

---

<div class="post-metadata">

**Author:** ![hnyman](https://forum.openwrt.org/user_avatar/forum.openwrt.org/hnyman/32/19_2.png) [@hnyman](https://forum.openwrt.org/u/hnyman)\
**Post date:** [August 24, 2022, 6:26pm UTC](https://forum.openwrt.org/t/installing-python2/135375/15 "2022-08-24T18:26:30Z")

</div>

> [@deyloTT](#):
>
> his is the code. when i use python3 i get error.

Looking at the code, (and running it through [https://python2to3.com/](https://python2to3.com/) converter), I think that you just need to change all print statements to print functions by adding ( ) to 10 lines.  
In style of

```plaintext
    print "\n:-------PythonProxy-------:\n"
    print "Listening addr: " + LISTENING_ADDR

```

to

```plaintext
    print("\n:-------PythonProxy-------:\n")
    print("Listening addr: " + LISTENING_ADDR)

```

And apparently also "thread" on the first line needs to be "\_thread":  
`import socket, threading, _thread, select, signal, sys, time, getopt`

---

<div class="post-metadata">

**Author:** ![ipha](https://forum.openwrt.org/letter_avatar/ipha/32/6_449c533f586939b6e5f246632a46421f.png) [@ipha](https://forum.openwrt.org/u/ipha)\
**Post date:** [August 24, 2022, 6:31pm UTC](https://forum.openwrt.org/t/installing-python2/135375/16 "2022-08-24T18:31:30Z")

</div>

It looks like a simple http proxy server, why not use one of the supported ones instead? [https://openwrt.org/docs/guide-user/services/proxy/start](https://openwrt.org/docs/guide-user/services/proxy/start)

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 6:38pm UTC](https://forum.openwrt.org/t/installing-python2/135375/17 "2022-08-24T18:38:08Z")

</div>

thanks much. will look into it!

---

<div class="post-metadata">

**Author:** ![deyloTT](https://forum.openwrt.org/user_avatar/forum.openwrt.org/deylott/32/58980_2.png) [@deyloTT](https://forum.openwrt.org/u/deyloTT)\
**Post date:** [August 24, 2022, 6:38pm UTC](https://forum.openwrt.org/t/installing-python2/135375/18 "2022-08-24T18:38:50Z")

</div>

im reading up on it now. you all have been a great help and im grateful. will report back when the issue is fixed!

again to everyone...thanks
