Creating Python Apps Using My Android Phone Because I Am Desperate To Program

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@sidkay588·
0.000 HBD
Creating Python Apps Using My Android Phone Because I Am Desperate To Program
<center>***...who needs computers to program anyway, am I right?***</center>

<center>
![](https://images.ecency.com/DQmSptYm3mX1gTeso8fGRq5aS1ffutLH4zusaRXDxuofag4/img_0.0212117557607222.jpg)
</center>

<center><sup>[Image Source](https://hackmag.com/mobile/transforming-android-tablet-into-a-coding-machine/)</sup></center>

___

Hello once again, fellow programmers! It surely has been a while since I last programmed anything.

Remember how I said that I got a laptop from my brother some time ago? And how I mentioned that it was a bit slow to use since it was a laptop with 2 gigabytes of RAM and an Intel Celeron processor?

Yeah, it turns out that my patience was not able to keep up with using it since it lagged for basically everything. And its screen decided to die on top of that. I found out that the screen's backlight got damaged and I have no idea how because this issue came out of the blue.

So much for being a game changer...

Well it was expected to happen since it was an old laptop. Besides, it was already giving some signs that it wouldn't last much longer.

But fortunately, the programming spirit within me refused to die even after that happened.

I was able to find out that there is a way to continue programming, through my android phone.

If you are a fellow Python developer or looking to become one but have nothing but an android phone, you're in luck because I will be sharing how I managed to do this.

Frankly, I was a bit shocked to find out that such a thing is even possible to do on android given how tedious the task of programming can get.

___

For the first step, we are going to be installing an app called Pydroid 3.

<center>
![](https://images.ecency.com/DQmUFLTa41ESWDLHQUEZFL8hPBpKmnQHVWhrQWpFZa2jfbd/img_0.0019410439227223026.jpg)
</center>

This is an IDE that allows you to write Python code in android. It comes with all the essentials that you'll need to write Python code - an interpreter, a command line, a pre-packaged version of Python and of course the ability to edit code.

It even comes with additional modules like Tkinter for building GUIs, Pygame for game development in Python, and other modules that I don't know the use of.

<center>
![](https://images.ecency.com/DQmNk7ysXvtDoKcDqoc5nHcxAvCwsLYPQM6ujpkDCgbJF5j/img_0.0676403997944142.jpg)
</center>

<center>
![](https://images.ecency.com/DQmf273eSoBSD5Y8jkY3fMwr6KPuAzqPzRFombhAhL8z1Jc/img_0.9572904523880622.jpg)
</center>

Normally, I would say that the tutorial ends here. But using this apps alone has a few setbacks.

- First up, it will not be possible to create virtual environments. When I tried it, I noticed that the Android operating system wouldn't even let me try that.

<center>
![](https://images.ecency.com/DQmZUFoH4Wsfo9WUuuF2nasjoDBZZJNrtCzmZcFPuGiurVC/img_0.278750060703078.jpg)
</center>

I am a person that likes to create a virtual environment anytime I work on a new project since it allows me to use separate packages depending on the project I'm working on.

- Because it isn't possible to create virtual environments, creating projects using a framework like Django may be difficult.

- I am aware that I said that the app has a command line interface. Unfortunately, this one does not allow you to do any other thing on it besides installing Python packages and running Python programs.

<center>
![](https://images.ecency.com/DQmf75vps7yxLRKQ18mJnpLEezVawowW5TCgqfbWxSJQhof/img_0.912425294094689.jpg)
</center>

So if you were looking forward to using Git to push code to a version control website, this app will not let you.

At least using **only** this app won't let you do those things.

Now this is where we install another app to help sort out those issues.

___

The next step is to install an app called Termux.

This app serves more like a Linux terminal for Android. And it is pretty much able to run commands on a phone just as you would run them on a Linux based PC.

<center>
![](https://images.ecency.com/DQmRvoVtzNXZwfYdeKEHMmPiHPbssLk8gPHEy6Bv64N4Geh/img_0.7524088130311036.jpg)
</center>

Before you head off to download it, this app is not on the play store. At least a downloadable version is not on the Play Store.

It says that the app is too old for your device, which is not the case at all.

<center>
![](https://images.ecency.com/DQmXA6uGQ7aXRyQgSUzqhQgECD8ApkS9uUyuFz4kENvABvx/img_0.25829765736307086.jpg)
</center>

A working version can be found on its official GitHub repository [here](https://github.com/termux/termux-app/releases).

Once you are done downloading and installing the app, you can open it up.

Once you start up the app, you will have to run the commands:

```
pkg update
```

```
pkg upgrade
```

...to install updates and other necessary files onto the terminal.

The next thing to do is to run:
 
```
termux-setup-storage
```

This command sets up a directory where termux can run freely because Android will still deny the app from working directly on your phone's storage.

Now we can now install Python and Git using:

```
apt install python && apt install git
```

This will install the Python interpreter and the Git command line into Termux.

<center>
![](https://images.ecency.com/DQmYvT1Muxm5uFKLSUW7X1J38GxTY73D8L2iytNAq8NubCr/img_0.16353691795340178.jpg)
</center>

<center>
![](https://images.ecency.com/DQmVtvq6rg4ppLhBpJ91GAFUsdfrdUKwX8kXKpE73qmA7Tu/img_0.7125980853700389.jpg)
</center>

Now you can install the Python packages that you want to use into Python on termux. For instance, if you want to install the package for virtual environments, virtualenv, you can run `pip install virtualenv` and it will install the package.

Once it is done, you can then create a virtual environment if you want.

Before that, I would recommend changing the current working directory and avoid working directly in the root directory. We can do this by using the command:

```
cd storage
```

<center>
![](https://images.ecency.com/DQmVZ5vRahLNdrkiwi4BVmXAoUeyQuvBxokzqs64uToZWvB/img_0.7109156349596859.jpg)
</center>

And then make a new folder called "Python apps" for instance.

```
mkdir "Python apps"
```

<center>
![](https://images.ecency.com/DQmXUQyH893UbHDKSHRrykNqEMUVSuQAQ13CpEw3yTdYSzD/img_0.630633231885429.jpg)
</center>

If you run `ls`, you'll see all the files that are currently within that directory.

But you probably may have gone to the file explorer on your phone and noticed that the created files aren't there. Or the files listed from running the `ls` command are different from what is normally on your phone's storage. What happened then?

As I said earlier, Android denies the permission to perform certain operations that you would want to do when programming on Pydroid like installing programs that are not Python packages.

Everything that was done until now is on some sort of virtual directory within the Termux app where those restrictions don't apply.

If we go to Pydroid again, select the option to open a file, and then pick "Storage Access Framework", we will see all of our created files on there.

<center>
![](https://images.ecency.com/DQmaa4ShhgCGCgg7SDy5MbXpC3h6f4dijhRNLHmxUqEwpBh/img_0.9293626627184356.jpg)
</center>

<center>
![](https://images.ecency.com/DQmTcvRWJ6cKJPwcrfEbZfgupbTzk9ZwDu3zXYbY4TqhECQ/img_0.25761357749123526.jpg)
</center>

<center>
![](https://images.ecency.com/DQmYN5yqK2abqXgcEecNXpLBt8HiN6aeY1JmKB2MUp7TVhk/img_0.969306433932967.jpg)
</center>

<center>
![](https://images.ecency.com/DQmQLKtBnSnC1J5Vit8A6SF437WumeVNhRAxzmewQ1BXNiP/img_0.6075012066347673.jpg)
</center>

And now everything is now set up.

## An example

So now, I will be creating a new Django app using this.

First, I'll create a directory that will contain the virtual environment and the Django application.

```
mkdir test
```

<center>
![](https://images.ecency.com/DQmeE1TFd1iGoBGtR1QizfBz1HPrWmd9LQkYeGFRugqT2T3/img_0.2725719358080142.jpg)
</center>

After that, I'll create a virtual environment in the new "test" directory with the command:

```
python -m venv env
```

<center>
![](https://images.ecency.com/DQmZnfHAsKH2qKvyP8CM3G9PGmUs7yWaoUEwzvmWpRuFXq3/img_0.9758519827699131.jpg)
</center>

Then I'll activate the environment using:

```
source env/bin/activate
```

<center>
![](https://images.ecency.com/DQmVhZRKt7mWiJba9v1CU83HBdsD36nbsvXvbmdEvuwn6AJ/img_0.5643639469272279.jpg)
</center>

Now I can install Django onto the environment:

```
pip install django
```

<center>
![](https://images.ecency.com/DQmV3jZb8DoZJaS5p5G7RTiD4c9Q8yzzk7aLhNfvGkxhfuC/img_0.924501510310902.jpg)
</center>

Next is to create a new Django project

```
django-admin startproject sampleproject
```

<center>
![](https://images.ecency.com/DQmQZnjcHLxJJGzjWwxDVXev3simM7QjNW5wPzzPFohyMm5/img_0.9669796352061185.jpg)
</center>

Then change the CWD to the newly created project and run the command to start the project.

```
cd sampleproject
```

```
python manage.py runserver
```

Then you will probably see a message with a local host web address. You can then copy it and open it in your browser.

<center>
![](https://images.ecency.com/DQmQEasJpTCp55nanxZzKTWJBAsPprdwbHXJqj6H2NxtGrS/img_0.8708249656514503.jpg)
</center>

And... It works!

<center>
![](https://images.ecency.com/DQmX95pyx12w2CnW2yDj37mp39dV59egF1Diz88qUDbZS5s/img_0.2053425455237726.jpg)
</center>

___

## But Unfortunately...

I am not going to lie, while this has made it possible for me to code without the need for a laptop and pretty much anywhere at this point, it may be a bit cumbersome to go use at times.

First off, if you are coming from the easy life of coding on an IDE like VSCode, this one will be a bit problematic to use.

There is no option to auto complete code that you're typing, so that means you'll have to type out a lot of things. Or pray that you are typing the correct syntax.

The IDE layout is not so great. You know how IDEs have this colour layout thing where different structures have different colours to distinguish them from each other makes your code easier to read? It's not so common in this one.

Reading code on this app can be difficult at times since its not so easy to know what is what. The only things that have a form of differentiation are the special keywords reserved for Python (like 'def', 'class', 'for', etc.), comments and strings. That's it.

So reading code at times can be a pain.

But hey, at least the app has a quick access tray for the punctuation marks that will be used a lot in coding, and also automatic indentation.

<center>
![](https://images.ecency.com/DQmZVA5vMMQwifEBmRP7Y2GosjxjRPr5FNK1xfpX8gi3vwH/img_0.8157539739695493.jpg)
</center>

This next issue depends on the specifications of your mobile phone.

If you are using a low end smartphone, like myself, you may struggle with having to deal with multiple open applications. 

It can be a bit stressful sometimes having to cycle between my browser, IDE and the terminal. And a lot of times, when I minimize one app, it takes time for everything to reopen again. Sometimes, the app may even restart like I'm opening an application that was closed.

Luckily this issue doesn't affect Termux. It keeps running even in the background until I properly stop the terminal process.

Oh, and a friendly tip I have is to turn off code wrapping in Pydroid's settings, unless you don't like having to swipe across the screen to read long lines of code. This is because code wrapping kind of squashes the code to fit into the screen and may make it harder to understand.

___

This method of programming is neither the best nor convenient to use. It has also slowed down my programming speed since I type much faster on a physical keyboard. But I can't really complain if this is the only way that can work for me now.

I really hope that this was also able to help out anyone else that is facing a similar scenario that I am.

<center>With that being said, thanks a lot for reading and see you next time :D</center>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,