How to use python on glitch?

I know that glitch officially supports JavaScript but is there anyway to use Python on it? Can someone give me a step-by-step instruction please?

creating your python file and then changing package.json should work:

{
    "start": "python python-file.py"
}

How would I import discord.py?

Open console and write pip3 install discord.py

1 Like

Alright, thank you. I’ll try it

Hey @Infinity1231 I suggest you take a look at the projects in https://glitch.com/@python for some examples of how to work with Python on Glitch. One thing to keep in mind is that if you omit a package.json file and instead include a requirements.txt file, Glitch will automatically install the dependencies from requirements.txt and run the project using Python.

Hope this helps!

2 Likes

I was very busy these days, but now I have tried it but I don’t know how do I start the main file? Can you check my project @cori? It’s wobbly-coast

Hey @Infinity1231, with a python project, Glitch looks for a file called start.sh in your project’s home directory and runs that when it starts up. You can place code to start your app in that file and go from there. https://glitch.com/edit/#!/hello-flask?path=start.sh:1:0 might be a good place to look for a working example.

Hey @cori. Can you check why glitch isn’t running my bot? The code is correct, I think I there’s problem with importing modules. Project name: acoustic-burglar

Hey @Infinity1231 I’m not quite sure what you’re trying to do in that project, but based on the code you have it’s doing what I would expect.

Having a glitch.json file in your project puts Glitch into “custom app mode” and runs that install and start scripts you’ve defined. In that file you’re telling Glitch to install from requirements.txt and then to start server.py which in turn starts up a minimal Flask app that renders “Hello World!” when requested. All of that works exactly as I’d expect it to.

If you don’t have a glitch.json file but do have a requirrements.txt file then Glitch goes into “Python mode”, automagically installs from requirements.txt and then starts the app using what’s in start.sh. In there it looks like you might be trying to start a bot, but you’re asking Glitch to run a file called app.py using Python. This code won’t run as long as you have the glitch.json file in place, and if that weren’t there, Glitch wouldn’t be able to find the non-existant app.py file.

Can you help me understand how you’d like this to work?