Skip to content

ImportError: cannot import name 'run_main' #812

Closed

Description

@timmolter

This is in reference to an issue already posted at tensorflow/tensorflow#14855.

After building TF V1.4 (master) from source on a Mac running High Sierra, and running Tensorboard, I get the following error.

$ tensorboard --logdir=/tmp/cifar10_train
Traceback (most recent call last):
  File "/usr/local/bin/tensorboard", line 7, in <module>
    from tensorboard.main import run_main
ImportError: cannot import name 'run_main'

This previously worked before I built TF from source insstalling it via: pip3 install --upgrade tensorflow. I tried deleting /tmp/cifar10_train, but it did not help. Any ideas?

Activity

  1. nfelt commented on Dec 13, 2017

    @nfelt
    Contributor

    Can you provide the exact steps you're using to build? Ideally such that you can reproduce it via a sequence of steps from git clone onwards.

    Specifically, what's the tensorboard binary that you're invoking here? And what directory are you invoking it from?

  2. timmolter commented on Dec 13, 2017

    @timmolter
    Author

    @nfelt Thank you for your response! Here is what I did to build TF from source. I'm new to TF and all these build tools. BTW, this is after I did a clone from TF master commit dd788dbbfa544c1ea4768940ac4300c22bb7e88e on Dec 4th. I'll pull the latest updates and try again...

    $ which tensorboard
    /usr/local/bin/tensorboard
    

    I invoked tensorboard from ~.

    Compile TF from source

    Install XCode via AppStore.

    Bazel is a software dependency and build tool similar to ANT and Maven. Installation Instructions are here.

    brew install bazel
    bazel version
    brew upgrade bazel
    pip3 install six numpy wheel 
    brew install coreutils 
    

    The C++ API (and the backend of the system) is in tensorflow/core.

    xcode-select --install (might be able to skip this actually if XCode is installed.)
    cd path/to/tensorflow
    mkdir /tmp/tensorflow_pkg
    

    We need a custom build_tf.sh because we didn't install Python the recommended way using VirtualEnv. The source of our build file is here. This retrieves all CPU features and applies some of them to build TF, which makes TF faster as it will utilize specialized CPU instructions if your computer has them.

    Here is our build_tf.sh:

    #!/bin/bash
    
    # Author: Sasha Nikiforov
    
    # source of inspiration
    # https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions
    
    raw_cpu_flags=`sysctl -a | grep machdep.cpu.features | cut -d ":" -f 2 | tr '[:upper:]' '[:lower:]'`
    COPT="--copt=-march=native"
    
    for cpu_feature in $raw_cpu_flags
    do
        case "$cpu_feature" in
            "sse4.1" | "sse4.2" | "ssse3" | "fma" | "cx16" | "popcnt" | "maes")
                COPT+=" --copt=-m$cpu_feature"
            ;;
            "avx1.0")
                COPT+=" --copt=-mavx"
            ;;
            *)
                # noop
            ;;
        esac
    done
    
    bazel clean
    #./configure
    bazel build -c opt $COPT -k //tensorflow/tools/pip_package:build_pip_package
    bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    
    pip3 install --upgrade /tmp/tensorflow_pkg/`ls /tmp/tensorflow_pkg/ | grep tensorflow`
    

    Notice the commented out line: #./configure, which you'll need to run the first time to configure tensorflow. To run the script run:

    ./build_tf.sh
    

    Make sure the file is executable! chmod +x build_tf.sh

    Path to python, when asked, is:

    /usr/local/bin/python3
    

    The first build might take over two hours!

    Re-run an example

    python3 tensorflow/examples/tutorials/mnist/mnist_softmax.py

    Congratulations!!

  3. timmolter commented on Dec 13, 2017

    @timmolter
    Author
  4. timmolter commented on Dec 13, 2017

    @timmolter
    Author

    OK, I rebuilt after updating to the latest commit on tensorflow master and got the same error.

  5. jart commented on Dec 13, 2017

    @jart
    Contributor

    If you're building TensorFlow from source please pip install tb-nightly.

  6. timmolter commented on Dec 13, 2017

    @timmolter
    Author

    running pip install tb-nightly indeed fixed the issue. I don't know what that does, but thanks a lot!

  7. nfelt commented on Dec 13, 2017

    @nfelt
    Contributor

    The tensorflow pip package by default depends on tensorflow-tensorboard; tb-nightly is the nightly build of tensorboard. In your case the version of tensorflow at HEAD that you were building creates the tensorboard script calling run_main (a recent change from the old main method name), so for that to work it requires a newer version of tensorboard than the stable release.

  8. nfelt commented on Jan 9, 2018

    @nfelt
    Contributor

    What exactly do you mean by no "tb-nightly" could be found? Is there no access to pip on your platform?

    If you can't install tensorboard from a package at all, I think your only real option is downloading the sources from the git repository here and trying to build it locally, but I can't really guarantee if that will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions