Free Hosting for Python Scripts on Google Cloud
HTML-код
- Опубликовано: 11 сен 2024
- Update: Google has changed this deal and now the free usage is only for 3 months rather than the original 12 months.
In this video I show you how to create a free Google Cloud account and host your Python scripts in the cloud.
I also show you how to use a tmux so your script will continue to run when you close the SSH window.
Finally I show how to use crontabs to schedule you script to run automatically.
If you have any questions, please leave them below and I'd be glad to help you out!
Thanks for this video, no annoying music, no bullsh!t, just straight to the point, and also you explain every single step you do including new keywords and everything. Thanks!!!
Thanks, glad you found it helpful!
@@JayMartMedia Oh yeah we did, nice work there man.
Thanks. These 10 minutes saved a lot of my time!
Great, glad to hear it!
Hi, be careful, the blur can be removed, I don't want to teach how, but I suggest you and everyone to don't input private information under bluring.
You can also simply make an exemple in text without your information for the video purposes.
(My goal is to help, I hope it does)
Nice video! Perfect for testing.
Blur can be removed? You think we live inside a cave?
nice bait
This approach is not limited to python scripts, I deployed my jar as well, thank you!
Thanks alot! I was looking for this type of solution. Your tutorial is easy to follow. Thank you for sharing this. Keep up the good work.
don't stop making videos. you way of explaining things is awesome
Loved it !! Thanks for taking it so slow and thorough :)
Glad you found it helpful!
This content quality and education value is great. Thank you so much!
great video. It was really helpful. I was able to automate a process of tunrning an XML into a csv and put it on a server for a php script to pick up and inject products into a e commerce shop data base. Thank you Jay!!
Sir you did this all wrong. You were straight to the point and showed exactly what to do. You explained everything. You didn't skip steps. Tisk tisk.
Thank you so much!
Glad you found it helpful!
Most valuable 10 minutes I have ever seen 🙌
Thank you so, so much. This was one of the best tutorials I have ever watched.
This is extremely helpful. My code ran for about 25 hrs. Thank you!
I've been looking for this quite a lot, thanks for amazingly useful info
BOMB!!!! Thank you for the video, especially for the cron!
Bro your mic and radio voice is 🔥
Thanks!
*Actually you can directly upload your files by clicking the settings icon then "upload file", as simple as that no need to use FTP !*
Or you can use git to install your files from github. I prefer to use that way
Thanks for explaining what acronyms stand for, I never knew them!
Yes, understanding what the acronyms mean really helps me to remember them. Glad you found it helpful!
Love your video! I'm working on a project with several APIs and I have to deploy it on a cloud but I don't have any experience with cloud
This is the best and most useful tech video I've ever used. Thanks so much
I'm glad you found it helpful!
You are a GOD. One video is all I needed, that is a miracle. Thank you so much
WOW this is the best tutorial in cloud easy to understand.
This is fantastic! I am extremely new to Python and this is exactly what I wanted and very easy to follow. Thank you!
One question - I just signed up for the Google Cloud Platform. If I selected the lowest VM tier items (like you did) to run my script, will this still be free for me to run after my trial runs out?
Glad you found the video helpful!
No, unfortunately the trial does not extend after the 3 month trial, even if you have a credit remaining. So you will have to cancel after three months, or start paying.
@@JayMartMedia Thanks for responding! I am running a very simple python script using TMUX. Is there a way to tell how much this will cost after the trial ends?
@@walbarn Unfortunately I can't say for sure exactly how much it would cost.
Google has a calculator here which says that one instance of the f1-micro compute engine will cost ~$3.88/month when running 24/7: cloud.google.com/products/calculator
One option would be to continue one month after the trial ends, and then cancel if. You decide it is too expensive.
@@JayMartMedia Thanks! Huge help!
@@JayMartMedia Actually this answer is false, since T2 micro in free tier, so if you have ONE T2 micro instance, you can have it for unlimited time for free. (You have 720h montly)
thx, this is a really great tutorial and i could not have done the job without your help!
Glad you found it helpful!
clear and concise, thanks a lot my dude
hey, nice video! but if i see it right, it is not for free. it is 4,28 USD monthly? (see 1:44 )
Have the same question, although I have 2 guesses:
1. You have free tier for operations each month, and only exceeding are paid.
2. You have $300 credit for registration which is almost 6 years with that price.
Is it necessary to use tmux with corntab to run even if you close
Love it!, much appreciated.
man.. you're amazing!!!!!!
So, by using tmux, is the script in running state or does tmux only save the last state and then resumes to that state once we manually login? So, for example, if I had a script that continuosly downloaded random images from the internet and I leave it on with tmux, would it continue downloading images in the background even when I've closed the SSH terminal?
Btw, awesome tutorial!
Good question, tmux stays in a running state even after you disconnect.
Assuming that your script doesn't crash, and that you wrote your script to run continually (for example, a while longer that never exits) it will continue downloading images from the internet!
Good one. EASY to follow and it works!
Thank you so much. .This is the video I am searching for.
Thank you, I got it make my project. Your video is amazing
How do we install all the dependencies needed for our python script?
You can use pip to install packages just as you would locally. Here is a video where I install the discord library, your libraries will be similar, just a different package name: ruclips.net/video/VEn70C7S5Q8/видео.html
@@JayMartMedia thanks for all the help!
YAY THANKS btw this is da 200th comment pls pin
Hey Gangster, glad you found the video helpful! Thanks for 200th comment!
Google has changed this deal and now the free account is good for 3 months instead of 12 months as it was originally.
Check out my video about uploading files to the Google Cloud server: ruclips.net/video/5oI5ZC-jnJQ/видео.html
JayMartMedia Hey,i have question when i put credit card info will it take out like 1€ like other sites do? so it could check if its real
Great video! I came to the comments to see if I could do this and you've said it yourself. I need to run a selenium script so do you think uploading the driver exe will work?
@@aman4434 Unfortunately Linux does not run .exe files natively. There is a chance that you could install a program, but I have never tried. You may be about to install a version of selenium that was built for Linux, it it MAY be possible to run a version of Windows on Google Cloud.
@@JayMartMedia ah right. I will check it out. This will still be useful for other purposes. Thanks again!
Like Heroku, If I want to run the script continuously 24/7 as there are some scheduled functions in it. Which will be the cheaper option GCP or Heroku
Thanks for the "update" heads up in the description!
Thanks a lot for this clear explanation, can you also explain how to run a scraping script on google cloud and how to get the outputs even if they were CSVs, images, pdfs, etc.?
Very well explained, saved so much of my time! I have a question though, basically if my script was supposed to run forever, I'd be using tmux right?
Correct, tmux will allow the script to continue running when you close the terminal window. If there is an uncaught error in your program it will stop. You could look into using something like PM2 to restart your script if it ever stops: www.npmjs.com/package/pm2
@@JayMartMedia Alright, thanks
Amazing tutorial. Thank you so much bro!
Super cool tutorial i dreamed of!!! Thank you a ton👍👍👍👍👌👌😎
Glad it helped you, Bogdan!
Super well explained!
dear sir i am quite new to this field and watched this very carefully and i was so impressed, but now tell me about my password my project id and how to deploy python code
regards
abdul haseeb
Another great video. Thank you
mkdir: cannot create directory ‘first-directory’: Permission denied
if there any supporting file need to run that script, where should i put it?
I have a python script that uses selenium webdriver to scrap data and then push this data to google sheet, how can I deploy this code including all supporting file on google cloud?
Should not be anything else that you need to run before creating a new directory.
Where are you trying to create the directory? It may be restricted and require admin permission to create a new directory in that directory.
You should either run 'sudo mkdir {insert name of dir}' to try to create the directory as a super-user (admin). Or you could try to cd into a different directory that is not restricted. 'cd ~' will move you to the home directory of the current user, which I expect will not be restricted.
One Question
I have created a python game using pygame and tkinter and i want to upload the file on the web/make the game run on the web and have its own address not localhost
how can i do that?
Hi I'm getting an error that says:
Reading state information... Done
E: Unable to locate package python3.9
E: Couldn't find any package by glob 'python3.9'
E: Couldn't find any package by regex 'python3.9'
when trying to execute sudo apt-get install python3.9
Any thoughts?
You will need to add an additional package archive to install newer versions of python. Here is an article about that:
docs.python-guide.org/starting/install3/linux/
Awesome, thanks man! But I used it on Russian Yandex Cloud :D
Great. I'm glad it worked for you!
яндекс дерьмо феерическое.Самая еб*нутая авторизация на яндекс клауд ,из всех что я видел. так и не удалось зайти)
Hey, can I download txt or csv file which has been created by a script? Is it accessable from google drive or is there some easy chain of commands to either dowload it directly or move it to the my google drive? Thanks a lot!
Hey, working on college project n
I've one python code and want to keep it running continuously 24/7, as it contains conditional statements, I don't want to start the whole code again from beginning, just want to keep it active/running as it is for 24/7 until it gets stopped by stop() command. I don't know whether it's possible as you described in video at last using tmux, as it restarts the code from start.
You would have to implement your own loop in your code, and just run it using tmux once. This could create some problems depending on your code though, and you'd need a lot of error handling
This is great! Thanks man
very usefull, thanks for making this
Awesome video! Thanks a lot.
Thanks! Glad you found it helpful!
Thank you! Possible to use this method (Google Cloud) to run a python-based web site associated with a domain name?
Yes, that is possible! The most difficult part is setting up the nameservers and port forwarding. This documentation may help you out: codelabs.developers.google.com/codelabs/cloud-webapp-hosting-gce/index.html?index=..%2F..index#0
question how to import package to the python script? it always says "ModuleNotFoundError: No module named 'schedule'
fantastic tutorial. thank you so much for sharing - incredibly helpful.
Great Share ! I know it says the about hourly 0.006 hourly so if you a run a simple script all day rob wont charge you. The estimate monthly says 4.28 dollars. Im assuming you tried this and never got charged.
Yeah, this tutorial is pretty old, but there is still a 90 day trial where you can use up to $300 of credit (if it's a new account). It also looks like you can have one free small compute VM indefinitely as long as it is in one of the eligible regions: cloud.google.com/free/docs/free-cloud-features#free-tier-usage-limits
@@JayMartMedia awesome thanks, do you have any new videos on this on your channel.
Hi Jay, thanks for the informative video. I am currently making a Twitter bot which is supposed to run on an hourly basis. I followed the crontabs part, but it doesn't seem to run, any idea what's causing this? Must I use tmux for this since I only want the bot to post hourly? Thanks once again.
can you make an update video to this showing how to restart and run the script even after it crashes
One question. What is the difference between Compute Engine, App Engine and Cloud Run?
Compute engine is a virtual machine running on a cloud server. You don't maintain the hardware, but you have full control of the OS.
Cloud Run is used to run docker images. So you create a docker (or other container) image, and tell cloud run what image to use, and it will spin up and scale as needed.
App Engine is somewhat between the two. It is similar to Cloud Run, except you don't need to create a docker image. App Engine supports a few popular language, but not all languages.
Here is a document from Google that may be helpful: www.google.com/url?sa=t&source=web&rct=j&url=cloud.google.com/blog/topics/developers-practitioners/where-should-i-run-my-stuff-choosing-google-cloud-compute-option
@@JayMartMedia Thank you!
Any ideas why SSH window keeps crashing a few moments after I click the "SSH" button? I can't get into the black SSH at all... I just see the loading screen and then boom... crash. I just see "Transferring SSH keys to the VM".... I am clicking the SSH button for the very first time, had never logged in before because I keeps failing ever since.
I'm not sure. I haven't had that problem before. I tried to see if I could find a solution online, but nothing stick out to me.
If there is a specific error message displayed, I would try copy/pasting that into your search bar in case someone else has had the problem. Otherwise you may be able to try a different browser
@@JayMartMedia I've found a person on stackoverflow with the same issue but no suggestion provided... I tried different browser, different projects... same issue, I don't really understand.
The only other option I can think of is using a different ssh client.
You may be able to use gcloud: Click the dropdown next to the SSH button in the google cloud console and click "View gcloud command", then click "Run in cloud shell". This should open a panel in the bottom of your browser and prompt you to create an RSA key (type "Y" for yes, type a new password for the key, confirm the password)
Alternatively you could use a third-party client such as PuTTY on Windows. This will be more difficult to set up if you haven't done it before. You can probably find another youtube video about it, and there is also documentation from Google here: cloud.google.com/compute/docs/instances/connecting-advanced#thirdpartytools
very nice, Jay! thank you!
May be a stupid question but when u install something with pip can you just type import in the python document or will u need to gave it a file directory or move stuff around?
When you install with pip you should be able to just import in your python script. No moving files around required!
I am having difficulties understanding the frequency, say I wanted to run nightly, doesn't matter when, so say midnight, what is the cronjob setting then? Thanks!!
This site may be helpful when setting cron job frequencies: crontab.guru/every-night-at-midnight
Tl;dr: "0 0 * * *" is midnight
First: 0 means it only runs the first minute
Second: 0 means it only runs in the first hour
Third: * means it runs any day of the month
Fourth: * means it runs any month
Fifth: * means it runs any day of the week
YOU ARE GREAT MAN !
Thanks, glad you found the video helpful!
i have a question, i have a python script that does checks prices for products on amazon, and emails me if if there is a price drop/discount. So because of that, my python script requires other libraries, so will I need to first pip install/download those libraries to the server?
You will need to use pip to install those libraries onto the virtual machine
Hey, I am a bit confused and new to this stuff. Do you have to use tmux to keep the crontab running or they are two separate things and once I set up a crontab it will be live and stay live even if I close the window?
You do not have to use tmux to keep cron running. Cron will continue running commands at the specified time once the crontab is saved and closed.
Great video, thanks
Check out my 100 subscriber video to enter to win a SanDisk SSD: ruclips.net/video/oy7cYek3nnw/видео.html
I'm not expecting a ton of entries, so your chance to win is decent.
Entry is simple:
• Comment on the giveaway video (include the name of a programming language)
.
• Subscribe to the channel.
Full rules in the description of the giveaway video. Hope to see ya' there!
help! everything works but the crontab! i write "00 10 * * * python tweepy-bots/mybot.py" but it doesnt work! it works when i write it (its a twitter bot, when i type the command it works) but if i put that in crontab it doesnt work at all and i really dont know what to do.
The issue is likely that you are using a relative file path in the command. A relative path is dependent on which directory that you are in when you run a command. Crontab is likely 'running' the command from a different directory than you are running it from when you are testing the command. I would recommend using an absolute path.
Here is a document which discusses the difference between relative vs absolute file paths: www.google.com/amp/s/www.geeksforgeeks.org/absolute-relative-pathnames-unix/amp/
Hope that helps!
I'm getting this error and when I delete this code line it's still happening in other lines can you help me with that please ?
File "bot.py", line 64
await channel.send(f'Welcome {member.mention}! Ready to jam out? See `!help` command for details!')
^
SyntaxError: invalid syntax
post 12 months / after my free credits i still have to pay right ?
Any good tips on how to integrate this with some sort of web form that other people can use? For instance if I wanted to perform some simple script hosted as you describe above, but have a web form where people can enter the parameters to run it with and see the results?
Thanks for the video, it's been very helpful. One question, why my bot python go on sleep mode and it Needs two commands for start?
MongoDB also has a free service up to 512MB. In case any one wanted to know.
Great video!
thank you man :-)
but I have a question when we say ( 4 v CPU) for example we mean by that 4 core CPU ?
Pretty much. vcpu is a virtual cpu, this could be a single core or in the case of hyper-threading, there may be two vcpu's per core.
stackoverflow.com/questions/45967797/is-1-vcpu-on-google-compute-engine-basically-half-of-1-physical-cpu-core
I have followed this and it tries to make a transaction. What's the problem? It's a free trial I thought.
I have a question. If I need another file besides the python code in the directory, for example a JSON file, how would I add that to the directory? Would I add it the same way the python file was added?
You can either create it as you did the python file, or you can follow this video about uploading files: ruclips.net/video/5oI5ZC-jnJQ/видео.html
Or you can look up how to upload files via FTP
@@JayMartMedia Thanks!
Does scripts works even after we shut down system ?? Also I don't understand why you have filled info in google cloud platform ??
Hi,
I followed your instruction concerning setting up a cronjob. However, it did not work. I did some research and apparently the paths are not specified well enough. What fixed it for me was using the full path to python bin file like so "/usr/bin/python3" and also using the full path with home directory like so "/home/USERNAME/my-first-directory/my-script.py.
The full cronjob would look like this:
*/5 * * * * /usr/bin/python3 /home/USERNAME/my-first-directory/my-script.py
I have a question. I don´t see the terminal do anything when the cronjob starts executing the script. However, the python script did run at the specified time. How can I see the code running in terminal like when executing the script manually?
Outputting to a console from cron is difficult. However, if you only want to view the output, then you can save the scripts output into a text file pretty easily.
Try using : "*/5 * * * * /usr/bin/python3 /home/USERNAME/my-first-directory/my-script.py > /home/USERNAME/my-first-directory/cronoutput.txt 2>&1"
All I did was append "> /home/USERNAME/my-first-directory/cronoutput.txt 2>&1" to the end of you current Cron job.
The ">" routes the normal output to the file specified. The "2&>1" routes any error output to the same file (alternatively you could replace the "1" in "2&>1" with a path to a different file if you wanted error output to a different file.)
Let me know if this helps you out!
@@JayMartMedia having log files is good. thx ;)
Awesome@@P3teR0cK, I'm glad that worked!
@JayMartMedia Do I need to run the TMUX command in order to have the CRON JOB work? Or is this something seperate?
These are separate things. The cron job simply runs a specified command at a specific time (Command Run ON). And tmux allows a terminal session to remain open after disconnecting.
Solo paso nuevamente para dejar mi agradecimiento. Soy nuevo con Google Cloud y este video me ayudo a comenzar. Para que tengas una idea, me ayudaste a reducir los costos operacionales de mis Scripts en un 73.33%.
¡Gracias!
Genial, me alegro que te haya resultado útil el vídeo. ¡Gracias por los ánimos!
idk how to use this, but i wna just learn to make a gui rock paper scissors game on this. awesome! going to start this project!
Hi Jay, this video is amazing, exactly what I am looking for! Thanks Jay!. However, I do have some confusion here.
1. Is the CRONTAB-E function same as TMUX? Is there any relation between tmux and cron job?
2. If I want to schedule a cron job to send out an email at 7pm every day, do I need to do the tmux thing first? Or just open ssh and then type crontab -e?
3. If i don't use the tmux upfront and set up a cron job, will the script running after I close the cron job?
Your advise is very much appreciated..
Millions thanks in advance!
Hi Jeff, I'm glad you found the video helpful!
There is no relation between tmux and crontab.
Crontab is used for running commands at a certain time or interval. Cron comes from "Command Run ON". It literally just runs a certain command at a certain time.
In this video I'm only using tmux to keep the terminal session active after closing the browser terminal.
From what you said, it sounds like you probably just want to use crontab. The Cron job will run at the specified time even if you do not have a current terminal session (so you don't need tmux).
@@JayMartMedia Hi Jay, you are such a good guy! Thank you very much for your reply and detail reply. I have tried and it works, and at the same time has understand crontab and tmux better now..
A big thank you for your help! I will always view your video!
can I host a bot to run 24 hours? or would I have a limit and would I have to pay something?
Yes, you could run the bot 24/7 for three months until the trial period runs out. Then you would have to start paying.
I believe there is also a spending limit during the trial period as well, but you shouldn't get anywhere close to it if you get a single, small compute instance.
Beast, appreciate it man!
Nice one!
Hi, my script needs several packages , where i have to install it ?
Thank you so much for this video,
I tried the cronjob however it's not working.
Hey bro, i had made a voice assistant and i want to run it on a website. When i will press a button on my website it will run the voice assistant. Please can you tell me , how to do that...?
good job. very helpful
Thanks for the encouragement. I'm glad you found the video helpful.
Can you not install pip files, it won’t let me, keeps saying pip command not found
Detail video Thanks
Helloo..
I am new on python and i want to install python web application on my web hosting ...and I face problem for installing pip install TA-Lib using Cpanel terminal..please help if you know solution
After 3 months you have to start paying. I contacted support and asked about it.
Hello, do you know how much do I have to pay monthly after 3 months period ?
helps me a lot
how is it free if you are to be charged around 5$ monthly?
cloud.google.com/free/docs/gcp-free-tier/#free-trial
It is now a 90-day free trial. They give you $300 in credits.
They begin charging if you use more than the $300 free credits, or after 90 days. Whichever comes first.
why crontab isn't working? im do the same as you