Can't import io using Python for Workers

I completed all of the normal setup for using Python with workers and got the base “Python Hello World” working, but running my own code which utilizes “import io” is throwing some errors. I’ve been able to edit the py file and publish that as well with some other random text tests, so I know the error has to do with how this is importing modules.

I run the following in my index.py:

import sys
import io
import pandas as pd
import numpy as np

I’ve tried re-running pip install ____ and that works for some of them, but installing io is not possible as it’s built in.

And get the following errors:

    Error while compiling (offending file last):
    	File '/Users/username/worktest/index.py', line 11, at import of:
    	File '/Users/username/worktest/env/lib/python3.7/site-packages/numpy/__init__.py', line 293, at import of:
    	File '/Users/username/opt/anaconda3/lib/python3.7/os.py', line 1026, at import of:
    	File 'io', line 95, namely:
    	
    	Import error, can't find any of:
    		/Users/username/worktest/_io/_WindowsConsoleIO.py
    		/Users/username/worktest/_io/_WindowsConsoleIO.js
    		/Users/username/worktest/env/lib/python3.7/site-packages/transcrypt/modules/_io/_WindowsConsoleIO.py
    		/Users/username/worktest/env/lib/python3.7/site-packages/transcrypt/modules/_io/_WindowsConsoleIO.js
    		/Users/username/worktest/_io/_WindowsConsoleIO.py
    		/Users/username/worktest/_io/_WindowsConsoleIO.js
    		/Users/username/opt/anaconda3/lib/python3.7/_io/_WindowsConsoleIO.py
    		/Users/username/opt/anaconda3/lib/python3.7/_io/_WindowsConsoleIO.js
    		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/_io/_WindowsConsoleIO.py
    		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/_io/_WindowsConsoleIO.js
    		/Users/username/worktest/env/lib/python3.7/site-packages/_io/_WindowsConsoleIO.py
    		/Users/username/worktest/env/lib/python3.7/site-packages/_io/_WindowsConsoleIO.js
    		/Users/username/worktest/_io.py
    		/Users/username/worktest/_io.js
    		/Users/username/worktest/env/lib/python3.7/site-packages/transcrypt/modules/_io.py
    		/Users/username/worktest/env/lib/python3.7/site-packages/transcrypt/modules/_io.js
    		/Users/username/worktest/_io.py
    		/Users/username/worktest/_io.js
    		/Users/username/opt/anaconda3/lib/python3.7/_io.py
    		/Users/username/opt/anaconda3/lib/python3.7/_io.js
    		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/_io.py
    		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/_io.js
    		/Users/username/worktest/env/lib/python3.7/site-packages/_io.py
    		/Users/username/worktest/env/lib/python3.7/site-packages/_io.js


    Aborted


    👀  ./index.py
    Module build failed (from ./node_modules/transcrypt-loader/__target_es5__/index.js):
    Error: Command failed: python3 -m transcrypt --nomin --map --verbose "index"
        at checkExecSyncError (child_process.js:630:11)
        at Object.execSync (child_process.js:666:15)
        at Object.main (/Users/username/worktest/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.

issue is also present for importing sys, since both aren’t found in pypi

http://www.transcrypt.org/docs/html/special_facilities.html#transcrypt-s-module-mechanism

https://transcrypt.org/numscrypt/docs/html/what_why.html

http://www.transcrypt.org/docs/html/supported_constructs.html#module-builtin-a-small-part-of-it-demo-ed

1 Like

Already looked through the first two and just read through the third — still doesn’t look like there’s a solution aside from manually downloading and placing those modules, but I ended up getting around this by reworking the code itself to not depend on those modules. Might be worth looking into for future use though.

I was able to resolve most of the errors but one still persists with Pandas. I’ve installed it but a lot of errors appear. Here is one of them:

Import error, can't find any of:
    		/Users/username/my-python-project/pandas/io/formats/format/_get_format_timedelta64.py
    		/Users/username/my-python-project/pandas/io/formats/format/_get_format_timedelta64.js
    		/Users/username/my-python-project/ev2/lib/python3.7/site-packages/transcrypt/modules/pandas/io/formats/format/_get_format_timedelta64.py
    		/Users/username/my-python-project/ev2/lib/python3.7/site-packages/transcrypt/modules/pandas/io/formats/format/_get_format_timedelta64.js
    		/Users/username/my-python-project/pandas/io/formats/format/_get_format_timedelta64.py
    		/Users/username/my-python-project/pandas/io/formats/format/_get_format_timedelta64.js
    		/Users/username/opt/anaconda3/lib/python3.7/pandas/io/formats/format/_get_format_timedelta64.py
    		/Users/username/opt/anaconda3/lib/python3.7/pandas/io/formats/format/_get_format_timedelta64.js
    		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/pandas/io/formats/format/_get_format_timedelta64.py
    		/Users/username/opt/anaconda3/lib/python3.7/lib-dynload/pandas/io/formats/format/_get_format_timedelta64.js
    		/Users/username/my-python-project/ev2/lib/python3.7/site-packages/pandas/io/formats/format/_get_format_timedelta64.py
    		/Users/username/my-python-project/ev2/lib/python3.7/site-packages/pandas/io/formats/format/_get_format_timedelta64.js

There are a lot of errors outputted along these lines, unable to find some package even though it exists in those directories.