spyder: Conflict python between Spyder, Octave and TensorFlow

Hello, I am very new of python environment. After some time spent learning python through Anaconda on Windows PC (in particular with Spyder), I also decided to learn Tensorflow, always in Spyder. So, I created a new dedicated environment for TF with the v3.6.9 and v1.17.2, respectively, for python and numpy.

I have never had problems running codes that require TF import with this configuration. However, after some time, to use the Octave symbolic library I had to download Python from Microsoft Store. The downloaded version were 3.8.3 and I also installed the pip package from cmd. The symbolic package in Octave works, but from that moment when I run a code in Spyder that requires the import of tensorflow, I get the following error:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devd_ocs/user/trou_bleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.6 from "C:\Users\ivang\.conda\envs\tensorflow_cpu\python.exe"
  * The NumPy version is: "1.18.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named `'numpy.core._multiarray_umath_'

As suggested, checking my PATH and PYTHONPATH environment variables I obtained the paths in the attached picture. PATHS These environment variables were not created by me, but by Python at the time of its stand-alone installation.

I understand that the problem is related to the different versions of python installed, but why this conflict happens if I created a dedicated environment in Anaconda, as explained at the beginning of the post? How can I solve this conflict using both TF in Spyder and the library in Octave on the same PC?

I tried to uninstall Python 3.8 but the environment variables remain and also the directory in C:\Program Files\Python38\ where site packages are installed.

Thank you so much for the help, IG

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Hey, so this is a pretty tricky issue that us Spyder developers struggle with too. As @juanis2112 explained, Spyder is using your Anaconda Python (as you intend), but then tries to load the Numpy 1.18 installed alongside Octive due to the PYTHONPATH, which takes precedence over the PATH. The Octave-Python-related entries in your PATH actually don’t directly contribute to the problem because they are at the end, and the Anaconda entries at the beginning override them (which you don’t see in your system PATH variable outside of Spyder since Anaconda adds them dynamically).

However, in your case there is a pretty straightforward solution, which I’ve confirmed works with Octave, Symbolic, and Anaconda: Uninstall the Python you installed and just point Symbolic to Anaconda’s own Python and SymPy instead, following Symbolic’s recommended install procedure.


To do this:

  1. Uninstall the Python 3.8 you installed from the Windows store, and any other stray Pythons on your system
  2. Delete the PYTHONPATH environment variable and the Python38-related PATH entries from Windows control panel
  3. Delete the directories %ProgramFiles%/Python38 and %appdata%/python if they still exist.
  4. Reboot your machine
  5. In Octave, enter the command setenv PYTHON C:/ProgramData/Anaconda3/python.exe to point Symbolic to your Anaconda Python
  6. Start and use Symbolic as you normally would (pkg load symbolic then syms x)

To avoid having to repeat step 5 every time you start Octave, in Control Panel create/set the PYTHON system environment variable to C:\ProgramData\Anaconda3\python.exe (or whatever path worked in Step 5) and reboot your machine, and you’ll be good to go. Thanks, and best of luck!

I’m glad you could fix it with what @CAM-Gerlach suggested! @IvanGas Thanks for your kind words. We’re happy to help!

Happy Spydering!

Thank you. Now is perfect. I had already read the Symbolic’s recommended install procedure, but as well as for eliminating the PYTHONPATH variable, I didn’t want to act manually every time I wanted to use Octave. I thank you, @CAM-Gerlach, and also @juanis2112 for the remarkable help you have given me. I was very surprised (positively) for the professionalism and help of the Spyder developers and support!

Thanks a lot!

Glad that worked! For the record, the above solution was very much a team effort between me and @juanis2112 , and she deserves most of the credit for it, she just didn’t happen to have a Windows machine handy to work out and test the procedure.

We really appreciate your thoughtful remarks! Its the support and kind words from users like you that makes Spyder possible and motivates us to do what we do every day. Thanks, and happy Spydering!

Yes, it seems that the path C:\Program Files\Python38\Lib\site-packages is what is breaking spyder. Try deleting it from your PATH, along with C:\Program Files\Python38\ andC:\Program Files\Python38\Scripts