New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'No module named tensorflow' after installing via pip #6548

Closed
tristanbrown opened this Issue Dec 29, 2016 · 28 comments

Comments

Projects
None yet
@tristanbrown

tristanbrown commented Dec 29, 2016

I'm running Anaconda on win64.
The files are in the correct site-packages directory, with an __init__.py, but python doesn't seem to be able to recognize the module, regardless of whether I'm working in a virtual environment or the root directory.
None of the following has changed this result:
This.
This.
This.

@tristanbrown

This comment has been minimized.

Show comment
Hide comment
@tristanbrown

tristanbrown Dec 29, 2016

I originally tried setting it up by generating an environment.yml file:

name: tensorflow
dependencies:
- python=3
- pip
- numpy
- scipy
- matplotlib
- pandas
- pip:
    - tensorflow

In the same directory, I use conda env create, followed by activate tensorflow. Running any import tensorflow statement then prints ImportError: No module named 'tensorflow'.

I've now found that I manually add 'C:\Program Files\Anaconda3\envs\tensorflow\Lib\site-packages' to my PYTHONPATH environment variable, I get past that error, though this workaround seems like it could cause problems with other environments. The next error that pops up is ImportError: cannot import name 'multiarray', from numpy.

tristanbrown commented Dec 29, 2016

I originally tried setting it up by generating an environment.yml file:

name: tensorflow
dependencies:
- python=3
- pip
- numpy
- scipy
- matplotlib
- pandas
- pip:
    - tensorflow

In the same directory, I use conda env create, followed by activate tensorflow. Running any import tensorflow statement then prints ImportError: No module named 'tensorflow'.

I've now found that I manually add 'C:\Program Files\Anaconda3\envs\tensorflow\Lib\site-packages' to my PYTHONPATH environment variable, I get past that error, though this workaround seems like it could cause problems with other environments. The next error that pops up is ImportError: cannot import name 'multiarray', from numpy.

@gunan

This comment has been minimized.

Show comment
Hide comment
@gunan

gunan Dec 29, 2016

Member

There are some known anaconda issues.
In your pip install command, could you try adding the --ignore_installed flag

Member

gunan commented Dec 29, 2016

There are some known anaconda issues.
In your pip install command, could you try adding the --ignore_installed flag

@tristanbrown

This comment has been minimized.

Show comment
Hide comment
@tristanbrown

tristanbrown Dec 30, 2016

I tried adding the --ignore-installed flag, and it doesn't change the result at all.

tristanbrown commented Dec 30, 2016

I tried adding the --ignore-installed flag, and it doesn't change the result at all.

@tristanbrown

This comment has been minimized.

Show comment
Hide comment
@tristanbrown

tristanbrown Dec 30, 2016

Yes, I'm using anaconda 64-bit, and there are no errors.

(tensorflow) E:\Tristan\Mython\TensorFlowTutorial>pip install --ignore-installed tensorflow
Collecting tensorflow
  Using cached tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
Collecting wheel>=0.26 (from tensorflow)
  Using cached wheel-0.29.0-py2.py3-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow)
  Using cached numpy-1.11.3-cp35-none-win_amd64.whl
Collecting six>=1.10.0 (from tensorflow)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.1.0 (from tensorflow)
  Using cached protobuf-3.1.0.post1-py2.py3-none-any.whl
Collecting setuptools (from protobuf>=3.1.0->tensorflow)
  Using cached setuptools-32.3.1-py2.py3-none-any.whl
Installing collected packages: wheel, numpy, six, setuptools, protobuf, tensorflow
Successfully installed numpy-1.11.3 protobuf-3.1.0.post1 setuptools-32.3.1 six-1.10.0 tensorflow-0.12.1 wheel-0.29.0

tristanbrown commented Dec 30, 2016

Yes, I'm using anaconda 64-bit, and there are no errors.

(tensorflow) E:\Tristan\Mython\TensorFlowTutorial>pip install --ignore-installed tensorflow
Collecting tensorflow
  Using cached tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
Collecting wheel>=0.26 (from tensorflow)
  Using cached wheel-0.29.0-py2.py3-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow)
  Using cached numpy-1.11.3-cp35-none-win_amd64.whl
