Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 12 months ago.
Improve this question
I want to access files in my local machine by using urls. For example "file:///usr/local/home/thapaliya/constants.py". What would be the best way to achieve this?
Use simple HTTP server:
python -m http.server 8000
Or for Python 2:
python -m SimpleHTTPServer 8000
https://docs.python.org/3/library/http.server.html
I copied from orszacky's answer for the similar question:
A little http server locally.
For Windows, the easiest is to install http-server globally using node's package manager:
npm install -g http-server
Then simply run http-server in any of your project directories:
C:\my_project> http-server
You can also use Python in Windows, and follow the instruction below:
For Linux, since Python is usually available in most Linux distributions,
run python -m SimpleHTTPServer
in your project directory, and you can load your page on http://localhost:8000
In Python 3 the SimpleHTTPServer module has been merged into http.server, so the new command is
python3 -m http.server.
Had the same need and have been searching for something simple but more versatile than python's built-in HTTP server (which is meant for debugging only and can't do range requests, i.e. doesn't handle streaming video properly).
Ended up writing a simple Web UI wrapper for caddy2 which relies on caddy's ability to return directory listings as JSON so the entire logic is browser-side. The main intent is to support audio/video playing in one frame while browsing related HTML/PDF or text in another split frame (there is some simple mapping with regexes for matching multimedia files with the related text files).
https://github.com/glowinthedark/mediabro4caddy
The old and currently unmaintained version is using python's built-in HTTP server which was extended to support range requests.
keep the files in a some folder which you want to access from a localhost
In command prompt go to that location and type
python -m http.server 8080
now type localhost :8080 in browser you will able to access files in that folder
if u want to use some js files for paticular html files then
<script src="http://localhost:8080/main.js"</script>
make sure you run this program on another port
Related
We have a Python application that runs on a single server (the master), and that is copied to multiple other servers via rsync (the nodes), in an all Ubuntu environment. Currently we have to login to each server when any Python changes include any new libraries, so we have to go to each server, login via SSH, and python3.7 -m pip install whatever. What is the pythonic way to do this so that it’s possible to efficiently clone a python application including new libraries?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
So my office has a company server to which all computers are connected. I've written a Python script which I would like to make available to all people in the office. Is there a way to install Python directly on this server such that this is possible?
Now, I know what you're thinking: make it an executable. I've tried that using py2exe and its just been a miserable failure. The executable it makes is slow, glitchy, and I have to jump through a ton of hoops just to get it to the barely functional state I've managed. The biggest issue is the use of modules which my program edits. To get these to update I have modify a zip archive which does not happen reliably. Installing Python to the server is the best workaround I can come up with for py2exe. I am asking if it is possible and, if yes, how to do it. If it's not, I'd love to hear whatever workaround y'all can come up with.
EDIT: Things I forgot so say, the server is Windows 64-bit, and I would prefer to not modify it directly (ie, I would like to do everything from my computer if possible)
Things I tried:
Installing vanilla Python directly onto the server. This didn't work since the actual dlls were not accesible to other machines on the LAN
Setting up path variables through the network to a machine which has Python installed. This didn't work because of firewalls on the network and such.
Since your trying to run py2exe, I'll assume windows clients for the following.
If they don't have python on their local system you can make a server share and serve out python from that location.
You can run this line in a .bat file
\\server\share\distribution\python.exe \\server\share\scripts\my_script.py
On a UNIX system:
ssh user#server-ip-address python path/to/myscript.py
If you run a *nix environment then the best way would be to use SSH. If you don't use unix then you can still run an SSH server and clients on Windows, it is just slightly more painful.
Virtual machines can also be an option.
Depending on the application, it may work as a web application. In which case look into create a web application with Python (there are many tutorials out there).
Edit: So for an SSH server, it basically gives you command line access to a remote machine. If you are on windows you need to install an SSH server. If you are on *nix then you probably have one installed. On the client if it's Windows, you install an app like Putty which allows you to initiate the connection. On a *nix machine you run something like:
ssh username#serveraddress
And you will get a connection. Then you just browse and run the programs as you normally would at a command line.
I have a small application written in python using TwistedWeb. It is a chat server.
Everything is configured right now as for localhost.
All I want is to run this python script on a server(shared server provided by Fatcow.com).
I mean that the script will be working all the time and some clients will connect/disconnect to it. Fatcow gives me python 2.5 without any custom libraries. Is there a way and a tutorial how to make it work with TwistedWeb?
Thanks in advice.
the easy_install/pip modes of installation are very likely to fail because of broken dependencies. You will have to download the tar and build it yourself. See the attached link for more info on installing the same on CENTOS.
http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#CanIinstallTwistedusingeasy_installorpip
I have contacted Fatcow.com support. They do not support SSH connections and do not support Python 2.7 with Twisted library, especially python socket application as server. So it is dead end.
Question resolved.
I am attempting to make a dynamic website for a school project. The problem is it has to be on the school server and I can't use any webframeworks. I have searched through google and stackoverflow but I can't seem to get an answer.
I have tried the code that was provided here:
How to implement a minimal server for AJAX in Python?
It worked on the local server but how can I change it so that it would open on the school server. When I used those codes, the page won't load or an internal error shows. Can someone point me in the right direction?
Using a web framework in python does not necessary needs a system package installation (like running a sudo apt-get install python-something).
In the end python frameworks are just files like in your project, but you can install them system wide (like in the apt-get example) or ship them within your project (probably what you want). Take a look at virtual environment for creating a self contained environment and setuptools foi packaging the application and its dependencies
For implementing an ajax server directly in python without a wsgi container (apache, nginx, etc) I recommend using flask. It is very, very simple and very powerful
For very simple, internal web-apps using ASP I was able to just switch IIS 'on' and then write some ASP scripts in the www directory that would start working immediately.
Is there an equivalent webserver app for Python scripts that I can run that will automatically start serving dynamic pages (python scripts) in a certain folder (with virtually no configuration)?
Solutions I've already found are either too limited (e.g. SimpleHTTPRequestHandler doesn't serve dynamic content) or require configuring the script that does the serving.
There's always CGI. Add a script mapping of .py to "C:\Python27\python.exe" -u "%s" then drop .py files in a folder and IIS will execute them.
I'd not generally recommend it for real work—in the longer term you would definitely want to write apps to WSGI, and then deploy them through any number of interfaces including CGI—but it can be handy for quick prototyping.
For development or just to play around, here's an example using the standard Python library that I have used to help friend who wanted to get a basic CGI server up and running. It will serve python scripts from cgi-bin and files from the root folder. I'm not near a Windows computer at the moment to make sure that this still works. This also assumes Python2.x. Python 3.x has this, it's just not named the same.
Make a directory on your harddrive with a cgi-bin folder in it (Ex. "C:\server\cgi-bin")
In a command window, navigate to "C:\server" directory
Type the following assuming you've installed python 2.7 in C:\Python27:
"c:\python27\python.exe -m CGIHTTPServer"
You should get a message like "Serving HTTP on 0.0.0.0 port 8000"
Linux is the same - "python -m CGIHTTPServer" in a directory with a cgi-bin/ in it.
WSGI setups are fairly easy to get started, but in no anyway turn key. django MVC has a simple built in development server if you plan on using a more comprehensive framework.
My limited experience with Python web frameworks has taught me that most go to one extreme or the other: Django on one end is a full-stack MVC framework, that will do pretty much everything for you. On the other end, there are Flask, web.py, CherryPy, etc., which do much less, but stay out of your way.
CherryPy, for example, not only comes with no ORM, and doesn't require MVC, but it doesn't even have a templating engine. So unless you use it with something like Cheetah, you can't write what would look like .asp at all.