How to install django applications on a Memory Stick - python

I am currently developing an open source software based on python/django. The software should later be easy installable by a standard windows/linux users without any programming experiance. It should also be portable to different computers. The only installation that should be required on these computers should be python itself.
Is there a way to get this to work?
I already found this "dbuilder" Django Projects as Desktop applications : how to?
desktop-applications-how-to
It seems to be a bit outdated and not a very smooth solution.
Are there better solutions?

Just use a portable version of python on your memory stick. Make a batch file that runs
projname.bat file:
python.exe /django-app-path/manage.py runserver
now open a browser and browse for it
the default address will be:
http://127.0.0.1:8000
If you need to browse your app on other device that you're app is running:
get your server ip with
windows shell>ipconfig
linux shell# ifconfig
then run your development server on that address (in the batch file):
python.exe /django-app-path/manage.py runserver your-ip-address:port-if-not-80

Related

How to set up full access to the shared folders in Linux?

everyone.
I run Linux python scripts under Linux virtual machine. There are a few shared folders between host and guest system. Script works with files in folder mounted to guest file system through VirtualBox Tools. I have changed access mode to all files and directories in this folder. Other programs (e.g. MatLab) have full access (create or delete any file) to shared file system if I run it under super user. Python returns this error when I run shutil.rmtree(path):
OSError: [Errno 26] Text file busy
How can I share my folders without the similar problems?
Details:
Guest - Linux Ubuntu 18.04
Host - Windows 10
VirtualBox version 6.1.6 r137129
Python 3.6
I get this problem as well with shared directories. To my knowledge, there is only one solution to this: don't work with executable files in shared directories.
My understanding of the problem is that the guest operating system is trying to run your command on that file/directory while the host operating system is currently doing something with it via VirtualBox. I don't know the specifics on what exactly VirtualBox is doing in this context, but I suspect it has something to do with synchronizing the content of the files back to the host.
Probably not the answer you were hoping for, but virtual machines are meant to be entirely self-contained, so using shared directories should probably be avoided. If your code is version controlled using something like Git, try cloning the repository into the virtual machine instead.

How to connect local PyCharm to python installed on a server? Is this even possible?

I have PyCharm on my machine (8GB RAM). I am required to to heavy data processing, and would like to use an institutionally provided server. This server has Python installed, but without any IDE. So all I see is a CUI, and it is difficult to program in such an environment.Also note that I cannot ask server admin to install software on the server for me. So, how can one connect one's local PyCharm to a python installed on a remote server? Is this even possible?
You can configure an interpreter using SSH:
Open the Add Python Interpreter dialogue
In the left-hand pane of the Add Python Interpreter dialogue, click SSH Interpreter.
Follow the wizard.
For more detailed instructions, check:
https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html
Note: unfortunately, this option is not available in the PyCharm Community Edition.

Visual Studio Code use on remote files

Is there any way to use the python extension to edit files that reside on a remote server? I have tried NFS and remoteFS, but I do not see any way to get Intellisense working using the remote installation. I normally edit and test on a windows machine, while the target runs on Linux.
I realise this is not limited to this extension, but is a more general issue.
Visual Studio Code now officially supports this using an Extension: Remote SSH
Read the release notes here: https://code.visualstudio.com/blogs/2019/05/02/remote-development
Today we're excited to announce the preview of three new extensions for Visual Studio Code that enable seamless development in Containers, remotely on physical or virtual machines, and with the Windows Subsystem for Linux (WSL). You can get started right away by installing the Remote Development Extension Pack.
As a workaround, I'm using a Linux Hosted virtual machine which has a similar setup as the target. This works surprisingly well. It is a shame VMware 12 removed support for unity.
I use SSHFS (wikipedia) (github repo)
sshfs OWN_USER#SERVER:/PATH_TO_FILES/ MOUNT_POINT
This makes the remote files visible to any program on your computer, as-if they were local files, through a virtual "FUSE" filesystem.
If your own user can't access the files (you need root or some other user), you can sudo like so:
sshfs -o sftp_server="sudo -u SYSTEM_USER /usr/libexec/openssh/sftp-server" \
OWN_USER#SERVER:/PATH_TO_FILES/ MOUNT_POINT
You can install sshfs for Linux, Mac, or Windows, check out Digital Ocean's guide in my first link.
Don't forget to umount, fusermount -u, or eject that MOUNT_POINT once you're done.
I don't know if other VS Code plugins like IntelliSense would work with this. They should because the sshfs makes the files visible just like any others. But, it would require that the python tool chain you have installed locally be the same on your laptop and on the server. It'd be interesting to find out.
Or, Microsoft just announced some new plugins on the way
Yes there are some. I used this one. It allows to synchronize code between local and remote server.
You will have to keep copy on local host and it can be configured to automatically update code on remote.
https://gurumantra.themillennialpost.info/2020/05/edit-linux-files-remotely-in-vscode.html
Download and install vscode in your localPc if you don’t have it. (click here to download vscode)
Summary :
Install Vscode, remote vscode – LocalPC
Install ssh and Rmate – RemotePc
Ready to access files/data
Detailed Steps:
https://gurumantra.themillennialpost.info/2020/05/edit-linux-files-remotely-in-vscode.html

Application on Raspberry Pi (Linux) with OpenCV that autostarts

I have used OpenCv within my Windows applications in the past and in this case, an application would be built and installed as a Windows Service so that it could be set to start automatically and start running. Differences are I have done these in compiled languages and we were on Windows.
Now, I am playing around with porting the application to run on Linux/Raspberry Pi. The application simply gets a video feed, does some object detection using OpenCv and then sends result via HTTP web api.
First comment before my question is (I am still getting familiar with this setup) it seems that Python is by far the language of choice for all of this. However, the end goal is to have this device be headless (no monitor or input devices and act like an IoT device) so I don't need or better, can't open a console and type commands.
So, for the question, what is the equivalent to a Windows Service on Raspberry Pi so that my application just starts up on boot and runs as long as the device is on? The subjective follow up question is Python still a good choice considering everything I have described above or would I be better off doing a full blown compiled app in c or c++?
Thanks!
If you are using Raspbian, then I would say the easiest tool il systemd (daemon) and the systemctl (shell command).
In order to run your python script as a daemon (a daemon is what Windows calls "Service") is to create a configuration file named .service and put it in the /etc/systemd/system path.
To get an idea of how to configure the file, you can take this example:
[Unit]
Description=Your service name
[Service]
ExecStart=python <path to python script>
StandardOutput=null
[Install]
WantedBy=multi-user.target
Alias=this_script_name>.script
Hope it helps!
Check out Supervisor: http://supervisord.org/. It should do what you need to do in terms of running your program on boot and restarting if it crashes, etc.
I don't have any experience with OpenCV, but web app frameworks like Flask (http://flask.pocoo.org/) make it very easy to expose an HTTP API with minimal code.
Good luck!

How can I create an local webserver for my python scripts?

I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.
I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network.
Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either.
Or am I missing something obvious?
Don't waste a lot of time creating Windows service.
Don't waste a lot of time on Windows Apache.
Just make a Python service that responds to HTTP requests.
Look at https://docs.python.org/2/library/basehttpserver.html
https://docs.python.org/3/library/http.server.html for version 3
Python offers an HTTP server that you can extend with your server-side methods.
Look at http://docs.python.org/library/wsgiref.html
Python offers a WSGI reference implementation that makes your server easy and standards-compliant.
Also http://fragments.turtlemeat.com/pythonwebserver.php
"I'm trying to avoid making the user run python stuff from the command prompt."
I don't see how clicking a web page is any different from clicking desktop icons.
Starting a web server based on Python is relatively easy, once you have the web server. First, build the server. Later, you can make sure the server starts. Let's look at some ways.
Your user can't use a random browser to open your local page. They need a bookmark to launch "localhost:8000/myspecialserverinsteadofthedestop/" That bookmark can be a .BAT file that (1) runs the server, (2) runs firefox with the proper initial URL.
You can put the server in the user's start-this menu.
You can make your Python program a windows "service".
Best way is to make your own local server by using command prompt.
Make a new folder say Project
Make a new folder inside project & name it as "cgi-bin"(without quotes)
Paste your .py file inside the cgi-bin folder
Open cmd and change to the directory from which you want to run the server and type "python -m CGIHTTPServer"(without quotes)
Minimize the cmd window & open your browser and type "localhost:8000/cgi-bin/yourpythonfilename.py"(without quotes).
The wasiest step would be navigate to folder where your files are located and running http.server module
cd /yourapp
python3 -m http.server
the you should see something like this in console
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Running a native python webserver as a windows service should be a no brainer. Check out the documentation for writing windows services (win32api, ActiveState python) in python and also the documentation for subclassing BaseHttpServer and SimpleHttpServer.
BTW: I had a similar question on stackoverflow: How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?
Basically, you subclass BaseHTTPServer (you have to anyway...) and then... but just read the accepted answer - it set me on the right track!

Categories

Resources