Collecting six>=1.10.0 (from tensorflow)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.1.0 (from tensorflow)
  Using cached protobuf-3.1.0.post1-py2.py3-none-any.whl
Collecting setuptools (from protobuf>=3.1.0->tensorflow)
  Using cached setuptools-32.3.1-py2.py3-none-any.whl
Installing collected packages: wheel, numpy, six, setuptools, protobuf, tensorflow
Successfully installed numpy-1.11.3 protobuf-3.1.0.post1 setuptools-32.3.1 six-1.10.0 tensorflow-0.12.1 wheel-0.29.0
@gunan

This comment has been minimized.

Show comment
Hide comment
@gunan

gunan Dec 30, 2016

Member

OK, one observation, you are installing tensorflow inside a conda environment, so tensorflow is only available in that conda environment.
by any chance, are you trying to run tensorflow outside this environment?

Another possible issue, is it possible you have multiple python distributions installed?

Member

gunan commented Dec 30, 2016

OK, one observation, you are installing tensorflow inside a conda environment, so tensorflow is only available in that conda environment.
by any chance, are you trying to run tensorflow outside this environment?

Another possible issue, is it possible you have multiple python distributions installed?

@Carmezim

This comment has been minimized.

Show comment
Hide comment
@Carmezim

Carmezim Dec 30, 2016

Contributor

Couldn't reproduce the error. It's really something on your side.

C:\WINDOWS\system32>activate tensorflow

(tensorflow) C:\WINDOWS\system32>pip install --ignore-installed tensorflow
Collecting tensorflow
  Using cached tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
Collecting numpy>=1.11.0 (from tensorflow)
  Downloading numpy-1.11.3-cp35-none-win_amd64.whl (7.6MB)
    100% |################################| 7.6MB 123kB/s
Collecting six>=1.10.0 (from tensorflow)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.1.0 (from tensorflow)
  Downloading protobuf-3.1.0.post1-py2.py3-none-any.whl (347kB)
    100% |################################| 348kB 907kB/s
Collecting wheel>=0.26 (from tensorflow)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |################################| 71kB 1.1MB/s
Collecting setuptools (from protobuf>=3.1.0->tensorflow)
  Downloading setuptools-32.3.1-py2.py3-none-any.whl (479kB)
    100% |################################| 481kB 415kB/s
Installing collected packages: numpy, six, setuptools, protobuf, wheel, tensorflow
Successfully installed numpy-1.11.3 protobuf-3.1.0.post1 setuptools-32.3.1 six-1.10.0 tensorflow-0.12.1 wheel-0.29.0

(tensorflow) C:\WINDOWS\system32>python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, testing TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, testing TensorFlow!'
Contributor

Carmezim commented Dec 30, 2016

Couldn't reproduce the error. It's really something on your side.

C:\WINDOWS\system32>activate tensorflow

(tensorflow) C:\WINDOWS\system32>pip install --ignore-installed tensorflow
Collecting tensorflow
  Using cached tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
Collecting numpy>=1.11.0 (from tensorflow)
  Downloading numpy-1.11.3-cp35-none-win_amd64.whl (7.6MB)
    100% |################################| 7.6MB 123kB/s
Collecting six>=1.10.0 (from tensorflow)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.1.0 (from tensorflow)
  Downloading protobuf-3.1.0.post1-py2.py3-none-any.whl (347kB)
    100% |################################| 348kB 907kB/s
Collecting wheel>=0.26 (from tensorflow)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |################################| 71kB 1.1MB/s
Collecting setuptools (from protobuf>=3.1.0->tensorflow)
  Downloading setuptools-32.3.1-py2.py3-none-any.whl (479kB)
    100% |################################| 481kB 415kB/s
Installing collected packages: numpy, six, setuptools, protobuf, wheel, tensorflow
Successfully installed numpy-1.11.3 protobuf-3.1.0.post1 setuptools-32.3.1 six-1.10.0 tensorflow-0.12.1 wheel-0.29.0

(tensorflow) C:\WINDOWS\system32>python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, testing TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, testing TensorFlow!'
@zafartahirov

This comment has been minimized.

Show comment
Hide comment
@zafartahirov

zafartahirov Jan 2, 2017

Contributor

I might be mistaken, but I always thought that Anaconda has its own package and environment control and didn't use pip or venv. Have you tried following the conda instructions? I am not sure if the instructions are the same for Windows, but it should as simple as

conda create -n tensorflow python=2.7
Contributor

zafartahirov commented Jan 2, 2017

I might be mistaken, but I always thought that Anaconda has its own package and environment control and didn't use pip or venv. Have you tried following the conda instructions? I am not sure if the instructions are the same for Windows, but it should as simple as

conda create -n tensorflow python=2.7
@gunan

This comment has been minimized.

Show comment
Hide comment
@gunan

gunan Jan 3, 2017

Member

virtualenv can still be made available when using anaconda, but you are right.
Anaconda has conda.

However, one important detail. We only have python 3.5 support in windows. so the python=2.7 part in the command wont work in windows.

Member

gunan commented Jan 3, 2017

virtualenv can still be made available when using anaconda, but you are right.
Anaconda has conda.

However, one important detail. We only have python 3.5 support in windows. so the python=2.7 part in the command wont work in windows.

@michaelisard

This comment has been minimized.

Show comment
Hide comment
@michaelisard

michaelisard Jan 6, 2017

Member

@tristanbrown did these suggestions help?

Member

michaelisard commented Jan 6, 2017

@tristanbrown did these suggestions help?

@tristanbrown

This comment has been minimized.

Show comment
Hide comment
@tristanbrown

tristanbrown Jan 10, 2017

The only other python distribution I have installed is WinPython, but I've already removed the path variables for that installation.

I have followed the conda instructions. That line only creates the new environment, named "tensorflow."

I have tried both:

  1. Installing tensorflow within a conda environment and running it within that environment.
  2. Installing tensorflow to the root environment and running it outside of any environment.

Both of these options render the same error.

I can install and run other modules (e.g. theano, yahoo_finance, pandas_datareader) without issue, so this problem is unique to Tensorflow.

tristanbrown commented Jan 10, 2017

The only other python distribution I have installed is WinPython, but I've already removed the path variables for that installation.

I have followed the conda instructions. That line only creates the new environment, named "tensorflow."

I have tried both:

  1. Installing tensorflow within a conda environment and running it within that environment.
  2. Installing tensorflow to the root environment and running it outside of any environment.

Both of these options render the same error.

I can install and run other modules (e.g. theano, yahoo_finance, pandas_datareader) without issue, so this problem is unique to Tensorflow.

@gunan

This comment has been minimized.

Show comment
Hide comment
@gunan

gunan Jan 10, 2017

Member

What is your python installed with WinPython and Anaconda?
Also, Could you confirm all your environment/path variables refer to your anaconda python?

Member

gunan commented Jan 10, 2017

What is your python installed with WinPython and Anaconda?
Also, Could you confirm all your environment/path variables refer to your anaconda python?

@jart

This comment has been minimized.

Show comment
Hide comment
@jart

jart Jan 13, 2017

Member

@tristanbrown Could you also copy and paste your command line session into this bug similar to what @Carmezim did above? That should hopefully help us get a better idea of what's going on, since we can see the error message and the commands you're running.

Member

jart commented Jan 13, 2017

@tristanbrown Could you also copy and paste your command line session into this bug similar to what @Carmezim did above? That should hopefully help us get a better idea of what's going on, since we can see the error message and the commands you're running.

@Carmezim

This comment has been minimized.

Show comment
Hide comment
@Carmezim

Carmezim Jan 14, 2017

Contributor

@jart I followed his same steps to try reporduce the error:

  • Created new anaconda env
  • Activated it
  • Installed clean TensorFlow installation through pip with ignore flag
  • Imported TensorFlow (where his error occurred) and ran snippet successfully

So I assumed is on his side. The difference is I have only one Python distribution which is Anaconda's, while as @gunan pointed out @tristanbrown apparently has WinPython and Anaconda so is something to consider.

Contributor

Carmezim commented Jan 14, 2017

@jart I followed his same steps to try reporduce the error:

  • Created new anaconda env
  • Activated it
  • Installed clean TensorFlow installation through pip with ignore flag
  • Imported TensorFlow (where his error occurred) and ran snippet successfully

