0

So I program a tensorflow program in python3, and can execute said scripts with python3, with the modules that I installed using pip3. But when using

tensorboard --logdir="./graphs" --port 6006

It is using Python2.7, and numpy is not installed, since I am not using Python 2. When installing numpy with pip (instead of pip3) it still does not work because AttributeErrors.

How can i tell tensorboard (and other programs) to use python3 with the pip3 modules, instead of python2.7?

Using python3 tensorboard --logdir="./graphs" --port 6006 does not work, since python3 expects me to give it a script file.

Additional Information: The tensorboard graph file has been created in the given path, from this code

import os
import tensorflow as tf
import numpy as np

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 
tf.reset_default_graph()

a = tf.constant(2)
b = tf.constant(3)
c = tf.add(a, b)

with tf.Session() as sess:
    writer = tf.summary.FileWriter('./graphs', sess.graph)
    print(sess.run(c))

3 Answers 3

0

Personally, I use miniconda to create an environment in which I have control over the python (etc.) versions used. There is also a python specific environment manager pipenv.

If you create an environment which only has python3 and which has your version of tensorflow & tensorboard, you may find it easier, especially as new software versions come out and you want to be able to control the versions in your environment.

4
  • That did worked, thanks. But I would like to run the scripts and programs outside of a virtual environment. I tried pipenv btw. I can run tensorboard in there with python3, but I still would like to just use the normal tensorboard installation thats already on my ubuntu, with python3 etc. Without any environments added
    – TrackLab
    Jan 28, 2019 at 12:53
  • AFAIK there's no distribution which comes with tensorboard out-of-the-box, so your "normal tensorboard installation" must have been installed by you (or you're using a machine image with it installed already. If the former, ask the people who provided the instructions you followed ... and if the latter, ask them why it's not working. Or, you could follow the crowd and use an environment (think container-light) ...
    – JeToJedno
    Jan 29, 2019 at 19:39
  • Tensorboard is being installed automatically when installing TensorFlow. So I have that since I installed TensorFlow. The Scripts are easy to run with python 3, by simply using "python3 script.py". But to run tensorflow to create a local webside with the graph, you cant specify it in python3 since python3 wants a file, and not a program command
    – TrackLab
    Jan 30, 2019 at 9:53
  • 1
    Sorry for being a bit dense, but I've just looked in the source and it all looks like python to me, and looking at the tensorboard binary ... and it is 5 lines of python code which calls tensorboard's main function. What's the problem?
    – JeToJedno
    Feb 22, 2019 at 9:12
0

Suppose you have two python versions say python2.x and python3.x and say you want to use tensorboard for python 3.x. Go to the python 3.x directory and go to tensorboard directory. You will find the main.py file there. Open terminal from this location. Typepython3 main.py --logdir path/to/log/directory That's it. Open the link given and watch your logs. Enjoy!

0

Expanding on the @JeToJedno's answer.

TL;DR: $ python3 /usr/local/bin/tensorboard --logdir ...


Explanation:

Since /usr/local/bin/tensorboard is a bash script that uses /usr/local/bin/python interpreter:

#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from tensorboard.main import run_main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(run_main())

You can just run is with python of the desired version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.