Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'run_main' #812

Closed
timmolter opened this issue Dec 12, 2017 · 8 comments

Comments

@timmolter
Copy link

commented Dec 12, 2017

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?

@nfelt

This comment has been minimized.

Copy link
Collaborator

commented Dec 13, 2017

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?

@timmolter

This comment has been minimized.

Copy link
Author

commented Dec 13, 2017

@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!!

@timmolter

This comment has been minimized.

Copy link
Author

commented Dec 13, 2017

Here's a recent S.O. reference to this issue: https://stackoverflow.com/q/47762691/1625820

@timmolter

This comment has been minimized.

Copy link
Author

commented Dec 13, 2017

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

@jart

This comment has been minimized.

Copy link
Contributor

commented Dec 13, 2017

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

@jart jart closed this Dec 13, 2017

@timmolter

This comment has been minimized.

Copy link
Author

commented Dec 13, 2017

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

@nfelt

This comment has been minimized.

Copy link
Collaborator

commented Dec 13, 2017

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.

@nfelt

This comment has been minimized.

Copy link
Collaborator

commented Jan 9, 2018

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
Projects
None yet
3 participants
You can’t perform that action at this time.