So I assumed is on his side. The difference is I have only one Python distribution which is Anaconda's, while as @gunan pointed out @tristanbrown apparently has WinPython and Anaconda so is something to consider.

@jart

This comment has been minimized.

Show comment
Hide comment
@jart

jart Jan 14, 2017

Member

In that case I'll trust your judgement and close this one out. Thank you for your time @Carmezim.

Member

jart commented Jan 14, 2017

In that case I'll trust your judgement and close this one out. Thank you for your time @Carmezim.

@Carmezim

This comment has been minimized.

Show comment
Hide comment
@Carmezim

Carmezim Jan 14, 2017

Contributor

@jart edit: oh, my bad, I misread you asked him to post the cmd session and thought you asked me then replied that. So sorry

Contributor

Carmezim commented Jan 14, 2017

@jart edit: oh, my bad, I misread you asked him to post the cmd session and thought you asked me then replied that. So sorry

@ayushya2531

This comment has been minimized.

Show comment
Hide comment
@ayushya2531

ayushya2531 Apr 3, 2017

@Carmezim I was also able to do the same things as you have shown in your post on 29th Dec. However, I am not being able to run a '.py' file. Anaconda gives the error that there is no module names tensorflow.

ayushya2531 commented Apr 3, 2017

@Carmezim I was also able to do the same things as you have shown in your post on 29th Dec. However, I am not being able to run a '.py' file. Anaconda gives the error that there is no module names tensorflow.

@Carmezim

This comment has been minimized.

Show comment
Hide comment
@Carmezim

Carmezim Apr 3, 2017

Contributor

Hi @ayushya2531, sorry you are having problems. Would you mind to please open a new issue filling the template with the necessary info and commenting me so we can better asses what is happening?

Contributor

Carmezim commented Apr 3, 2017

Hi @ayushya2531, sorry you are having problems. Would you mind to please open a new issue filling the template with the necessary info and commenting me so we can better asses what is happening?

@veryvishal

This comment has been minimized.

Show comment
Hide comment
@veryvishal

veryvishal Apr 11, 2017

I installed using pip3, and then it dint work on python prompt. Used python3 prompt and it worked like a charm!

veryvishal commented Apr 11, 2017

I installed using pip3, and then it dint work on python prompt. Used python3 prompt and it worked like a charm!

@ernestyalumni

This comment has been minimized.

Show comment
Hide comment
@ernestyalumni

ernestyalumni Jul 11, 2017

@Carmezim

I am on Fedora 23 Workstation (will upgrade soon with full reinstall) and --ignore_installed worked perfectly for me, with anaconda installed. In my next reinstall on this system, I would NOT install anaconda because of how it places the site-packages separately other than from root, during pip.

Since I also confirmed pip install --ignore-installed tensorflow-gpu worked without a hitch and I confirmed the GPU ran with import tensorflow-gpu I'll repeat your answer (worth repeating):

In your pip install command, could you try adding the --ignore_installed flag

Question: why did --ignore_installed work? (for the future)

ernestyalumni commented Jul 11, 2017

@Carmezim

I am on Fedora 23 Workstation (will upgrade soon with full reinstall) and --ignore_installed worked perfectly for me, with anaconda installed. In my next reinstall on this system, I would NOT install anaconda because of how it places the site-packages separately other than from root, during pip.

Since I also confirmed pip install --ignore-installed tensorflow-gpu worked without a hitch and I confirmed the GPU ran with import tensorflow-gpu I'll repeat your answer (worth repeating):

In your pip install command, could you try adding the --ignore_installed flag

Question: why did --ignore_installed work? (for the future)

@aritrabasu104

This comment has been minimized.

Show comment
Hide comment
@aritrabasu104

aritrabasu104 Aug 29, 2017

I am having the same issue.. @tristanbrown were u able to solve ur issue?

aritrabasu104 commented Aug 29, 2017

I am having the same issue.. @tristanbrown were u able to solve ur issue?

@tristanbrown

This comment has been minimized.

Show comment
Hide comment
@tristanbrown

tristanbrown Sep 6, 2017

The error came from the multiple Python distributions I had installed. I removed all the other ones from my PATH file, and the issue was resolved.

tristanbrown commented Sep 6, 2017

The error came from the multiple Python distributions I had installed. I removed all the other ones from my PATH file, and the issue was resolved.

@sunsided

This comment has been minimized.

Show comment
Hide comment
@sunsided

sunsided Sep 23, 2017

For me it was similar with TensorFlow built from source. In the end I uninstalled tensorflow and numpy and then reinstalled both (tensorflow first, then numpy via conda); this solved the issue.

sunsided commented Sep 23, 2017

For me it was similar with TensorFlow built from source. In the end I uninstalled tensorflow and numpy and then reinstalled both (tensorflow first, then numpy via conda); this solved the issue.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Nov 21, 2017

For me, the error went I away when I went into the anaconda prompt and activated tensorflow using the pre-installation command: activate tensorflow
But I still have no idea why that worked :/

ghost commented Nov 21, 2017

For me, the error went I away when I went into the anaconda prompt and activated tensorflow using the pre-installation command: activate tensorflow
But I still have no idea why that worked :/

@madhusudangr

This comment has been minimized.

Show comment
Hide comment
@madhusudangr

madhusudangr Jan 22, 2018

@tristanbrown how do we solve the error, when I don't have any python related lines in my PATH file ?

I have multiple python versions(2.7 & 3.5) installed in various envs in Anaconda.

madhusudangr commented Jan 22, 2018

@tristanbrown how do we solve the error, when I don't have any python related lines in my PATH file ?

I have multiple python versions(2.7 & 3.5) installed in various envs in Anaconda.

@superjose

This comment has been minimized.

Show comment
Hide comment
@superjose

superjose Jan 23, 2018

I was having the same problem. I'm running Windows 10 Build 17074 and how I got it running was by opening a Command Prompt (CMD - Not PowerShell) as Administrator, and following the installation tutorial.

superjose commented Jan 23, 2018

I was having the same problem. I'm running Windows 10 Build 17074 and how I got it running was by opening a Command Prompt (CMD - Not PowerShell) as Administrator, and following the installation tutorial.

@madhusudangr

This comment has been minimized.

Show comment
Hide comment
@madhusudangr

madhusudangr Jan 23, 2018

@superjose I tried it in CMD, nothing different. Installation finishes without any error, but I am not able to import tensorflow

madhusudangr commented Jan 23, 2018

@superjose I tried it in CMD, nothing different. Installation finishes without any error, but I am not able to import tensorflow

@superjose

This comment has been minimized.

Show comment
Hide comment
@superjose

superjose Jan 23, 2018

@madhusudangr Did you try running CMD as Administrator?

superjose commented Jan 23, 2018

@madhusudangr Did you try running CMD as Administrator?

@superjose

This comment has been minimized.

Show comment
Hide comment
@superjose

superjose Jan 23, 2018

@madhusudangr I don't know if this will help you, but here's my Path's content inside Environment Variables:
image

If you're using Windows 7/8,x, you can always do:

  1. Go to Computer
  2. Click System Properties.
  3. Click Advanced System Settings
  4. Under the Advanced Tab (Should be already selected) click Environment Variables.

OR:
Press WinKey + Break.

In Windows 10:

  1. Go to Computer and Click System Properties OR Go to Settings and Click System and go to the About tab.
  2. On the right panel, click "System info" which appears under Related Settings.
  3. Click "Advanced System Settings"
  4. Click on "Environment Variables"

Check this image to see if it helps:
image

superjose commented Jan 23, 2018

@madhusudangr I don't know if this will help you, but here's my Path's content inside Environment Variables:
image

If you're using Windows 7/8,x, you can always do:

  1. Go to Computer
  2. Click System Properties.
  3. Click Advanced System Settings
  4. Under the Advanced Tab (Should be already selected) click Environment Variables.

OR:
Press WinKey + Break.

In Windows 10:

  1. Go to Computer and Click System Properties OR Go to Settings and Click System and go to the About tab.
  2. On the right panel, click "System info" which appears under Related Settings.
  3. Click "Advanced System Settings"
  4. Click on "Environment Variables"

Check this image to see if it helps:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment