我正在尝试导入 sys 和 io:
import sys
import io
但我收到以下错误:
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.
我正在尝试使用 Transcrypt 和 Wrangler 让我的 Python 脚本在 Cloudflare 的 Workers 上运行,但是无法导入这些模块(pypi 上不存在)的问题阻止了我这样做。
在 pypi 中是否有任何替代方案可供我使用?如果没有,我如何在我的路径中本地安装它们。
它们的实际用法如下:
old_stdout = sys.stdout # Memorize the default stdout stream
sys.stdout = buffer = io.StringIO()
for row in query_job:
# Row values can be accessed by field name or index.
print("col1={}, col2={}, col3={}".format(row[0], row[1], row[2]))
sys.stdout = old_stdout # Put the old stream back in place
out1 = buffer.getvalue() # Return a str containing the entire contents of the buffer.
执行该操作以收集 Google BigQuery 查询的输出。这最终成为我能找到的实际检索输出的最简单方法,但我也愿意改变它。