Skip to main content

Command Palette

Search for a command to run...

Running Python on Your Android Phone: A Beginner-Friendly Guide for Coding On-the-Go

Updated
6 min read
Running Python on Your Android Phone: A Beginner-Friendly Guide for Coding On-the-Go
D
I'm just a human trying to give value to everybody and anybody and I advance in the name of the Lord of hosts, the God of the armies of Israel. Web Designer, Graphic Designer and Software Engineer, Entrepreneur-to-be.

Hey everyone! If you're new to coding or just starting with Python, you might think you need a fancy computer to practice. But guess what? You can run Python right on your Android phone! This is super handy if you're a student doing homework on commute like me or someone who wants to experiment with code without your laptop nearby. No internet needed for most parts—perfect for offline work.

Beware: This is not meant to replace coding on laptop, this is just an alternative for situations where you cannot just use your laptop, A laptop remains the best way to code.

In this beginner guide, I'll show you how to set it up step by step. We'll use two free apps: Pydroid 3 (like a simple notepad for writing and running Python code) and Termux (a tool that lets you type commands like on a computer). I'll explain everything simply, with example commands you can copy-paste. By the end, you'll be able to write code, fix errors, and even sync your work with GitHub (like a online folder for your projects).

Don't worry if terms like "Git" or "SSH" sound scary—I'll break them down!

Why Code Python on Your Phone?

  • Easy and Free: Start coding in minutes without buying anything.

  • Offline Mode: Write and test code anywhere, like on a bus.

  • Great for Beginners: Practice simple scripts or school assignments.

  • Sync with Computer: Use GitHub to move your code between phone and laptop without copying files manually (no more messed-up spacing!).

Just know: Phones aren't as powerful as computers, so stick to basic stuff like math problems or data calculations. For fancy graphics or big programs, a laptop is better.

What You'll Need

  • An Android phone.

  • Apps: Pydroid 3 and Termux (free from Google Play Store).

  • A GitHub account (free to sign up at github.com) if you want to sync code.

Step 1: Install the Apps

  1. Open the Google Play Store.

  2. Search for "Pydroid 3" and install it. (It's a Python playground—write code and run it instantly.)
    Pydroid on Play Store

  3. Search for "Termux" and install it. (This is like a mini computer terminal for commands.)

    Termux on Play Store

Open both apps once to make sure they work. Pydroid 3 might ask for permissions—say yes to storage so it can save files.

Step 2: Set Up Shared Storage (So Apps Can Share Files)

Termux and Pydroid 3 need to "talk" to each other by accessing the same folder on your phone.

  • Open Termux (it looks like a black screen for typing).

  • Type this command and press Enter:
    termux-setup-storage
    (This asks for permission to access your phone's storage. Tap "Allow" when prompted.)

Now, create a folder for your projects:

  • Type: mkdir /storage/emulated/0/my_python_projects
    (This makes a new folder called "my_python_projects" in your phone's main storage.)

  • For quick access: ln -s /storage/emulated/0/my_python_projects ~/my_projects
    (This creates a shortcut in Termux.)

Example: After typing, you'll see no big message—just a new prompt. That's success!

Step 3: Install Git in Termux (For Saving and Syncing Code)

Git is like a "save button" that tracks changes and lets you share code on GitHub.

  • In Termux, type: pkg update && pkg install git
    (This updates Termux and installs Git. It might take a minute—watch for "Done" or similar.)

Step 4: Connect to GitHub (Secure Way with SSH)

GitHub is your online storage. To push/pull code safely, set up SSH (a secure key, like a password but better).

  1. Generate a key:
    Type: ssh-keygen -t ed25519 -C "your_email@example.com"
    (Replace "your_email@example.com" with your real GitHub email. Press Enter for defaults, and skip passphrase if you're a beginner.)

  2. Start the agent:
    eval "$(ssh-agent -s)"

  3. Add the key:
    ssh-add ~/.ssh/id_ed25519

  4. Copy the public key:
    cat ~/.ssh/id_ed25519.pub
    (Highlight the long string that appears and copy it.)

  5. Add to GitHub:

    • Open a web browser on your phone.

    • Go to github.com, log in.

    • Click your profile picture > Settings > SSH and GPG keys > New SSH key.

  6. Paste the copied string, name it "My Phone Key", and save.

  7. Test it:
    ssh -T git@github.com
    (You should see: "Hi [your username]! You've successfully authenticated..." That's good! The "no shell access" part is normal.)

Step 5: Clone a GitHub Repo (Get Your Assignment on Phone)

Let's say your teacher has a GitHub repo (like for homework).

  • In Termux, go to your folder: cd ~/my_projects

  • Clone it: git clone git@github.com:your_teacher/repo_name.git
    (Replace with the SSH URL from GitHub: On the repo page, click "Code" > SSH > Copy.)

    Mobile

    Desktop(ignore for mobile)

Example: If the URL is git@github.com:teacher/assignment1.git, type:
git clone git@github.com:teacher/assignment1.git

Now your code is on your phone!

Step 6: Edit and Run Code in Pydroid 3

  • Open Pydroid 3.

  • Tap the folder icon to open files.

  • Navigate to: /storage/emulated/0/my_python_projects/repo_name

  • Open your .py file (like main.py).

  • Write or edit code. Example simple script:

      def hello():
          print("Hello, world!")  # Indent with 4 spaces!
    
      hello()
    
  • Tap the play button to run. See output at the bottom.

For better typing: In Pydroid settings, enable autocomplete (suggests words as you type). Install extras: Tap the pip icon and type pip install jedi for smarter suggestions.

Your Beginner Workflow: Code, Save, Sync

  1. Update from GitHub: In Termux, cd to repo folder, then git pull (gets latest changes).

  2. Edit in Pydroid: Make changes, save.

  3. Save Changes: In Termux:
    git add . (adds all files)
    git commit -m "Fixed hello function" (saves with a note)
    git push (sends to GitHub)

  4. On Laptop: Use Git to git pull your phone's work.

Example full session in Termux:

cd ~/my_projects/assignment1
git pull  # Get updates
# After editing in Pydroid
git add .
git commit -m "Added print statement"
git push  # Send back

Fixing Common Beginner Errors

  • IndentationError: Python needs spaces (not tabs). Example fix: Use 4 spaces under def main():
    Bad: print("Hi") (no space)
    Good: print("Hi")

  • Auth Error: If Git asks for password, redo SSH setup.

  • Dubious Ownership:if you see errrors like this

    “fatal: detected dubious ownership in repository at '/storage/emulated/0/your-repo”

    Type the command Git suggests, like git config --global --add safe.directory /path/to/repo

  • No Name/Email: Set with: git config --global user.name "Your Name" and git config --global user.email "your@email.com"

Fun Extras for Beginners

  • Install packages in Pydroid: pip install requests (for web stuff).

  • Try: pip install numpy for math, or matplotlib for graphs.

  • For iOS friends: Use Pythonista app—similar but no Termux.

Wrapping Up

There you go! You're now set to code Python on your phone like a pro (or at least a confident beginner). Start with a simple "Hello World" script, then try your assignments. If stuck, search YouTube for "Pydroid 3 tutorial" or ask on Reddit's r/learnpython.

Happy coding! Share your first mobile script in the comments 😊

Dev Stuff

Part 1 of 1

In this series, I will try to drop anything I can to help devs especially beginners 🙂