Python Forum
Is it possible to import / run compiled Python (.pyd) file in web browser?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to import / run compiled Python (.pyd) file in web browser?
#1
Hi,

I am new to Python and am trying to import a compiled Python library file (.pyd) into a Python script in a web browser. I have been trying to do this with Brython but have found that it is not possible in that environment. Brython cannot parse / execute compiled Python.

My problem is that I don't know if it's just Brython that this can't be done in or if it is just not possible in a web browser at all. I can find references to how the generic Python include will look for .py, .pyc and then .pyd extensions, but I cannot find anything online that deals with how to do it in a web browser, or indeed if it can even be done in a web browser. This leads me to suspect maybe it is not possible?

Please could someone let me know - is it possible to include a compiled python (.pyd) file into a web-browser Python script? If it is, please could someone point me in the right direction? I am not looking for a solution or finished code or anything - I'm happy to do tons of research and coding - I just need help getting started as I've drawn blanks so far.

Thanks in advance.
Reply
#2
From my understanding, a pyd file is basically a windows DLL. It doesn't make sense to me to try to force a DLL to work in a browser - I use OS X at work, Linux at home, and Android on mobile, so what you're doing wouldn't be accessible at all to someone like me.
Reply
#3
Hi,

It's a compiled file which contains functionality that the browser app needs. The user base is exclusively running Windows PCs, so there won't be the case of someone on OS-X, Android or whatever trying to use the browser app.

I'd agree that in most circumstances it doesn't seem like a sensible thing to want to do, but in this instance it is a valid requirement - honest! Smile

Aside form wisdom or otherwise of doing it, can it actually be done?

Thanks!
Reply
#4
dvid Wrote:Aside form wisdom or otherwise of doing it, can it actually be done?
They more normal way is to have python code on server side,
then send or call(using eg jinjaAjax) that code on client side.

I have a tutorial about this here,
so the point is to throw away the JavaScript code(that can run in Browser)
and do the same with Python code.
Doing a Ajax call to Python function server side,
so for the user in browser there is no diffidence as JavaScript and Python is doing the same task here.
Reply
#5
In order for your code to show, you need several things:

Firstly, there needs to be a server that handles HTTP requests. At the moment you are just opening a file with Firefox on your local hard drive. A server like Apache or something similar is required.

Secondly, presuming that you now have a server that serves the files, you will also need something that interprets the code as Python code for the server. For Python users, the go-to solution is nowadays mod_wsgi. But for simpler cases, you could stick with CGI (more info here), but if you want to produce web pages easily, you should go with an existing Python web framework like Django.

Setting this up can be quite the hassle, so be prepared.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a Browser Extension using Python j49857 3 826 Feb-13-2024, 10:49 PM
Last Post: j49857
  webdriver.remote to connect back existing browser without open new browser? gahhon 6 6,653 Feb-26-2019, 03:53 PM
Last Post: gahhon
  Enable error logging to browser for Python's Flask under Apache + mod_wsgi nikos 1 3,017 Sep-18-2018, 09:15 PM
Last Post: nikos

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020