How to Launch streamlit local server from within nativefier - python

This excellent thread Streamlit Deployment as an Executable File
shows how to deploy a website as an executable using the smart-tool, nativefier.
nativefier --name appname http://localhost:8501 --platform windows \
--icon ../apps/icon.ico --clear-cache --single-instance
The command above generates an executable appname.exe which when double-clicked will open localhost:8501, or other website indicated by the url-link above.
For a website on localhost, you need to start the local server beforehand. This issue on nativefier github issue # 639 implies I should be able to start the local server before I navigate to localhost:8501. However, the link is broken and I cannot locate the info on nativerfier's docs.
I simply would like to start the streamlit local server:
streamlit run app.py --server.headless true
before navigating to the localhost:8501 using the executable generated by nativefier. thanks for any pointers.

Related

How to create a setup file that run on hosted server 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

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.

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.

Azure msdeploy Python App Service

I'm trying to deploy an Azure App Service running Flask on Python 3.4. When I deploy from within Visual Studio (2015) via Web Deploy, everything works nicely. But, when I attempt to deploy from my CI/CD server (TeamCity 10.0.3 on Windows Server 2012 R2) using an MSBuild step, the deployment succeeds without errors, but my app is apparently missing some crucial components and just throws HTTP errors on every request (my logging isn't able to capture the actual errors because the app is apparently totally hosed at this point). I'm deploying numerous C# applications from this TeamCity instance using Web Deploy without fail. My build has the following steps:
Command Line Runner - Copy publish profile (because msdeploy looks for it at ~/__profiles for some unknown reason and I can't find a flag or configuration setting to change):
mkdir __profiles
copy *.pubxml __profiles
Command Line Runner - Create venv at top level folder:
c:\python34\python.exe -m venv env
Command Line Runner - Install from requirements.txt:
env\scripts\pip install -r requirements.txt
Powershell Runner - Stop Azure App Service
MSBuild Runner - Deploy (Build file path points to the .pyproj file):
/p:DeployOnBuild=true
/p:PublishProfile="My Publish Profile"
/p:Configuration=Release
/p:AllowUntrustedCertificate=True
/p:UserName=%WebDeployUserName%
/p:Password=%WebDeployPassword%
Powershell Runner - Start Azure App Service
Related GitHub Issue

PyDev: Running Code in local machine to remote machine

Would you please let me know, how would I run my code in local machine to remote server?
I have source code and data in local machine. But I would like to run the code in remote server.
One solution would be:
Install python on the remote machine
Package your code into a python package using distutils (see http://wiki.python.org/moin/Distutils/Tutorial). Basically the process ends when you run the command python setup sdist in the root dir of your project, and get a tar.gz file in the dist/ subfolder.
Copy your package to the remote server using scp, for example, if it is an amazon machine:
scp -i myPemFile.pem local-python-package.tar.gz remote_user_name#remote_ip:remote_folder
Run sudo pip install local-python-package.tar.gz on the remote server
Now you can either SSH to the remote machine and run your code or use some remote enabler such as fabric to start commands on the remote server (works for any shell command, specifically python scripts)
Alternatively, you can just skip the package building in [2], if you have a simple script, just scp the script itself to the remote machine ane proceed using a remote python myscript.py
Hope this helps
I would recommend setting up git repository on repote server and connect local source (for git you can read about how to do it here: http://git-scm.com/book).
Then you can use i.e. Eclipse EGit and after you change your local code you can push it to remote location.

Categories