Search In
• More options...
Find results that contain...
Find results in...

# Getting started with Tensorflow (GPU edition)

## Recommended Posts

Posted · Original PosterOP

I Want to Install tensorflow-gpu on my computer.

What have I done so far:

3)
Created environment for tensorflow with   conda create --name tensorflow

4) Activated said environment with   activate tensorflow

5) Installed tensorflow-gpu package with  conda install tensorflow-gpu

6) Tried to import tensorflow as tf and got this error:

Can anybody point me in the right direction?

##### Share on other sites

I guess you have to reinstall numpy as it said in the error.

Making the web a better place for everyone.

##### Share on other sites
Posted · Original PosterOP

I have tried it already. Nothing changed. Not ever the error message

##### Share on other sites
2 hours ago, Dimitris S said:

I have tried it already. Nothing changed. Not ever the error message

What you do with Conda is install python into your Conda environment.

When you use a global Python install, but local library installs, you end up having to do all sorts of weird things to get your libraries to import, like:

import sys

sys.path.append("path\to\library")

import libraryA
import libraryB
import libraryC
...:
import HowManyDoINeed 

There are a few caveats with that method, however.

Teacher: Does anyone have a thin ruler?

Students: No.

Teacher: Ok. Does anyone have a nail file.

Students: Why do you need a nail file?
Teacher: I have a staple I need to remove.

Student: Oh. I have a staple remover...

People don't want power drills, they want holes.

##### Share on other sites

Why not create virtualenv and install from pip/wheel?

##### Share on other sites
Posted · Original PosterOP
5 hours ago, straight_stewie said:

What you do with Conda is install python into your Conda environment.

When you use a global Python install, but local library installs, you end up having to do all sorts of weird things to get your libraries to import, like:


import sys

sys.path.append("path\to\library")

import libraryA
import libraryB
import libraryC
...:
import HowManyDoINeed 

There are a few caveats with that method, however.

Can u briefly describe what is the solution in steps? I have trouble understanding fully what are you saying

##### Share on other sites
21 minutes ago, Dimitris S said:

Can u briefly describe what is the solution in steps? I have trouble understanding fully what are you saying ﻿

Python's import system basically only uses relative filepaths. Ostensibly this means that all of your libraries, like tensorFlow or numpy expect to be installed to your python installs root location, and python expects that as well.

The problem you are experiencing is because you are using a global python install: i.e. you downloaded python from python.org, and installed it, and added it to your PATH variable. But, you are using local library installs. Ergo, python doesn't know where the libraries are, and the libraries don't know where python is.

There are two ways easy ways to fix this:

• Stop using Conda. I mean, do you really need to have separate environments for every project you're working on? Instead, you can use pip to install your packages into your global python installation, and then they will work from everywhere with few problems.
• Use Conda, but also install python into every Conda environment. This way, all of your libraries and your python install are in the same place. This could be finicky, I haven't tried it myself.

The third way is what I described above. This basically tells python to switch it's "system path" from whatever is in your PATH variable that points to your pythons root directory, to whatever path you put there, and then you can import things from that folder.

I know that all of the science packages really try very hard to push you into using Conda, but you do not need to use it. Most or all of the packages available on Conda are also available on pip. Installing tensorFlow globally is as easy as typing "pip install tensorflow" at the command prompt. (unless you're running linux, then: "sudo pip install tensorflow")

EDIT:: For the Cuda enabled version of tensorFlow, the commands would be "pip install tensorflow-gpu" and "sudo pip install tensorflow-gpu" respectively.

Teacher: Does anyone have a thin ruler?

Students: No.

Teacher: Ok. Does anyone have a nail file.

Students: Why do you need a nail file?
Teacher: I have a staple I need to remove.

Student: Oh. I have a staple remover...

People don't want power drills, they want holes.

##### Share on other sites
Posted · Original PosterOP
10 hours ago, straight_stewie said:

Python's import system basically only uses relative filepaths. Ostensibly this means that all of your libraries, like tensorFlow or numpy expect to be installed to your python installs root location, and python expects that as well.

The problem you are exp﻿eriencing is because you are using a global python install: i.e. you downloaded python from python.org, and installed it, and added it to your PATH variable. But, you are using local library installs. Ergo, python doesn't know where the libraries are, and the libraries don't know where python is.

There are two ways easy ways to fix this:

• Stop using Conda. I mean, do you really need to have separate environments for every project you're working on? Instead, you can use pip to install your packages into your global python installation, and then they will work from everywhere with few problems.
• Use Conda, but also install python into every Conda environment. This way, all of your libraries and your python install are in the same place. This could be finicky, I haven't tried it myself.

The third way is what I described above. This basically tells python to switch it's "system path" from whatever is in your PATH variable that points to your pythons root directory, to whatever path you put there, and then you can import things from that folder.

I know that all of the science packages really try very hard to push you into using Conda, but you do not need to use it. Most or all of the packages available on Conda are also available on pip. Installing tensorFlow globally is as easy as typing "pip install tensorflow" at the command prompt. (unless you're running linux, then: "sudo pip install tensorflow")

EDIT:: For the Cuda enabled version of tensorFlow, the commands would be "pip install tensorflow-gpu" and "sudo pip install tensorflow-gpu" respectively.

Thanks for the detailed explanation. I appreciate it

##### Share on other sites
Posted · Original PosterOP

Ι ditched anaconda and made a system-wide install of tensorflow with pip. Now I call a python interpreter from anywhere and import tensorflow as tf. Thanks for the great advice @straight_stewie