I was excited to see the Python hello world template now available in the template gallery (GitHub - cloudflare/python-worker-hello-world: Python hello world for Cloudflare Workers ) , however I had issues compiling it.
I followed the instructions, created the virtual environment, activated it, installed transcrypt, but ran into a few issues when running wrangler publish
I’ve detailed the issues in the Github repo:
opened 03:18AM - 27 Jul 20 UTC
closed 08:39PM - 31 Jul 20 UTC
I've installed virtualenv, and transcrypt within that env, however, wrangler pub… lish seems to be running a command that fails
```
⬇️ Installing wranglerjs...
⬇️ Installing wasm-pack...
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640Error compiling C:\Users\admin\wranglers\pythonhelloworld\index.py:
./index.py
Module build failed (from ./node_modules/transcrypt-loader/__target_es5__/index.js):
Error: Command failed: python3 -m transcrypt --nomin --map --verbose "index"
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
at checkExecSyncError (child_process.js:611:11)
at Object.execSync (child_process.js:647:15)
at Object.main (C:\Users\admin\wranglers\pythonhelloworld\node_modules\transcrypt-loader\__target_es5__\index.js:56:67)
Error: webpack returned an error. Try configuring `entry` in your webpack config relative to the current working directory, or setting `context = __dirname` in your webpack config.
```
On Windows 10, it's normal for python3 to be ran as `python`, when it's installed from the installer from https://www.python.org/downloads/
How can I force wrangler to use `python` instead of `python3`?
opened 03:47AM - 27 Jul 20 UTC
closed 08:49PM - 31 Jul 20 UTC
I managed to bypass https://github.com/cloudflare/python-worker-hello-world/issu… es/1 by deleting the fake Windows 10 python3 (that redirects to Windows Store), and making a copy of python.exe as python3.exe (dirty hack)
However, `wrangler publish` seems to be failing still
```
C:\Users\admin\wranglers\pythonhelloworld>wrangler publish
⬇️ Installing wranglerjs...
⬇️ Installing wasm-pack...
./index.py
Module not found: Error: Can't resolve './__target__index.js' in 'C:\Users\admin\wranglers\pythonhelloworld'
resolve './__target__index.js' in 'C:\Users\admin\wranglers\pythonhelloworld'
using description file: C:\Users\admin\wranglers\pythonhelloworld\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\Users\admin\wranglers\pythonhelloworld\package.json (relative path: ./__target__index.js)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Users\admin\wranglers\pythonhelloworld\__target__index.js doesn't exist
.wasm
Field 'browser' doesn't contain a valid alias configuration
C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.wasm doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.json doesn't exist
as directory
C:\Users\admin\wranglers\pythonhelloworld\__target__index.js doesn't exist
[C:\Users\admin\wranglers\pythonhelloworld\__target__index.js]
[C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.wasm]
[C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.mjs]
[C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.js]
[C:\Users\admin\wranglers\pythonhelloworld\__target__index.js.json]
@ ./index.py 1:0-38 1:0-38
Error: webpack returned an error. Try configuring `entry` in your webpack config relative to the current working directory, or setting `context = __dirname` in your webpack config.
```
I managed to work around issue 1 with a dirty hack, but issue 2 I have no idea what to do
Judge
July 27, 2020, 2:23pm
2
I don’t think it’s particularly ready for use yet, especially since the feature hasn’t been generally announced yet (only referenced):
This week we’ll be announcing support for Python, Scala, and Kotlin. We want to make sure you don’t have to learn a new language and a new platform to get the benefits of Cloudflare Workers. (I’m still pushing for Perl support.)
I assumed it would be ready if it was in the template gallery
Seems like they have officially announced this now
Today, we’re excited to announce support for Python, Scala, Kotlin, Reason and Dart. You can build applications on Cloudflare Workers using your favorite language starting today.
I agree there are issues with path handling for python, virtualenv, and webpack transcrypt-loader on windows 10. This is not an issue specific to wrangler (all wrangler is doing in this case is calling webpack). I’ll look for workarounds. In the meantime have you tried using Windows Subsystem for Linux?
2 Likes
Workaround added to the readme and the issue linked in the original post