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

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.

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

app.windows() returning empty list when application is started in virtual environment

Tried to automate postman application using pywinauto in python virtual environment
from pywinauto import Application, Desktop
filePath = <FilePath>
app = Application(backend='uia').start(filePath, timeout=10)
print(app.windows())
Everytime I execute this code I am getting empty list output and the application is opening as GUI
Can someone explain why the strange issue happening and this is not happening in normal environment(not a virtual env)
support you can use subprocess module to start the process first, then use desktop automation library to recognized the control and do operation.

How to Launch streamlit local server from within nativefier

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.

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.

Local Django server cannot connect when run through Bash on Windows

I recently realized that I could use Bash for Windows as the terminal for use in Pycharm so that the IDE had a proper terminal in it even through it was in Windows. I want to work on a Django project but I realized something strange. When I run the server through the IDE's run button, everything runs as expected. However, when I try to run the server through the command line via
python3 manage.py runserver,
the terminal output is the same, but my browsers cannot connect. Instead they say that the connection was reset. I have full installations of Django and Python for both Windows and the Bash environment and both seem to be fully functional. I can make migrations and create new apps through the command line just fine, but I was wondering if anybody else knew why the Django Server does not connect when run through Bash on Windows

Categories