1

I'm using PHP to run python scripts using the exec() function.

After installing Anaconda and making it the default Python install by placing it first in myPATH variable, I was able to import all the modules I needed like Scikit Learn, Numpy etc, and still run the script from PHP using exec().

Here's the problem: when I installed Tensorflow (with Anaconda), by following the instruction on this page, it needs you to activate the Anaconda environment after the install before you can actually use it. It works when I do it on the command line, but I how can I reproduce that activation process from a PHP script? I, understandably get the ModuleNotFoundError. Or to rephrase, how can I make importing Tensorflow as effortless as the other modules that come with Anaconda? Am I missing something?

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
Mav
  • 1,087
  • 1
  • 15
  • 37
  • just to clarify, you have installed tensorflow in the environment and NOT in the root of anaconda? It should have nothing to do with the module and by the sounds of it you are getting confused between the built in packages in the root of anaconda and what's installed in an environment. Can you please clarify exactly how you're configured everything? – JCooke Jul 04 '17 at 12:37
  • I created a conda environment using: 'conda create -n tensorflow python=3.5' and then activated it using: 'activate tensorflow' and then used 'pip install' from within the environment. Is there another way? Can I install it in the root? – Mav Jul 04 '17 at 14:09
  • No that sounds right. It sounds like you're not activating your anaconda directory when you make your php calls. I've not done any work in this though so dont want to lead you down the wrong path. There are probably tutorials available on how to use environments within php somewhere – JCooke Jul 04 '17 at 14:52
  • I'm open to any suggestions, any way of running tensorflow in python from a PHP call? – Mav Jul 04 '17 at 14:56
  • Again, i've never used python through php so I have no idea. Does activating the environment through a shell call before running a file work? I'm not sure sorry. Hopefully someone else can come and give you more help. – JCooke Jul 04 '17 at 15:19
  • That was the first thing I tried, unfortunately no. Thanks any way :) – Mav Jul 04 '17 at 15:41
  • Why not just install `tensorflow` into the root (default) environment? – darthbith Jul 05 '17 at 01:27
  • Without using Anaconda @darthbith? – Mav Jul 05 '17 at 11:17
  • 1
    No, into the root environment of Anaconda. In other words, why create an Anaconda environment just for tensorflow? You said all the other packages worked, why not just install tensorflow there? – darthbith Jul 05 '17 at 13:07
  • Oh god, yeah, it works now. I did try doing that before, but it didn't work because I was using a different python version, and apparently Tensorflow only works with 3.5.2 . More information here https://stackoverflow.com/questions/33622613/tensorflow-installation-error-not-a-supported-wheel-on-this-platform – Mav Jul 05 '17 at 13:40

1 Answers1

1

I solved it by installing Tensorflow in the root, rather than an environment. Keep in mind though, if you're on Windows like me, you'll need to have Python 3.5.2. More on that here

Mav
  • 1,087
  • 1
  • 15
  • 37