I talk about this allot in Comments but the Truth is I was always more of a Python Dev I am sure some people can relate & It randmly does things I never asked for Like when I tried to make a simple python script it made a snake game in Js
Yeah, I noticed that the formatting is a little off with building Node/JS code, so that will likely cause issues with Python code formatting, for one. I also find that a lot of these models are better at JS and maybe simple Python.
As you try to do compound logic, the code the AI produces quickly goes downhill. I do a bit of code in both Angular and Python for work. I love Python but sadly trying to AI to help has sadly and utterly frustrated me at times.
A lot of what I do is write Toolboxes for ESRI ArcGIS Pro and I’m not sure if it’s just bad documentation or lack of training, but it makes so much crap up, it’s near impossible to use. There are those times that it helps though. Hopefully it gets a lot better.
What AI Model(s) are you trying to use?
Once we reach all our initial development goals maybe we can focus on other languages. but yes the formatting can get in the way. and the webcontainer does not support any python native libraries like matplotlib or numpy etc…
unlike JS where most of the libraries are pure js code, for python majority of the code is actually a c code running in the background and that can be challenging as every of these code needs to be compiled into web assembly to make it work in browser
Yeah, adding this functionality to Python isn’t likely as there hasn’t been changes to RustPython (the Python version integrated into the WebContainer) in about a year (when I believe they had a presentation). And while possible, it would be an undertaking.
Sorry, this got me thinking. Not sure RustPython is “compatabile” but I’ve done something like this with normal and embedded python. And I’ve done it for servers I can’t “install” on using pip, etc.
My Thought: I could build a “fake” pip install function (written in JavaScript) that grabs the package from PyPi (pure python, no binaries, in tar file), downloads it, extracts to the system directory that is added to the path variable (would just have a default set/assumed already). That should allow them to work through RustPython (assuming it can find the .py files to import). And sure, not EVERYTHING would work, but many “should”.
More complicated modules and those with advanced pathing and import logic will have issues, and also those that are compiled into binaries for performance reasons. But if I were to take a guess, 75% of most PyPi/Pip packages should/might work.
Thoughts?
Please tell me if I’m being dumb before I attempt testing this, lol!
no I thing this is a great idea, we can test this out
I will test it out tonight. It’s honestly simple (prototype at least), hence why I’m hesitant to think it will work. And there will definitely be issues… but could be a start. I’ll follow up with an in-depth article by Friday (got work and other obligations). Could be my new Python dev environment, pretty cool I have to say (RustPython does seem pretty fast compiled in Wasm).
Update: Eh, just had to try it out. It kind of works.
Before:
After:
node pip.js install requests
I still have to work on the pathing logic but it downloaded and wrote the module source to “/tmp/site-packages” but I need to account for structure (actual module is in /path/to/download/src folder). So I had to move it out, but final version would account for that. But proof of concept does install modules and import works.
Also, I used AI to boilerplate things which is awesome, but the Python formatting is wrong… the first line is right and each line after has an extra indent. Same for JS files and whatnot, but it’s only an “issue” for python arguably. Not a huge deal, definitely made for a quick prototype. The future man!
Request module now works (needs a lot of testing).
Would need to then add an alias for “pip” → pip.js and a bunch more of passthrough flags/logic… but very cool, lol.
And others are working.
And @bencode549, sorry for hijacking your thread as this does not address the original problem.
This is awesome!!! Love this
Put this file in the bin folder remove the extension and add a shebang line the you can directly use pip instead of node pip.js
Checkout the npm code in the bin for reference
What would pip install pip do? Lol
I mean would “real” pip work if fake-pip installed it?
My guess is not because the WebContainer has limited permissions (would have to write somewhere that has access). Might be possible to modify this behavior but not sure yet, or if it’s even worth it. I used /tmp for that reason.
I’ll need to build a plan/project on this and test out more later.
I might be submitting a PR for it soon, lol.
Thanks for the idea!
Permission error:
I would have to modify this in the base code itself.
Using alias, it works (but need to handle pathing):
Maybe PM me with thoughts moving forward with this? Or maybe some of us could have a discussion?
As far as I know WebContainer do not support binaries.
Python will not run in WebContainers in that sense.
This ties into discussions of replacing WebContainers with something that can support both node and python.
Yesterday OpenAI announced Python Execution in Browser for ChatGPT Canvas.
I am making a video about it and made a blog post today
It uses Pyodide — Version 0.26.4 to run Python in browser.
And honestly its pretty bad.
That environment does not support many things.
It will definitely not work well for Bolt.
So I understand desire for Python but its quite a huge undertaking to support it in a way in which WebContainers work.
We would need help from people who know how to run python in browser.
Actually, they seem to have pretty good support:
“Any pure Python package with a wheel available on PyPi is supported. Many packages with C extensions have also been ported for use with Pyodide. These include many general-purpose packages such as regex, PyYAML, lxml and scientific Python packages including NumPy, pandas, SciPy, Matplotlib, and scikit-learn.” – pyodide/pyodide: Pyodide is a Python distribution for the browser and Node.js based on WebAssembly
And I just tested it out, a lot of modules you usually have to install are included. So, at this stage, it’s way better than RustPython (support wise) that is included in the WebContainer.
And their license, issued under the “Mozilla Public License 2.0”, is pretty permissive too. They only want to protect their "patent or trademark"
, which is reasonable.
yes pyodide has lots of binaries compiled into assembly… but again it will be difficult to work along with webcontainer
I don’t think it will work along at all.
One needs to figure out how to run backends inside of it that can serve pages somehow.
Including complex things like sockets and stuff.
I think that ability for WebContainer to transparently look like a server for browser is most interesting thing about it.
agree the networking part is really nicely done