简体   繁体   中英

How to install tensorflow-gpu for both python2 and python3

I already have installed tensorflow 1.2, CUDA 8.0 and CuDNN 5.1 for python2.7. Now I want to use it for python3.5 but importing tensorflow fails. How do I install tensorflow for python3 again. And do I have to do the CUDA and CuDNN episodes again?

You can create separate environment for python 2 and 3. Thus, you can easily install corresponding tensorflow versions. Remember you have to install everything separately on virtual environment once cuda and cudnn are installed on your system as per the instructions on Tensorflow webpage: https://www.tensorflow.org/install/install_linux

Although I would preferably keep both the envs separate but I tried to install both the versions in the same environment and it works.

My system configs are - CUDA - 8.0, CuDNN -7.1 and I tried installing Tensorflow 1.4.0.

# First, I created virtualenv for python2 as:
virtualenv --system-site-packages tf3n4 # tf3n4 is env name
# Then, I installed virtualenv for python3 with same name, it will not override python2 but it will create a seperate python3 bin. 
virtualenv --system-site-packages -p python3 tf3n4


# go to your env (it's in my home directory)
source ~/tf3n4/bin/activate

Now you can check for both pythons by which python2 and which python3 , this will be in your env path but not on the local machine python. For example: I got this /home/USERNAME/tf3n4/bin/python2 and /home/USERNAME/tf3n4/bin/python3 .

#Now, install tensorflow for python 2: 
python2 -m pip install --upgrade tensorflow-gpu==1.4
# install tensorflow for python 3:
python3 -m pip install --upgrade tensorflow-gpu==1.4

Once, you are done, you can run any python just by mentioning it:

python2 or python3 before running any code on terminal

If you have already installed tensorflow 1.2, CUDA 8.0 and CuDNN 5.1 for python2.7. Then you can:

  • yum install python3-pip

(now you have python3 and pip3, however the python version may not be 3.5)

  • python3 -m pip install --upgrade tensorflow-gpu==1.2

(make sure the installed version is exactly same as that of python2)

I made it after these two steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM