{"id":108901,"date":"2024-05-06T17:29:31","date_gmt":"2024-05-06T17:29:31","guid":{"rendered":"\/tutorials\/?p=108901"},"modified":"2025-12-18T22:49:50","modified_gmt":"2025-12-18T22:49:50","slug":"how-to-run-a-python-script-in-linux","status":"publish","type":"post","link":"\/my\/tutorials\/free-woocommerce-themes-20","title":{"rendered":"How to Run a Python Script in Linux VPS"},"content":{"rendered":"<p>Running Python scripts in Linux is a fundamental skill for developers and system administrators. Thanks to its versatility and ease of use, Python is preferred for automating tasks, analyzing complex data, building applications, and managing systems.<\/p><p>Python&rsquo;s integration with Linux-based systems is seamless, thanks to the availability of interpreters and libraries in Linux repositories. In this tutorial, we&rsquo;ll explain how to run a Python script in your remote server&rsquo;s Linux command line.<\/p><p>You&rsquo;ll also learn about common errors that could occur while running your Python script in Linux and how to troubleshoot them.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites\">Prerequisites<\/h2><p>Before we begin, have the following details of your VPS ready:<\/p><ul class=\"wp-block-list\">\n<li>Server IP address<\/li>\n\n\n\n<li>SSH port<\/li>\n\n\n\n<li>SSH username<\/li>\n\n\n\n<li>SSH password<\/li>\n<\/ul><p>If you&rsquo;re a Hostinger user, you&rsquo;ll find these details under the following:<\/p><p><strong>VPS<\/strong> &rarr; <strong>Server Details <\/strong>&rarr; <strong>Manage. <\/strong>Your credentials are located under the <strong>SSH access<\/strong> tab. <\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c44e7b7\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"1476\" height=\"822\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/ssh-access.png\" alt=\"hPanel SSH Access tab\" class=\"wp-image-109063\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/ssh-access.png 1476w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/ssh-access-300x167.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/ssh-access-1024x570.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/ssh-access-150x84.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/ssh-access-768x428.png 768w\" sizes=\"(max-width: 1476px) 100vw, 1476px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/my\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-execute-a-python-script-in-your-linux-vps-command-line\">How to Execute a Python Script in your Linux VPS Command Line<\/h2><p>This section will walk you through the steps to run Python scripts, from making them executable to running them in the Command Line Interface (CLI).<\/p><h3 class=\"wp-block-heading\" id=\"h-1-transfer-a-python-script-to-vps\">1. Transfer a Python Script to VPS<\/h3><p>To run your script, you&rsquo;ll need to import it from your local machine, and there are several ways to do this. Each method offers a different approach to transferring data from your machine to your VPS, with varying levels of complexity and security.<\/p><p>Here are some file-transferring methods and protocols out there.<\/p><p><strong>Secure copy protocol (SCP)<\/strong><\/p><p>SCP relies on <strong>SSH<\/strong> for safe data transfer as it encrypts both the file and the authentication information. To copy files, you must have <strong>read<\/strong> permission on the source file and <strong>write<\/strong> permission on the target system.<\/p><p>First, connect to your VPS using <strong>PuTTY<\/strong>. You&rsquo;ll need to download it to your system to <a href=\"\/my\/tutorials\/how-to-use-putty-ssh\">access your server<\/a>.&nbsp;<\/p><p>When you&rsquo;re ready, launch the PuTTY SSH client by typing <code>putty<\/code> into your Linux terminal. Use <strong>Ctrl + Alt + T<\/strong> or <strong>Command + Option + T<\/strong> if you&rsquo;re using macOS to open the <strong>Terminal<\/strong>.<\/p><p>Enter your server&rsquo;s <strong>SSH IP<\/strong> and <strong>SSH Port<\/strong>. Click <strong>Open<\/strong> to proceed.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c451722\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"652\" height=\"572\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image2.png\" alt=\"PuTTY ip port\" class=\"wp-image-108905\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image2.png 652w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image2-300x263.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image2-150x132.png 150w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If PuTTY disappears after entering your details and you see an <strong>unable to load font <\/strong>error, relaunch PuTTY and change the font.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c45316f\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"724\" height=\"202\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image14.png\" alt='Linux terminal launching Putty and displaying \"Putty: unable to load font \"server: fixed\" error' class=\"wp-image-108907\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image14.png 724w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image14-300x84.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image14-150x42.png 150w\" sizes=\"(max-width: 724px) 100vw, 724px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>This error was displayed because the font wasn&rsquo;t specified. Click <strong>Change <\/strong>and select the font.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c454d71\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"652\" height=\"575\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image24-min.png\" alt=\"Fonts section of Putty window with server:fixed as font\" class=\"wp-image-108910\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image24-min.png 652w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image24-min-300x265.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image24-min-150x132.png 150w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c456afb\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"567\" height=\"547\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image4.png\" alt=\"change font \" class=\"wp-image-108911\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image4.png 567w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image4-300x289.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image4-150x145.png 150w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Click <strong>Open<\/strong>, and the server window will appear.<\/p><p>Type your <strong>username<\/strong> and <strong>password<\/strong> to continue. Note that there will be<strong> no visual indication<\/strong> of what you&rsquo;re typing in your terminal.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c458740\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"1024\" height=\"606\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image1.png\" alt=\"Pitch-black Putty window displaying prompts to enter username and password\" class=\"wp-image-108912\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image1.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image1-300x178.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image1-150x89.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image1-768x455.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Now that you&rsquo;re connected to the server, enter the following command:<\/p><pre class=\"wp-block-preformatted\">scp [path to file\/folder on your machine][username@IP address]:[path to desired location on VPS]&nbsp;<\/pre><p>For example, if you want to <a href=\"\/my\/tutorials\/using-scp-command-to-transfer-files\/\">transfer a file<\/a> called <strong>scpfile.py<\/strong> located in the <strong>Code<\/strong> folder<strong> <\/strong>on your local machine to the files folder on your VPS, the command should look something like this:<\/p><pre class=\"wp-block-preformatted\">scp C:\/Users\/username\/Desktop\/Code\/scpfile.py root@31.220.57.32:files<\/pre><p>Note that you can <strong>duplicate<\/strong> the terminal to perform this action since the other instance will be busy activating the server. If you get the <strong>connection timed-out <\/strong>error like this, modify the command to include the port.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c45a2a1\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"578\" height=\"48\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image11.png\" alt=\"port error\" class=\"wp-image-108913\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image11.png 578w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image11-300x25.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image11-150x12.png 150w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><pre class=\"wp-block-preformatted\">scp -P [Port number][path to file\/folder on your machine] [username@IP address]:[path to desired location on VPS]<\/pre><pre class=\"wp-block-preformatted\">scp -P 67003 C:\/Users\/username\/Desktop\/Code\/scpfile.py root@31.220.57.32:files<\/pre><p>You&rsquo;ll get a warning message.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c45c01f\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"620\" height=\"37\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image19.png\" alt=\"warning after adding port\" class=\"wp-image-108914\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image19.png 620w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image19-300x18.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image19-150x9.png 150w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Simply type <strong>yes<\/strong> and enter your password.<\/p><p>A progress bar will appear, and the file will be uploaded to your VPS.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c45dc86\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"692\" height=\"23\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image8.png\" alt=\"scp file\" class=\"wp-image-108916\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image8.png 692w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image8-300x10.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image8-150x5.png 150w\" sizes=\"(max-width: 692px) 100vw, 692px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To upload multiple files, remove <strong>scpfile.py<\/strong> and replace it with an <strong>asterisk<\/strong> in the local folder path.<\/p><pre class=\"wp-block-preformatted\">scp -P 67003 C:\/Users\/username\/Desktop\/Code\/* root@31.220.57.32:files<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c45fbf3\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"691\" height=\"132\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image7.png\" alt=\"scp multiple files\" class=\"wp-image-108918\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image7.png 691w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image7-300x57.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image7-150x29.png 150w\" sizes=\"(max-width: 691px) 100vw, 691px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To upload an entire folder, you&rsquo;ll have to copy all the files by adding <strong>-r <\/strong>to the command line in the example here:<\/p><pre class=\"wp-block-preformatted\">scp -r -P 67003 C:\/Users\/username\/Desktop\/Code\/* root@31.220.57.32:files<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c4618e1\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"447\" height=\"76\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image3.png\" alt=\"copy folder\" class=\"wp-image-108919\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image3.png 447w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image3-300x51.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image3-150x26.png 150w\" sizes=\"(max-width: 447px) 100vw, 447px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Remember that SCP doesn&rsquo;t provide any warnings or prompts before overwriting an existing file with the same name. Therefore, you can easily overwrite files or directories by accident, so be careful.<\/p><p><strong>rsync<\/strong><\/p><p><strong>rsync<\/strong> (remote synchronization) is a method for syncing files and directories between two locations. The first time rsync is used, it transfers the entire content of a file or directory.<\/p><p>It uses a remote synchronization protocol that transfers only the changes between the files, making it an efficient solution for large data transfers. rsync also picks up where it left off when the connection is interrupted.<\/p><p>For copying multiple files, rsync is excellent because it can copy everything using a single command. It can automatically create subdirectories and use the same ssh session for each. It&rsquo;s also a fast and efficient solution for backups and secure file transfers between local and remote systems.<\/p><p>To begin <a href=\"\/my\/tutorials\/how-to-use-rsync\">using rsync<\/a>, check whether your VPS has it installed using the following command:<\/p><pre class=\"wp-block-preformatted\">command -v rsync<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c4639fa\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"472\" height=\"37\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image15.png\" alt=\"check rsync install status\" class=\"wp-image-108920\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image15.png 472w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image15-300x24.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image15-150x12.png 150w\" sizes=\"(max-width: 472px) 100vw, 472px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If you don&lsquo;t have rsync installed, use this command.<\/p><p>For <strong>Ubuntu<\/strong>, <strong>Linux Mint<\/strong>, and <strong>Debian<\/strong> use the following:<\/p><pre class=\"wp-block-preformatted\">sudo apt-get install rsync<\/pre><p>For other distributions such as <strong>Fedora<\/strong>, <strong>CentOS<\/strong>, <strong>AlmaLinux<\/strong>, and <strong>Red Hat<\/strong>, use the command:<\/p><pre class=\"wp-block-preformatted\">sudo dnf install rsync<\/pre><p>Once that&rsquo;s taken care of, start and enable rsync:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl start rsync&nbsp;<br><br>sudo systemctl enable rsync<\/pre><p>This command will move your files from a local machine to your VPS:<\/p><pre class=\"wp-block-preformatted\">rsync [options][path to file\/folder on your machine][username@IP address]:[path to desired location on VPS]<\/pre><p>rsync offers a variety of options to customize and control file synchronization. Here are some of the commonly used options:<\/p><ul class=\"wp-block-list\">\n<li><strong>-a<\/strong> or <strong>&ndash;archive<\/strong> &ndash; preserves permissions and timestamps.<\/li>\n\n\n\n<li><strong>-v<\/strong> or <strong>&ndash;verbose<\/strong> &ndash; shows detailed information about the files being synced.<\/li>\n\n\n\n<li><strong>-z<\/strong> or <strong>&ndash;compress<\/strong> &ndash; allows compression during data transfer, reducing network usage.<\/li>\n\n\n\n<li><strong>-r<\/strong> or <strong>&ndash;recursive<\/strong> &ndash; syncs directories recursively.<\/li>\n\n\n\n<li><strong>-u<\/strong> or <strong>&ndash;update<\/strong> &ndash; skips files that are newer on the receiver.<\/li>\n\n\n\n<li><strong>-n<\/strong> or <strong>&ndash;dry-run<\/strong> &ndash; performs a trial run without making any changes. A helpful command for testing.<\/li>\n\n\n\n<li><strong>&ndash;delete<\/strong> &ndash; removes files from the destination directory.<\/li>\n\n\n\n<li><strong>&ndash;exclude<\/strong> &ndash; stops files or directories from being transferred.<\/li>\n\n\n\n<li><strong>&ndash;progress<\/strong> &ndash; shows progress during transfer.<\/li>\n\n\n\n<li><strong>&ndash;bwlimit<\/strong> &ndash; limits the bandwidth to be used for the transfer.<\/li>\n\n\n\n<li><strong>&ndash;partial<\/strong> &ndash; allows to continue interrupted transfers.<\/li>\n\n\n\n<li><strong>&ndash;ignore-existing<\/strong> &ndash; ignores files that already exist in the destination.<\/li>\n\n\n\n<li><strong>&ndash;include<\/strong> &ndash; includes only specific files or directories.<\/li>\n\n\n\n<li><strong>&ndash;exclude-from<\/strong> &ndash; excludes files or directories listed in a specified file.<\/li>\n\n\n\n<li><strong>&ndash;remove-source-files<\/strong> &ndash; removes transferred files from the source after a successful transfer.<\/li>\n<\/ul><p>These options can be combined to suit your specific requirements.<\/p><p>Refer to the rsync manual for comprehensive documentation and additional options:<\/p><p><code>man rsync<\/code> or <code>rsync<\/code><\/p><p>Here&rsquo;s how a rsync command will look with the details plugged in:<\/p><pre class=\"wp-block-preformatted\">rsync -avz -e ssh C:\/Users\/username\/Desktop\/Code\/rsyncfile.py\/ root@31.220.57.32:files\/<\/pre><p>Note that the <strong>trailing \/ (forward slash)<\/strong> at the end of both directory paths tells rsync to place all the files and subdirectories<strong> <\/strong>under that specific directory. Removing these will make rsync copy the directory itself. <\/p><p>Furthermore, you can use SCP and rsync to transfer files between locations. However, SCP is better used for one-off transfers, especially if the file size is relatively small.<\/p><p>In contrast, rsync is best used when the file size is big or when more complex and efficient synchronization is needed. It&rsquo;s also the better choice for recurring tasks.<\/p><p><strong>SFTP (SSH File Transfer Protocol)<\/strong><\/p><p>SFTP is a secure alternative to FTP for transferring files over SSH. It provides file access, transfer, and management functionalities over a secure channel. Here&rsquo;s how it works.<\/p><p>First, connect to the server using the following command:<\/p><pre class=\"wp-block-preformatted\">sftp user@remoteserverIPaddress<\/pre><p>To upload a file to your remote server, use <strong>put<\/strong> or <strong>mput<\/strong> if you&rsquo;re transferring multiple files:<\/p><pre class=\"wp-block-preformatted\">put sftpfile.py<\/pre><p>Note: Move into the directory in which you want to place the file, or else it will be stored in the root directory. You can use the -r option or * to upload a folder, as seen in the SCP example above.<\/p><p><strong>Secure Shell (SSH) protocol<\/strong><\/p><p>SSH is a cryptographic network protocol that enables safe communication between two systems by encrypting the data transmitted between them.<\/p><p>First, connect to the server.<\/p><pre class=\"wp-block-preformatted\">ssh username@IPaddress&nbsp;<\/pre><p>Specify the port if you get an error. Unlike the others, ssh uses a small p.<\/p><pre class=\"wp-block-preformatted\">ssh -p 6000 root@31.220.57.32<\/pre><p>Now, use SCP to transfer the files to your VPS.<\/p><p>If everything is working correctly, you should see a progress bar that will alert you when the process is complete.<\/p><h3 class=\"wp-block-heading\" id=\"h-2-make-sure-python-is-installed-on-your-vps\">2. Make Sure Python Is Installed on Your VPS<\/h3><p>First things first, ensure your VPS has Python installed. Most Linux distributions come with Python preinstalled, but you&rsquo;ll have to install it manually if you don&rsquo;t own a VPS. To check whether or not you have Python installed, run this command:<\/p><pre class=\"wp-block-preformatted\">python --version<\/pre><p>OR<\/p><pre class=\"wp-block-preformatted\">python3 &ndash;-version<\/pre><p>If your VPS has Python installed, a version number will be displayed.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c466cba\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full is-resized wp-lightbox-container\"><img decoding=\"async\" width=\"427\" height=\"60\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image12.png\" alt=\"python version\" class=\"wp-image-108923\" style=\"width:427px;height:auto\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image12.png 427w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image12-300x42.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image12-150x21.png 150w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Sometimes, Python can be saved in a different location. To view these locations, use the which command:<\/p><pre class=\"wp-block-preformatted\">which python<\/pre><p>OR<\/p><pre class=\"wp-block-preformatted\">which python3&nbsp;&nbsp;<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c468a84\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"392\" height=\"53\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image10.png\" alt=\"which python\" class=\"wp-image-108922\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image10.png 392w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image10-300x41.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image10-150x20.png 150w\" sizes=\"(max-width: 392px) 100vw, 392px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If Python is not installed, you will receive the following message:<\/p><pre class=\"wp-block-preformatted\">bash: python3: command not found<\/pre><p>If you&rsquo;ve used the <code>which<\/code> command, you&rsquo;ll receive a no python in path error instead.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c46aa4e\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"712\" height=\"53\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image22.png\" alt=\"no python in\" class=\"wp-image-108926\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image22.png 712w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image22-300x22.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image22-150x11.png 150w\" sizes=\"(max-width: 712px) 100vw, 712px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Here&rsquo;s how to install Python for different Linux distributions.<\/p><p><strong>Ubuntu\/Debian<\/strong><\/p><p>First, update the package index using the following:<\/p><pre class=\"wp-block-preformatted\">sudo apt update&nbsp;<\/pre><p>Then, install <strong>Python 3<\/strong> and the <a href=\"\/my\/tutorials\/install-pip-in-ubuntu\/\">Python pip<\/a> package:<\/p><pre class=\"wp-block-preformatted\">sudo apt install python3 python3-pip<\/pre><p><strong>CentOS\/RHEL<\/strong><\/p><p>For CentOs\/RHEL 8, use the following:<\/p><pre class=\"wp-block-preformatted\">sudo dnf install python3 python3-devel python3-pip&nbsp;<\/pre><p>For CentOS\/RHEL 7, use these commands:<\/p><pre class=\"wp-block-preformatted\">sudo yum install epel-release<br><br>sudo yum install python3 python3-devel python3-pip<\/pre><p><strong>Arch Linux<\/strong><\/p><pre class=\"wp-block-preformatted\">sudo pacman -Syu python python-pip python-setuptools<\/pre><p><strong>Fedora<\/strong><\/p><pre class=\"wp-block-preformatted\">sudo dnf install python3 python3-pip python3-devel<\/pre><p><strong>openSUSE<\/strong><\/p><pre class=\"wp-block-preformatted\">udo zypper update python3 python3-pip python3-devel<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-make-your-script-executable\">3. Make Your Script Executable<\/h3><p>Before executing the Python script, you need to make it <strong>executable<\/strong>. Turning your script into an executable converts it into machine language your VPS can understand. To make your file executable, add a <strong>shebang<\/strong> line.<\/p><p>shebang is a special declaration that tells the VPS which interpreter to use. Add a Python shebang to the top of your script:<\/p><pre class=\"wp-block-preformatted\">#!\/usr\/bin\/env python3<\/pre><p>\/enli<\/p><p>shebang informs the VPS that the file is a Python script, so it should invoke the Python interpreter to run it.<\/p><p>To add a shebang, edit the script using <strong>nano<\/strong>, a<strong> <\/strong>Linux text editor. First, go into edit mode:<\/p><pre class=\"wp-block-preformatted\">nano .\/executable.py<\/pre><p>Add a shebang at the top of the script and press <strong>Ctrl + O <\/strong>to <strong>save<\/strong>. Hit <strong>Ctrl + X<\/strong> to <strong>exit<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/my\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image17-1.png\"><img decoding=\"async\" width=\"711\" height=\"420\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image17-1.png\" alt=\"adding a shebang\" class=\"wp-image-108928\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image17-1.png 711w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image17-1-300x177.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image17-1-150x89.png 150w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/a><\/figure><\/div><p>Next, navigate to the folder containing the file:<\/p><pre class=\"wp-block-preformatted\">cd path\/to\/file<\/pre><p>Now, you&rsquo;ll have to set permissions for the executable using the following command:<\/p><pre class=\"wp-block-preformatted\">chmod +x [Python file]<br>chmod +x&nbsp; executable.py<\/pre><p>The <strong>chmod<\/strong> command in Linux stands for <strong>change mode<\/strong>, and it is used to <a href=\"\/my\/tutorials\/how-to-change-linux-permissions-and-owners\">change the permissions<\/a> of a file or directory. Each file or directory in Linux has permissions that determine who can read, write, or execute it.<\/p><p>These permissions are represented by a series of letters or numbers, known as the file mode or permission mode. The <strong>chmod<\/strong> command above adds <strong>execute<\/strong> permissions to your script.<\/p><h3 class=\"wp-block-heading\" id=\"h-4-run-the-script-and-view-it-in-the-terminal\">4. Run the Script and View it in the Terminal<\/h3><p>Once the script is ready to be executed, you can run it using the Python interpreter. Use the following command to execute your script:<\/p><pre class=\"wp-block-preformatted\">.\/executable.py<\/pre><p>After running the script, you can view the output directly in the terminal.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c46d925\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"657\" height=\"91\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image21.png\" alt=\"running py script\" class=\"wp-image-108929\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image21.png 657w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image21-300x42.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image21-150x21.png 150w\" sizes=\"(max-width: 657px) 100vw, 657px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-5-view-logs\">5. View Logs<\/h3><p>You can also check the <strong>system logs<\/strong> for errors or messages generated by the script. To access Linux log files, move into the Linux system logs directory. The default directory path is <code>\/var\/log<\/code>:&nbsp;<\/p><pre class=\"wp-block-preformatted\">cd \/var\/log<\/pre><p>Once there, type <strong>ls<\/strong> to list the logs stored within this directory.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c46f724\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"656\" height=\"177\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image20.png\" alt=\"Linux terminal showing a change of directory to the log files folder and a list of all the files in the folder\" class=\"wp-image-108931\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image20.png 656w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image20-300x81.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image20-150x40.png 150w\" sizes=\"(max-width: 656px) 100vw, 656px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Linux logs provide a timeline of events that occur on your computer. They are helpful for troubleshooting issues, monitoring system health, diagnosing problems, and investigating security incidents. There are different kinds of logs, but the following are some log files and their definitions:<\/p><ul class=\"wp-block-list\">\n<li><code>\/var\/log\/syslog<\/code> &ndash; messages from the syslog daemon and other system daemons.<\/li>\n\n\n\n<li><code>\/var\/log\/auth.log<\/code> or <code>\/var\/log\/secure<\/code> &ndash; authentication-related messages. It records information about user logins, authentication attempts, and other security-related events.<\/li>\n\n\n\n<li><code>\/var\/log\/kern.log<\/code> &ndash; information about the kernel&rsquo;s operation, hardware drivers, and other low-level system activities.<\/li>\n\n\n\n<li><code>\/var\/log\/dmesg<\/code> &ndash; messages from the kernel ring buffer. It provides information about hardware detection, device initialization, and other kernel-related messages from the last boot.<\/li>\n<\/ul><ul class=\"wp-block-list\">\n<li><code>\/var\/log\/boot.log<\/code> &ndash; information about the boot process. It includes messages from system startup scripts and services that start during boot.<\/li>\n\n\n\n<li><code>\/var\/log\/daemon.log<\/code> &ndash; messages from system daemons or background services. This includes messages from services like Apache, MySQL, and others.<\/li>\n\n\n\n<li><code>\/var\/log\/cron<\/code> &ndash; information about cron jobs that are executed on the system, including when they were run and if there were any errors.<\/li>\n\n\n\n<li><code>\/var\/log\/maillog<\/code> or <code>\/var\/log\/mail.log<\/code> &ndash; mail server logs, including messages related to sending and receiving emails.<\/li>\n\n\n\n<li><code>\/var\/log\/lastlog<\/code> &ndash; keeps track of all users&rsquo; last login times in the system.<\/li>\n\n\n\n<li><code>\/var\/log\/audit\/audit.log<\/code> &ndash; on systems with <strong>auditd<\/strong> installed&mdash;an auditing daemon&mdash;this file contains logs of security-related events such as file access, user authentication, and other system-level security events.<\/li>\n<\/ul><p>Keep in mind that the exact location and naming conventions of these logs may vary between Linux distributions.<\/p><p>To view or examine the contents of any log file, use <code>less or cat<\/code>:<\/p><pre class=\"wp-block-preformatted\">less nameoflog<\/pre><p>For example, this is the command you&rsquo;ll use to view the syslog:<\/p><pre class=\"wp-block-preformatted\">less syslog&nbsp;<\/pre><p>Scrolling through any file might take some time because they are very long. You can use <strong>Shift + G<\/strong> to fast-forward to the <strong>(END)<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c4719f5\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"722\" height=\"520\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image9.png\" alt=\"end of log\" class=\"wp-image-108932\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image9.png 722w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image9-300x216.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image9-150x108.png 150w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To exit the file, simply type <code>q<\/code>.<\/p><p>Moving on, another command that helps you view the log files is the <strong>tail<\/strong> command. However, it only shows the <strong>last part of the file<\/strong>, where problems usually lie:<\/p><pre class=\"wp-block-preformatted\">tail \/var\/log\/syslog or&nbsp;<br><br>tail -f \/var\/log\/syslog<\/pre><p>Due to the <strong>-f<\/strong> in the command above, <strong>tail<\/strong> will continuously monitor the log file, displaying newly written lines in real time:<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c4738e4\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"735\" height=\"270\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image6.png\" alt=\"Linux terminal showing a change of directory to the syslog file and a display of the last 5 lines of the syslog file\" class=\"wp-image-108933\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image6.png 735w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image6-300x110.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image6-150x55.png 150w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>For a specific number of lines, such as the last five, use the following:<\/p><pre class=\"wp-block-preformatted\">tail -f -n 5 \/var\/log\/syslog<\/pre><p>As new lines appear, older ones are replaced. To exit the tail command, press <strong>Ctrl + C<\/strong>.<\/p><h2 class=\"wp-block-heading\" id=\"h-running-a-python-code-interactively\">Running a Python Code Interactively<\/h2><p>Python provides an interactive mode where you can execute code blocks or single lines of code and receive immediate feedback.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-launching-python-s-interactive-mode\">1. Launching Python&rsquo;s Interactive Mode<\/h3><p>To launch Python&rsquo;s interactive mode on your VPS, type <strong>Python<\/strong> or <strong>Python3<\/strong> into the terminal to launch the Python interpreter.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c47570d\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"643\" height=\"95\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image5.png\" alt=\"Linux terminal launching interactive mode after 'python3' is typed into the terminal\" class=\"wp-image-108934\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image5.png 643w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image5-300x44.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image5-150x22.png 150w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-2-executing-python-commands-interactively\">2. Executing Python Commands Interactively<\/h2><p>Once in interactive mode, you can enter Python commands directly and see their output immediately. This mode is useful for testing code snippets or experimenting with Python features.<\/p><p>We&rsquo;re going to print <code>Hello World<\/code> to the console.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c47734a\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"647\" height=\"160\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image23.png\" alt=\"arithmetic error\" class=\"wp-image-108935\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image23.png 647w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image23-300x74.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image23-150x37.png 150w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Here, we printed <code>Hello World<\/code> and performed an arithmetic operation. In the example above, we made a mistake, and Python threw an error.<\/p><p>In interactive mode, there is little room for error. You&rsquo;d have to repeat the entire code if you make a mistake. This is why interactive mode is mainly used to test code snippets and not for creating large chunks of code.<\/p><h3 class=\"wp-block-heading\" id=\"h-3-exiting-interactive-mode\">3. Exiting Interactive Mode<\/h3><p>To exit Python&rsquo;s interactive mode, type <code>exit()<\/code> or press<strong> Ctrl + D<\/strong> on your keyboard.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0c5c479f83\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"650\" height=\"77\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/image18.png\" alt=\"Linux terminal showing the result of printing 70+20. It also exits Python interactive mode after the 'exit()' command\" class=\"wp-image-108937\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image18.png 650w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image18-300x36.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2024\/05\/image18-150x18.png 150w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-troubleshooting-common-execution-errors\">Troubleshooting Common Execution Errors<\/h2><p>Encountering errors while running Python scripts is common. Here are some errors to look out for.<\/p><h3 class=\"wp-block-heading\" id=\"h-permission-denied-error\">Permission Denied Error<\/h3><p><strong>Error message: <\/strong>PermissionError: [Errno 13] Permission denied<\/p><p><strong>Cause:<\/strong> script does not have execute permissions.<\/p><p><strong>Troubleshoot:<\/strong> use <code>chmod +x [Python file]<\/code> to grant <strong>execute<\/strong> permissions to your script<\/p><h3 class=\"wp-block-heading\" id=\"h-no-such-file-or-directory-error\">No Such File or Directory Error<\/h3><p><strong>Error message:<\/strong> no such file or directory: &lsquo;script.py&rsquo;<\/p><p><strong>Cause:<\/strong> script file path is incorrect.<\/p><p><strong>Troubleshoot:<\/strong> make sure you are in the correct directory or provide the full path to the script:<\/p><pre class=\"wp-block-preformatted\">python3 \/path\/to\/pythonscript.py<\/pre><h3 class=\"wp-block-heading\" id=\"h-python-version-compatibility\">Python Version Compatibility<\/h3><p><strong>Cause:<\/strong> you have multiple versions of Python installed on your Linux system, and your script requires a specific version to run correctly.<\/p><p><strong>Troubleshoot:<\/strong> specify the desired Python version explicitly when running the script, depending on your requirements:<\/p><pre class=\"wp-block-preformatted\">python3 script.py or python2 script.py<\/pre><h3 class=\"wp-block-heading\" id=\"h-interpreter-not-found-error\">Interpreter Not Found Error<\/h3><p><strong>Error message:<\/strong> bash: python3: command not found<\/p><p><strong>Cause:<\/strong> the Python interpreter is not installed or not in the system&rsquo;s path.<\/p><p><strong>Troubleshoot:<\/strong> Install Python using the package manager. Then, add Python to the path or specify the full path to the interpreter.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Linux is a powerful tool that makes running Python a piece of cake. This is beneficial because Python is a high-level programming language used to create powerful applications and systems.<\/p><p>In this tutorial, we&rsquo;ve covered how to run a Python script in the command line, how to run a Python script interactively, and how to view log files. We&rsquo;ve also talked about some common execution errors and ways to troubleshoot them.<\/p><p>These steps will help you smoothly execute Python code for numerous tasks, from automation to system management. We hope you&rsquo;ve found this article helpful!<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-run-a-python-script-in-linux-faq\">How to Run a Python Script in Linux FAQ<\/h2><p>Here are some of the most commonly asked questions regarding running Python scripts.<\/p><div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-6944850ec5662\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How Do I Run a Python Executable in Linux?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>To run a Python executable in Linux, simply navigate to the executable&rsquo;s directory and run it using the <code>.\/<\/code> prefix followed by the <strong>filename<\/strong>. After running the script, you&rsquo;ll see the output in the terminal, or if it&rsquo;s an application, a window will open.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-6944850ec5665\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What&rsquo;s the Difference Between Running Python Scripts Interactively and From the Command Line?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Running Python scripts interactively allows you to execute Python commands line by line in real time, whereas running scripts from the command line allows you to execute the entire script at once. The command line is usually used to execute massive chunks of code that wouldn&rsquo;t make sense to run in interactive mode.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-6944850ec5666\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How Can I Run a Python Script at Scheduled Times on Linux?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Create a script with a shebang line, <code>#!\/usr\/bin\/env python3<\/code>. Make it executable by typing <code>chmod +x [Python script]<\/code>. Add a cron job <code>crontab -e<\/code>. Specify the schedule <code>[schedule] \/path\/to\/python3 \/path\/to\/script.py<\/code>&nbsp;and save. Verify with <code>crontab -1<\/code>.&nbsp;<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Running Python scripts in Linux is a fundamental skill for developers and system administrators. Thanks to its versatility and ease of use, Python is preferred for automating tasks, analyzing complex data, building applications, and managing systems. Python&rsquo;s integration with Linux-based systems is seamless, thanks to the availability of interpreters and libraries in Linux repositories. In [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/my\/tutorials\/free-woocommerce-themes-20\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":446,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Run a Python Script in Linux","rank_math_description":"Learn to run Python scripts on your Linux VPS: Discover file transfer, execution, and troubleshooting to streamline your development process.","rank_math_focus_keyword":"how to run a python script in linux","footnotes":""},"categories":[22640,22639],"tags":[],"class_list":["post-108901","post","type-post","status-publish","format-standard","hentry","category-vps-use-cases","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-run-a-python-script-in-linux","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-run-a-python-script-in-linux","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/108901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/users\/446"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/comments?post=108901"}],"version-history":[{"count":21,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/108901\/revisions"}],"predecessor-version":[{"id":126156,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/108901\/revisions\/126156"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media?parent=108901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/categories?post=108901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/tags?post=108901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}