Xiaojie Zhou
Xiaojie Zhou

Reputation: 172

Can I installed tensorflow for python 2.7 and 3.5 on my machine simultaneously?

Currently I have Python 2.7, Python 3.5, Tensorflow for Python 3.5 installed on my machine (MAC OX) via Anaconda. I would like to install Tensorflow for Python 2.7 on my machine as well.

When I tried "conda create -n tensorflow python=2.7", I got the following error: "Error: prefix already exists: /Users/x644435/anaconda/envs/tensorflow". It must be because I have already installed tensorflow for python 3.5.

Can I installed tensorflow for python 2.7 and 3.5 on my machine simultaneously? And how?

Thank you in advance for your help.

Upvotes: 4

Views: 9277

Answers (1)

Naveen Dennis
Naveen Dennis

Reputation: 1223

Yes, you can. Create two environments (tensorflow, tensorflow3) -- as @cel mentioned in the comments the environment names should be unique and it is only for your reference.

conda create -n tensorflow python=2.7
conda create -n tensorflow3 python=3.5

Now you have two environments with python2.7 and python3.5 (tensorflow is not installed yet!)

In order to do that move to each environment:

source activate <environment-name>

Then install Tensorflow in each environment based on the python that is to be used. (based on the anaconda version that you are using you can use pip/pip3 or conda-forge).

If you are installing with GPU then you need to download and install the CUDA libraries as well. Also, remember to set the environment variables in .bashrc

Once you are done, you can view the list of environments using the command:

conda info --envs

SOLUTION TO YOUR SPECIFIC ERROR: The error that you got is probably because you already have an enviroment with the name "tensorflow". List the environments to see your existing Conda Enviroments using conda info --envs and then create the new python 2.7 environment using another name enviroment name like tensorflow27 using conda create -n tensorflow27 python=2.7

NOTE: When installing ANACONDA if you pre-appended the CONDA path to the PATH environment variable then change it to post-append (export PATH="$PATH:/home/dennis/anaconda3/bin") so that the installation doesn't override the existing python installation. (you can check this using $which python

TESTED - I have both versions installed on my machine

REFERENCE: https://conda.io/docs/py2or3.html

Upvotes: 4

Related Questions