1

I have been trying to install tensorflow via Conda for a couple days now with no luck.

I made a fresh install of anaconda3/miniconda3 followed the steps to fix the .bash_profile issue. Then

$ conda create -n tensorflow pip python=3.6

seems to work. However

$ source activate tensorflow

does nothing. I tried conda activate tensorflow and nothing. If I type conda info I can see that the tensorflow env is running. But I have no ability to type within it?

mjwrazor
  • 1,866
  • 2
  • 26
  • 42
  • What do you mean "no ability to type within it"? Type within what? – darthbith Jun 15 '18 at 03:24
  • @darthbith well normally when you type source activate 'my_env' it gives a new shell prompt to type within. For me it does nothing. – mjwrazor Jun 15 '18 at 13:08
  • What do you mean a new shell prompt? Can you post the exact output when you type the `conda activate` command? How did you add the `conda` command to your `PATH`? Did you install miniconda 3 or anaconda 3? – darthbith Jun 15 '18 at 16:01
  • `conda create -n tensorflow pip python=3.6` works just fine for me – Oscar Montoya May 17 '20 at 17:42

4 Answers4

3

Welcome to Python and Tensorflow. This bit really takes a long time to figure out unless somebody told you how to do so.

Follow this. Assume you installed Miniconda (then python is automatically installed) and you are using linux (cuz you mentioned 'source')

You want to make an conda environment named 'ai3' and you wanna install many packages like tensorflow within 'ai3' env.

In your command line, 1) Create ai3 env: see https://conda.io/docs/user-guide/tasks/manage-environments.html for details

$ conda create -n ai3 python=3.6

2) Log your current command window into the ai3 env

 $ source activate ai3

3) Install packages, for example tensorflow: details in https://www.tensorflow.org/install/install_linux but that does not really help FOBs

$ pip install tensorflow

4) Enter yes whenever your command window asks sth. Once it's done, then you wish to use tensorflow (TF) in python. Do this

$ python
$ >> import tensorflow as tf
$ >> hello = tf.constant('Hello, TensorFlow!')
$ >> with tf.Session() as sess:
$ >>     sess.run(hello)

4-1-0) Obviously you don't wanna do this all the time. Download Pycharm community edition (in https://www.jetbrains.com/pycharm/download/#section=linux) and install. 4-1-1) Create a new project in any location you like with interpreter 'ai3'. Interpreter is the env you just prepared in step 1,2,3): click 'add local' by clicking a button at the right end of the 'Interpreter' line -> a python file at '/miniconda3/envs/ai3/bin/python'

5) Now work with many tutorials out there on this setup

sdr2002
  • 542
  • 2
  • 6
  • 16
  • For me I am getting stuck at (2). `source activate 'my_env'` does not open the new prompt that should come up. I have done it a year ago so I remember there being a new shell prompt that let me add to that environment. But `conda info` will show that my env is active. – mjwrazor Jun 15 '18 at 13:09
  • 1
    Oh Wow I didn't know I could point pycharm there for the intepreter. That should be written somewhere. – mjwrazor Jun 15 '18 at 13:11
  • @mjwrazor First, double-check you did >> source activate ai3, not >> source activate 'ai3'. Put ' signs out. Second, If you installed your conda and made your environment a year ago, then uninstalled the conda, reinstall it, and make the environment again. When a machine doesn't work in a very first few step, then it is always good to redo all the things again. Do this until this your source activate ai3 works, like if you do experiments. – sdr2002 Jun 16 '18 at 17:26
  • Lastly, you might install conda in wrong way. 'source' command is to make your shell program run (it is something that will run your conda). The word 'activate' activates your conda. 'source' cannot be a problem unless you did really nasty things on your linux machine. Highly likely you installed your conda in wrong way, so as suggested in Second, completely remove your conda (Anaconda or Miniconda or both) program out from your machine. – sdr2002 Jun 16 '18 at 17:32
  • So you need to do this: Remove your conda totally (https://stackoverflow.com/questions/29596350/how-to-uninstall-mini-conda-python), Install Miniconda with following instruction(https://conda.io/docs/user-guide/install/linux.html), and do 1),2),3),4),5) in the main text of mine. If you still get in trouble, screenshot where you get troubled and upload in here – sdr2002 Jun 16 '18 at 17:34
  • Do we need Miniconda installed to install tensorflow? Isn't conda sufficient without Miniconda? – Dulangi_Kanchana Dec 28 '20 at 01:06
1

First you need to check the naming convention you are using. I know that's how documentation suggests, but I think it's misleading.

Name your environment according to what you want to be doing inside of it. Tensorflow is a package (that can be a python package) that you will use inside of the environment so you can name it something like:

$ conda create --name 'machinelearning-env' pip python=3.6

Also if you just installed Anaconda you do not need to specify the python designation.

Then you need to activate your environment with source activate (whatever you named your conda env)

Next you can install with :

:~/anaconda3/envs$ pip install --ignore-installed --upgrade (the tensorflow url found here: https://www.tensorflow.org/install/install_linux#the_url_of_the_tensorflow_python_package )

Finally instantiate python and then you can import tensorflow with :

import tensorflow as tf

I suggest you refer back to the tensorflow documentation as it's all there. Good luck!

  • For me though. Source activate doesn't bring up the new prompt like I am used to. It just activates the environment in the background? – mjwrazor Jun 15 '18 at 13:12
  • mjwrazor, what terminal are you using? –  Jun 15 '18 at 13:17
  • Iterm2 with zsh – mjwrazor Jun 15 '18 at 13:20
  • mjwrazor. Go through this process with terminal, I think this is where your issue is. Also if you don't mind an upvote for the help. Thanks –  Jun 15 '18 at 14:26
  • It seems that even in the regular terminal it still doesn't work. – mjwrazor Jun 15 '18 at 14:38
  • Wow. At this point you may want to consider purging your conda install. Let me spend some time at lunch and see if I can't backtrack . In the meantime if you could post all your steps in code format above. --- Also if you aren't sold on condas I suggest trying this with a venv instead. –  Jun 15 '18 at 14:55
  • I figured it out. There must be some config file messed up somewhere. But it is changing the environment. It just isn't changing my command line view. So it is all working just something odd with that. Thanks for the help though. – mjwrazor Jun 15 '18 at 15:16
0

You should first give a name to your environment then give package names that you want to install ie. conda create -n tensorflow_env tensorflow

Easiest way for me at least.

stevevaius
  • 21
  • 4
0

If you're working in the miniconda or anaconda environment on macOS 13, the solution is to use the command conda install tensorflow to install TensorFlow.

user16217248
  • 3,119
  • 19
  • 19
  • 37
houxia_
  • 9
  • 2