tfx icon indicating copy to clipboard operation
tfx copied to clipboard

Invalid syntax in taxi_pipeline_simple.py

Open ajit-kumar-azad opened this issue 7 years ago • 15 comments

Hi There!

I am following Chicago Taxi Pipeline example steps. While running airflow webserver I am getting following error:

[2019-07-29 11:58:24 +0530] [16909] [INFO] Booting worker with pid: 16909
[2019-07-29 11:58:24,302] {__init__.py:51} INFO - Using executor SequentialExecutor
[2019-07-29 11:58:24,489] {__init__.py:305} INFO - Filling up the DagBag from /Users/XXXX/devdata/airflow/dags
[2019-07-29 11:58:24,494] {__init__.py:416} ERROR - Failed to import: /Users/XXXX/devdata/airflow/dags/taxi/taxi_pipeline_simple.py
Traceback (most recent call last):
  File "/Users/XXXX/dev/tfx-master/tfx/examples/chicago_taxi_pipeline/taxi_pipeline/lib/python2.7/site-packages/airflow/models/__init__.py", line 413, in process_file
    m = imp.load_source(mod_name, filepath)
  File "/Users/XXXX/devdata/airflow/dags/taxi/taxi_pipeline_simple.py", line 70
    def _create_pipeline(pipeline_name: Text, pipeline_root: Text, data_root: Text,
                                      ^
SyntaxError: invalid syntax

ajit-kumar-azad avatar Jul 29 '19 06:07 ajit-kumar-azad

@ajit-kumar-azad This might be that you're running beam on Python 2.7, but the code you're using in Python 3.5. Please upgrade your local virtuanenv to Python 3 and update.

Maybe the docs need to be updated?

htahir1 avatar Jul 29 '19 13:07 htahir1

@ajit-kumar-azad , Please provide details about what platform you are using (operating system, architecture). Also include your TensorFlow version. Also, did you compile from source or install a binary?

Make sure you also include the exact command if possible to produce the output included in your test case. If you are unclear what to include see the issue template displayed in the Github new issue template.

We ask for this in the issue submission template, because it is really difficult to help without that information. Thanks!

rmothukuru avatar Jul 29 '19 13:07 rmothukuru

@ajit-kumar-azad This might be that you're running beam on Python 2.7, but the code you're using in Python 3.5. Please upgrade your local virtuanenv to Python 3 and update.

Maybe the docs need to be updated?

@htahir1 I am following the exact steps and version of the softwares mentioned in the example documentation. I am using Python 2.7 and here are the versions of other softwares:

  • tensorflow - 1.13.1
  • docker - 4.0.1
  • apache-airflow - 1.10.3
  • tfx - 0.13.0

Should I use Python 3? If so, what shall be the versions of other required softwares?

ajit-kumar-azad avatar Jul 30 '19 03:07 ajit-kumar-azad

@ajit-kumar-azad Try and switch to python 3 and use the same versions. If that doesnt work, please add the errors that occur again

htahir1 avatar Jul 30 '19 06:07 htahir1

@ajit-kumar-azad , Can you please try @htahir1's suggestion. If you are still facing the issue, can you please provide

  1. Softwares you are using, along with versions
  2. OS details
  3. Exact code to reproduce the issue
  4. Error Log Thanks!

rmothukuru avatar Jul 31 '19 06:07 rmothukuru

Hi all, I've also been working through the Chicago Taxi example using Python 3 but hitting ImportErrors for Apache Beam. This is using the exact steps outlined in the README, on OSX Mojave:

Traceback (most recent call last):
  File "taxi_pipeline_simple.py", line 31, in <module>
    from tfx.components.transform.component import Transform
  File "/Users/XXXX/taxi_pipeline/lib/python3.7/site-packages/tfx/components/transform/component.py", line 24, in <module>
    from tfx.components.transform import executor
  File "/Users/XXXX/taxi_pipeline/lib/python3.7/site-packages/tfx/components/transform/executor.py", line 30, in <module>
    from tensorflow_transform.beam import analyzer_cache
ImportError: cannot import name 'analyzer_cache' from 'tensorflow_transform.beam' (/Users/XXXX/taxi_pipeline/lib/python3.7/site-packages/tensorflow_transform/beam/__init__.py)

It doesn't seem that the Chicago Taxi example is runnable in the tfx repo's current state. I believe Python 2 is recommended because Apache Beam is not yet compatible with Python 3, however the type annotations that were recently added are incompatible with Python 2.

Any thoughts on the best way to proceed? I suppose removing the type annotations and using Python 2, or waiting for Beam to be compatible with Python 3, but any other clever thoughts?

Edit: I'm attempting to run taxi_pipeline_simply.py using Python 2 and removing the type annotations. I encounter an ImportError from this:

Traceback (most recent call last):
ImportError: cannot import name external_input
  File "/Users/XXXX/taxi_pipeline/lib/python2.7/site-packages/airflow/models/__init__.py", line 413, in process_file
    m = imp.load_source(mod_name, filepath)
  File "/Users/XXXX/airflow/dags/taxi/taxi_pipeline_simple.py", line 38, in <module>
    from tfx.utils.dsl_utils import external_input
ImportError: cannot import name external_input

The README states that tfx==0.13.0 should be installed using pip. However, this version does not include the external_input() function in dsl_utils.py.

colson1111 avatar Jul 31 '19 14:07 colson1111

Hi @colson1111, it looks like we are being broken at head by differences in the API for https://github.com/tensorflow/transform. This is a known issue and we are working on making this dependency work better. Right now, the workaround is to build and install that package at head; you can also install the one-off nightly build here from test-pypi: https://test.pypi.org/project/tensorflow-transform-nightly/#files.

pip install https://test-files.pythonhosted.org/packages/4b/02/14ef3dc3d8d05b1999721add1a2812a8031cd91573ab29a6cdeb66939b97/tensorflow-transform-nightly-0.14.0.dev20190726.tar.gz

CC: @zhitaoli

charlesccychen avatar Jul 31 '19 18:07 charlesccychen

Has anyone been able to get this to work? I also tried what @colson1111 suggested to remove the Python 3 type annotations and also used the nightly build suggested by @charlesccychen but there are still a slew of issues pertaining to Python 2 vs 3 and/or Tensorflow/TFX. Given Apache Beam does not work with Python 3, is it safe to assume this taxi pipeline example cannot actually "work"? Any ideas are appreciated

ahsanshah avatar Aug 02 '19 03:08 ahsanshah

Hi @ahsanshah @colson1111, this works for me on Python 3. Processing with Apache Beam on Python 3 also works just fine, though it is still not certified as stably supported in the current release. What has worked for me is:

  1. Create and enter a new Python 3 virtualenv.
  2. Install TFX and Tensorflow using pip install https://test-files.pythonhosted.org/packages/4b/02/14ef3dc3d8d05b1999721add1a2812a8031cd91573ab29a6cdeb66939b97/tensorflow-transform-nightly-0.14.0.dev20190726.tar.gz tensorflow==1.14.0
  3. Download the sample data and run the example.

Can you let me know what step fails in your environment?

charlesccychen avatar Aug 02 '19 08:08 charlesccychen

The problem is the docs are "published" but versions that work aren't.

I found the same problems. First off, use python 3. The TFX docs say not to, BEAM gives warnings while running, but it does work. In terms of version, as mentioned above, the online docs do not work with the 'pip' versions. Basically use pip tf-nightly and manually install protoc. Then install nightly tfx: git clone https://github.com/tensorflow/tfx.git using setup.py.

That method worked, so I suspect https://github.com/tensorflow/tfx/issues/396#issuecomment-517609019 will also work. I wanted to mention how I did it but the best way would be the use the response by @charlesccychen above.

robertlugg avatar Aug 02 '19 17:08 robertlugg

Thanks. I did try the steps (or the combination of steps) outlined by @robertlugg and @charlesccychen . The issue seems to be with Airflow. I still get errors on the Airflow side such as:

  1. ERROR - Cannot use more than 1 thread when using sqlite. Setting parallelism to 1
  2. File "/u00/TFX3/taxi_pipeline/lib/python3.5/abc.py", line 225, in subclasscheck for scls in cls.subclasses(): TypeError: descriptor 'subclasses' of 'type' object needs an argument

Were you able to get Airflow working properly with TFX? I assume yes? I may need to further dig into why its not working on my end.

ahsanshah avatar Aug 03 '19 00:08 ahsanshah

@ahsanshah Yes, I was able to use the steps from @charlesccychen (along with the git clone + python setup.py install step from @robertlugg ) to get the example pipeline to run in Airflow. I am using a python3.7 virtualenv.

colson1111 avatar Aug 05 '19 17:08 colson1111

Steps mentioned on https://www.tensorflow.org/tfx/tutorials/tfx/workshop work and seems to be more up-to-date. I could get the example running.

ajit-kumar-azad avatar Aug 08 '19 05:08 ajit-kumar-azad

ImportError: cannot import name 'external_input'

I followed the steps mentioned on https://www.tensorflow.org/tfx/tutorials/tfx/workshop and still found the same problem. The workaround for me is to clone the r0.13 branch of tfx. git clone -b r0.13 https://github.com/tensorflow/tfx.git

@charlesccychen @ajit-kumar-azad

gzpyy avatar Aug 29 '19 03:08 gzpyy

Yes that is the right thing to do. Because we are still in 0.x versions and occasionally introduces breaking changes, we will ensure examples cloned from each released branch works with the released package version, and back port fixes if necessary.

zhitaoli avatar Aug 29 '19 03:08 zhitaoli