How to create a setup file that run on hosted server python? - python

I'm creating a python app to get details from a website. I'm using selenium and pyodbc to create my app. It is getting all the details and saves them into a SQL server database. It is working fine on my pycharm IDE. Now I need to use this app on a hosted server like Linux or ubuntu server. How can I create a .exe file to run my app on a hosted server? And I used pyinstaller to create a .exe file using the following command.
pyinstaller --one main.py
I don't know what are the initial things that I should install on my server. Or is it not necessary to install any of the things to run my app?

See if this can help:
You can install python on your server and create a service in linux to run it. You don't have to create a .exe file. Also, .exe won't run on linux or ubuntu server.
Here's an article that can help you installing python on linux server:
https://www.geeksforgeeks.org/how-to-install-python-on-linux/
Here's an article on how to create a service in linux:
https://medium.com/#benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6

Related

How to always run specific python script on windows server manager 2016

i am new to the community and new in using servers and could use some help.
I am trying to setup an automatic JSON parser to another server using http post calls. The idea is as follows:
I manually put JSON files into a folder Input on the server
A python script that is always running on the server reads the files located within the folder
It reads the JSON files, posts all objects to another server, and moves the files to a "Processed" folder one file at a time.
I have been given a Windows Server, with Windows Server Manager 2016, and have managed to do the following:
installed python 3.8.2. on the windows server
able to run a python script using powershell
Installed NSSM to create a windows service
Now the windows server manager says i cannot resume or start the service that i tried to install via NSSM.
I am very new to servers, as well as python itself. Can somebody help me to get a python script running 24/7 on a windows server with windows server manager 2016?
Edit:
I managed to create a python script that can read files, upload them and move them to a processed folder, but i still have to run it by myself while i want it to always run on the server

I am having difficulty importing code from a server?

I'm working on a project for a client and his code is running on his server. I've tried to download the code so that I can run a local version on my computer. The project is at least 5 years old and runs on Python 2.7.
The problem is I can't run python install -r requirements.txt without running into errors, because some of the files are no longer available. Specifically something called "sorl", "django-page-cms", "mercurial", and a few files the developer hosted on other sites.
If his website is working & the code is functioning on his server, that means there is a working version of these packages stored on the server? How could I find them?
You can try starting python while sshed into the server and doing an import like:
>>> import sorl
>>> sorl.__file__
'/home/jmunsch/PycharmProjects/projectname/venv_ok/lib/python3.6/sorl/__init__.py'
And if the os is the same then rsync the files over.
see:
- Copying files using rsync from remote server to local machine

pyinstaller: webbrowser.open doesn't work in packaged app

I have a simple app that runs a local Flask web server and opens a web browser to show it on start up using the following command:
webbrowser.open('http://localhost:%d' % port, new=2, autoraise=True)
When I run it in development mode, this works fine. However, when it's packaged using pyinstaller and run as an executable, I get this:
gvfs-open: http://localhost:5000: error opening location: No application is registered as handling this file
The order of the browser's web browser will try is the same in both instances:
'xdg-open', 'gvfs-open', 'gnome-open', 'x-www-browser', 'firefox'
I tried using specific commands using webbrowser.get(NAME).open but none worked (except Firefox).
It seems like this is a problem with pyinstaller. Is it possible some sort of environment variables are being lost or not exported to executable?
I'm using Python 3.5.2 and pyinstaller 3.3.1 on Ubuntu 16.04 with the command
pyinstaller --add-data="static:static" app.py
EDIT: I have confirmed that the environment variables are indeed being changed:
print('XDG_DATA_DIRS: ' + os.environ.get('XDG_DATA_DIRS', 'not found'))
yields
/usr/share/ubuntu:/usr/share/gnome:/usr/local/share:/usr/share:/var/lib/snapd/desktop:/var/lib/snapd/desktop
in development mode and
SOURCE_DIR/dist/linux/app/share
in the packaged executable. I'm going to create an issue on the pyinstaller github.

Problems installing Cloud SQL Proxy on Windows 64-bit

I'm trying to install Cloud SQL Proxy for Google Cloud Platform on my Windows 10 64 bit OS, so I can use Python scripts to dump data into SQL. I'm following this guide to get it set up.
I created a project and a Google Cloud SQL instance from the Console without any issues, and it shows up in the SDK shell without any problems. After downloading the proxy installer and installing it, a dialog window opens up and then closes before I can read it.
When I go to the Google Cloud SDK shell and try to start the Cloud SQL Proxy with: cloud_sql_proxy.exe -instances="[MyInstanceConnectionName]"=tcp:3306
No matter how many times I try, it throws the error "Cloud Sql Proxy is not recognized as an internal or external command, operable program or batch file." I already tried re-downloading and re-executing the file but it still won't work.
I have Python 3.6 with Anaconda and Google Cloud SDK shell installed on Windows 10 64-bit.
When you download the cloud_sql_proxy file make sure to rename it as per instructions in the how to guide. Also make sure you save it in the root directory of where you will run it from. E.g. If you are running the command from C:/users/desktop>.\cloud_sql_proxy.exe -instances="[YOUR_INSTANCE_CONNECTION_NAME]"=tcp:3306 then the cloud_Sql_proxy file must be located in the root C drive.
Open PowerShell or whatever terminal you use and navigate to the folder you saved cloud_sql_proxy.exe then add .\ like so:
.\cloud_sql_proxy.exe -instances="[YOUR_INSTANCE_CONNECTION_NAME]"=tcp:3306
I had the same problem, and i solved it by adding .\ before
so it would be like this
.\cloud_sql_proxy.exe -instances="[YOUR_INSTANCE_CONNECTION_NAME]"=tcp:3306
and I used PowerShell instead of normal cmd
Go to folder where you save proxy exe file and run following command
.\{cloud_sql_proxy file name}.exe -instances={projectID}:{zone}:{sql instance name}:{database}=tcp:{port} -credential_file={service account file path}
For instance related detail go to the instance look for "Instance connection name"
Your command is missing .\ before cloud_sql_proxy.exe -instances="[MyInstanceConnectionName]"=tcp:3306

How to run a python script on a remote ec2 instance using sudo from pycharm

I am running pycharm 2017.2.3. I want to run my python script on a remote ec2 instance using sudo user through pycharm. How do I acieve this?
Follow the steps below:
Go to File -> Settings -> Project Interpreter and add a new interpreter
Click on + to add a new python interpreter and then click on SSH interpreter
Provide your EC2 Public DNS in HOST and ubuntu as username
Click Next and add the private_key.pem file.
See this article for more details:
PyCharm setup for AWS automatic deployment
It looks like you can configure your python interpreter over SSH with the professional version of PyCharm.
Configuring Remote Interpreter + PyCharm
Finally found an answer after a researching through the internet. We can have a script on remote machine as a pycharm interpreter. Create a following script on a remote machine and make sure the script is executable.
#!/bin/bash
sudo /usr/bin/python "$#"
Now change the project interpreter to point to the above script on remote machine in pycharm. Now every script you run on local machine gets executed on remote as a sudo user.

Categories