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

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](http://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](https://play.google.com/store/apps/details?id=ru.iiec.pydroid3)
    
3. Search for "Termux" and install it. (This is like a mini computer terminal for commands.)
    
    [Termux on Play Store](https://play.google.com/store/apps/details?id=com.termux)
    

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`](mailto:your_email@example.com)`"`  
    (Replace "[your\_email@example.com](mailto: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`](http://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](http://github.com), log in.
        
    * Click your profile picture &gt; Settings &gt; SSH and GPG keys &gt; New SSH key.
        
6. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763095201745/cd2e233a-b5fc-4139-81d6-a220f76e16c8.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763095327950/84f7db44-8e8d-4329-a663-9355159a4404.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763095437137/976c3294-a212-48b5-9047-080a2510a9ab.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763095556185/472ae808-8f2b-4e10-bf29-2b49e62d6955.png align="center")
    
    Paste the copied string, name it "My Phone Key", and save.
    
7. Test it:  
    `ssh -T` [`git@github.com`](mailto: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`](mailto:git@github.com)`:your_teacher/repo_name.git`  
    (Replace with the SSH URL from GitHub: On the repo page, click "Code" &gt; SSH &gt; Copy.)
    
    **Mobile**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763094375608/460d6b20-de17-44d8-a2de-dd78e597ac8c.png align="center")
    
    Desktop(ignore for mobile)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763093048568/2b0daf5f-60f9-432d-8f03-f4f7fdf3b37f.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1763093463232/b4848f2a-6a48-4fb2-90c0-6410a75bfeac.png align="center")
    

Example: If the URL is [`git@github.com`](mailto:git@github.com)`:teacher/assignment1.git`, type:  
`git clone` [`git@github.com`](mailto: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](http://main.py)).
    
* Write or edit code. Example simple script:
    
    ```python
    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:

```plaintext
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`](http://safe.directory) `/path/to/repo`
    
* **No Name/Email**: Set with: `git config --global` [`user.name`](http://user.name) `"Your Name"` and `git config --global` [`user.email`](http://user.email) `"`[`your@email.com`](mailto: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 😊
