Glitch.com with Python

3.7k Views Asked by At

How to create and use Python 3.7 on Glitch.com? I created a project. Default Python version is old.


I used these files to run Python on Glitch:
  • main.py

    import discord
    from discord.ext import commands
    bot = commands.Bot(command_prefix="bot.")
    @bot.event
    async def on_ready():
       print("Bot ready!")
    bot.run("TOKEN_HERE")
    

  • start.sh

    python main.py
    

  • requiments.txt

    discord.py==1.2.3
    
    

  • 2

    There are 2 best solutions below

    0
    On BEST ANSWER
    0
    On

    Okay, the above answer is correct, an extension to that.

    use python3 main.py to run your code.

    glitch accepts to use start.sh file, that runs the start up script.

    If you are using some packages, you will need to install them, which we generally do using pip. But, Glitch pip runtime installs those packages in python 2 directory. So, even after using python3 in start.sh in Glitch project, it doesn't work.

    Here's the work around.

    Use Python to install packages.

    Following codes will do:

    python3 -m pip install -U pip
    python3 -m pip install -r requirements.txt
    python3 main.py
    
    

    Add above codes in start.sh

    • we're first upgrading pip using python3 (which we usually do)
    • Install all packages in requirements.txt ( don't forget s here, I did :|)
    • start the main.py

    Additionally, if you want to install a package separately, use python3 -m pip install <package_name>.

    Have fun. Your project just launched successfully.