Seite 1 von 1
tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 08:16
von aleph
ch habe Anaconda und Tensorflow wie in
https://www.tensorflow.org/install/inst ... h_anaconda beschrieben installiert. Wenn ich von cmd aus das Testprogramm
Code: Alles auswählen
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
starte, funktioniert alles. Wenn ich aber in PyCharm dasselbe Programm starte, kommt:
ModuleNotFoundError: No module named 'tensorflow'
Wenn ich cmd neu starte, und import tensorflow in python mache, kommt derselbe Fehler. Er verschwindet, wenn ich vorm Starten von python "activate tensorflow" mache.
Also müsste ich in PyCharm vorm Starten des Programms activate tensorflow machen. Ich habe bei "Run ..." als externes Tool "activate tensorflow" hinzugefügt, aber dann kommt "Cannot run program "activate"". Edit: Ich habe jetzt "C:\Anaconda\Scripts\activate.bat" als externes Tool hinzugefügt, und der Fehler bezüglich des Startens von activate ist jetzt weg. Der Fehler "ModuleNotFoundError: No module named 'tensorflow'" kommt allerdings immer noch.
Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 10:29
von __deets__
Activate wird nicht gehen, weil es die Umgebung ändert. Anaconda hat sich da augenscheinlich eine Parallelwelt zu virtualenv, pip und co gebaut. Wenn das analog ist, dann findest du im eng Verzeichnis ein Python executable, und kannst das verwenden. Ansonsten googelt es sich bestimmt was schönen mit anaconda and & pycharm
Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 11:09
von aleph
Ich habe nach "anaconda pycharm tensorflow" gegoogelt und gefunden:
http://stackoverflow.com/questions/3786 ... rary-issue Ich habe
Go to settings (ctrl+alt+s or File menu->Settings or alt+f+t)
Under Prject: go to Project Interpreter
Choose the interpreter you'd like to use
Click on the gear button (Right top - next to the interpreter selection)
Click More
Click on the right interpreter for your project again and then on the fifth button on the right:
enter image description here
Click on the + button and add the path for your directory containing init file of this library.
gemacht (mit dem Pfad C:\Anaconda\envs\tensorflow\Lib\site-packages) und der Fehler ist weg, allerdings kommt jetzt ein neuer Fehler:
Traceback (most recent call last):
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
import tensorflow as tf
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
import numpy as np
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda\envs\tensorflow\Lib\site-packages\numpy\core\__init__.py", line 24, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Process finished with exit code 1
Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 11:23
von BlackJack
@aleph: Das sieht so ein bisschen so aus als wenn Du `tensorflow` für eine Python-Installation installiert hast und jetzt versuchst das in einer anderen Python-Installation auszuführen.
Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 11:24
von aleph
BlackJack hat geschrieben:@aleph: Das sieht so ein bisschen so aus als wenn Du `tensorflow` für eine Python-Installation installiert hast und jetzt versuchst das in einer anderen Python-Installation auszuführen.
Ich habe nur Anaconda 4.3.1 64 Bit, Python 3.6 installiert. Edit: Ich mache gerade mal "conda update --all" und "conda update numpy". Mal sehen, ob es was bringt. Edit2: Der Fehler bleibt bestehen.

Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 12:02
von kbr
@aleph: Du warst schon auf dem richtigen Weg mit den PyCharm-Einstellungen. Conda ist ein Paketmanager der zusätzlich environments anlegen kann, also das Pendant zu virtualenv. Mit 'activate' kannst Du zwischen diesen envs umschalten (hierfür wird der Systempfad modifiziert). Deshalb klappt es im Terminal. PyCharm scheint dies aber zu ignorieren, so dass Du den Pfad zum Python-Interpreter des Environments, das alle erforderlichen Abhängigkeiten enthält, manuell angeben musst. Das hat für PyCharm den Vorteil, dass Du die Environments von PyCharm aus auswählen und umschalten kannst.
Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 12:05
von aleph
@kbr: Der Python-Interpreter in den Einstellungen ist auf C:\Anaconda\python.exe eingestellt. Was soll ich genau noch machen?
Re: tensorflow verwenden
Verfasst: Montag 1. Mai 2017, 17:08
von __deets__
Leider scheint anaconda da nicht so zu arbeiten wie virtualenv. Du koenntest mal probieren, ob du zuerst das env aktivierst, und wenn dann alles klappt (import numpy etc) ueber die Kommandozeile, dann startest du PyCharm *VON DER KOMMANDOZEILE*. Und schaust mal, ob das klappt.
Wenn ja, dann haengt das "einfach" an den Umgebungsvariablen die Anaconda setzt. Die kann man ggf. auch in PyCharm als run-configuration angeben, da kann aber wieder Google helfen.