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

...who needs computers to program anyway, am I right?



Image Source


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.



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.





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.



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.



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.



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.



A working version can be found on its official GitHub repository here.

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.





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



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

mkdir "Python apps"



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.









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



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

python -m venv env



Then I'll activate the environment using:

source env/bin/activate



Now I can install Django onto the environment:

pip install django



Next is to create a new Django project

django-admin startproject sampleproject



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.



And... It works!




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.



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.

With that being said, thanks a lot for reading and see you next time :D



0
0
0.000
9 comments
avatar

The Replit app offers syntax highlighting and more. But it is kind of slow, on my phone at least. Also it cannot be used offline.

0
0
0.000
avatar
(Edited)

Oh, I had never heard of that IDE before. But I will definitely try it out to see how it works.

0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000
avatar

Congratulations @sidkay588! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 4750 upvotes.
Your next target is to reach 5000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

0
0
0.000
avatar

Technically, a phone is also a computer, albeit a not so powerful one and that's why you can still code with it. I actually started doing web development with my phone a couple of years ago and it was easy for me but just like you said, after using an IDE, it's now very difficult to use my phone to code, mostly because of the flexibility that comes with using an IDE. Termux is a very good terminal for android, it works even better if your phone is rooted

0
0
0.000
avatar

Well fair point. I actually forgot that a phone is basically a mobile computer. 😅

I also heard that Termux works better when your phone is rooted, but honestly I'm scared of doing that lol.

0
0
0.000
avatar

I agree, it's very risky to root phones these days and you can pretty much use termux without it, so it's not worth the risk

0
0
0.000
avatar
(Edited)

It just goes to show how determined you are. Thanks for making this post. I always wondered if it was possible to use a cell phone to program. I'm probably not going to try this though.

Maybe on a tablet though... 😁😁😁

Screenshot_20231126-150259.png
#posh

0
0
0.000
avatar

Yo!

Thanks a lot for reading and sharing this, I really do appreciate it.

Yeah, I actually recommend doing something like this on a tablet since it has a much larger screen. Unlike a phone that has a pretty tiny screen.

0
0
0.000