简体   繁体   English

通过 repl 导入很好,但会中断脚本

[英]import through repl is fine but breaks from script

I have the following test1.py script:我有以下test1.py脚本:

import tfrecorder

If I run it, it fails:如果我运行它,它会失败:

I have no name!@519b05bc3bf9:/test$ python test1.py 
2021-10-26 00:22:56.863971: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-10-26 00:22:56.863989: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "test1.py", line 1, in <module>
    import tfrecorder
  File "/usr/local/lib/python3.7/site-packages/tfrecorder/__init__.py", line 19, in <module>
    from tfrecorder import accessor
  File "/usr/local/lib/python3.7/site-packages/tfrecorder/accessor.py", line 28, in <module>
    from tfrecorder import converter
  File "/usr/local/lib/python3.7/site-packages/tfrecorder/converter.py", line 27, in <module>
    import apache_beam as beam
  File "/usr/local/lib/python3.7/site-packages/apache_beam/__init__.py", line 104, in <module>
    from apache_beam import coders
  File "/usr/local/lib/python3.7/site-packages/apache_beam/coders/__init__.py", line 19, in <module>
    from apache_beam.coders.coders import *
  File "/usr/local/lib/python3.7/site-packages/apache_beam/coders/coders.py", line 43, in <module>
    from future.moves import pickle
  File "/usr/local/lib/python3.7/site-packages/future/moves/__init__.py", line 8, in <module>
    import_top_level_modules()
  File "/usr/local/lib/python3.7/site-packages/future/standard_library/__init__.py", line 810, in import_top_level_modules
    with exclude_local_folder_imports(*TOP_LEVEL_MODULES):
  File "/usr/local/lib/python3.7/site-packages/future/standard_library/__init__.py", line 781, in __enter__
    module = __import__(m, level=0)
  File "/test/test.py", line 1, in <module>
    from tfrecorder import input_schema
  File "/usr/local/lib/python3.7/site-packages/tfrecorder/input_schema.py", line 26, in <module>
    from tfrecorder import types
  File "/usr/local/lib/python3.7/site-packages/tfrecorder/types.py", line 24, in <module>
    from tensorflow_transform import beam as tft_beam
  File "/usr/local/lib/python3.7/site-packages/tensorflow_transform/beam/__init__.py", line 20, in <module>
    from tensorflow_transform.beam import analyzer_cache
  File "/usr/local/lib/python3.7/site-packages/tensorflow_transform/beam/analyzer_cache.py", line 163, in <module>
    class _WriteToTFRecordGzip(beam.io.WriteToTFRecord):
AttributeError: module 'apache_beam' has no attribute 'io'

However, in the REPL it's fine:但是,在 REPL 中它很好:

I have no name!@ff017054aef4:/$ python
Python 3.7.12 (default, Oct 12 2021, 03:26:18) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tfrecorder
2021-10-26 00:24:33.293181: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-10-26 00:24:33.293201: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
>>> 

It doesn't make any sense for me.这对我来说没有任何意义。 Any ideas?有任何想法吗?

It appears that this is a bug, and that has been rectified in the latest version of apache_beam .看来这是一个错误,并且已在最新版本的apache_beam得到纠正。 The explanation in this thread is descriptive.此线程中的解释是描述性的。 Circular Import Issue in apache_beam apache_beam循环导入问题

The problem is that TOP_LEVEL_MODULES variable defines a list of modules which includes test .问题是TOP_LEVEL_MODULES变量定义了一个包含test的模块列表。 Your test module's name collides with the built in module in apache_beam.您的test模块的名称与 apache_beam 中的内置模块相冲突。 You can try renaming your test module, and check.您可以尝试重命名您的test模块,然后检查。

You don't see the same issue in shell because sys.path does not have the directory /test In the shell environment.您在 shell 中看不到相同的问题,因为sys.path在 shell 环境中没有目录/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 脚本中的python语法错误,在REPL中很好 - python syntax error in script, fine in REPL Python:__ import__在REPL中有效,但在脚本中无效 - Python: __import__ works in REPL, but not in a script python导入在服务器环境中中断,但在我的计算机上工作正常 - python import breaks in server environment but works fine on my computer Python IDLE无法导入脚本(产生错误),但脚本可以从textwrangler正常工作 - Python IDLE won't import script (gives error) but script works fine from textwrangler 脚本无法导入模块,导入shell工作正常 - Script can't import modules, import in shell works fine 如何从 py 脚本自定义显示的输出<py-repl> REPL</py-repl> - How to customise the shown outputs from a py-script <py-repl> REPL 在REPL的后台导入python模块 - Import python modules in the background in REPL bash命令通过cli正常运行,但未在python脚本中运行 - bash command runs through cli fine but not running inside python script 猪通过python脚本与导入模块流 - Pig streaming through python script with import modules 脚本在终端中运行良好,但不是从启动时运行 - script runs fine in terminal but not from launchd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM