Active environment uses base/Lib/site-packages instead of <my-env>/Lib/site-packages

I’ve tried to create an environment with Python 3.7 and numpy 1.18 in order to be compatible with an application. The environment, py37-gmat, was created through Navigator, I activated the environment and started a command window from the Environments pane, the terminal showed that py37-gmat was the active environment. I used conda in the terminal to install numpy=1.18. The package was installed successfully and the Navigator Environment pane shows numpy 1.18.5 installed (attached)…

Note: PYTHONPATH is not set for this test.
Note: Anaconda Navigator 2.1.1 on Windows 10,

Open a terminal window from the environment using the Navigator, start python and import numpy. The import fails with the notorious:
“ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath’”

The terminal output shows python 3.7.12 but tries to import the numpy 1.20.3 from the base environment, which fails due to compatibility issues between python3.7 and numpy versions greater than 1.18. The terminal output is as follows:

(py37-gmat) C:\Users\Colin>python
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:37:49) [MSC v.1916 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import numpy
C:\Users\Colin\anaconda3\Lib\site-packages\numpy_init_.py:143: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see GitHub - IntelPython/mkl-service: Python hooks for Intel(R) Math Kernel Library runtime control settings.
from . import distributor_init
Traceback (most recent call last):
File "C:\Users\Colin\anaconda3\Lib\site-packages\numpy\core_init
.py", line 22, in
from . import multiarray
File “C:\Users\Colin\anaconda3\Lib\site-packages\numpy\core\multiarray.py”, line 12, in
from . import overrides
File “C:\Users\Colin\anaconda3\Lib\site-packages\numpy\core\overrides.py”, line 7, in
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\Colin\anaconda3\Lib\site-packages\numpy_init_.py”, line 145, in
from . import core
File “C:\Users\Colin\anaconda3\Lib\site-packages\numpy\core_init_.py”, line 48, in
raise ImportError(msg)
ImportError:

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/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.7 from “C:\Users\Colin\anaconda3\envs\py37-gmat\python.exe”
  • The NumPy version is: “1.20.3”

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’

Seems like there is something wrong with the PATH variable…

In the command windows (opened from Navigator), what is the output of where python and echo %PATH%, and finally echo %PYTHONPATH% ?

Also, interesting to see if you start python (from the terminal, just type python) and then:

import sys
import pprint
pprint.pprint(sys.path)

Hope you get it fixed!

Yes, I played around with the path variable, and got different answers for which python dll was being accessed. It was truly using the py37-gmat environment dll with the base environment numpy. That was so weird I decided to remove the py37-gmat environment and recreate it with a clean machine. Presto/Change-o the new py37 environment behaves as advertised. No idea how I got the original environment balled up in the first place, other than I created the second one from the navigator instead of using the conda command line. I’m sure I fell into some corner case. But all is well that all is well and all is well.

As I continue working with this application, GMAT, I’ve found that the strange behavior above recurs when I set the PYTHONPATH variable. I do this because the GMAT documentation states that PYTHONPATH is used to determine the location of the python site-packages. I’ve gone back and forth with setting this variable to my python37 environment and when it is set, Anaconda seems to perversely go the opposite direction, i.e. my IDE (VSCode) says that it is using the python37 environment, but when I run my script I get a numpy import error showing the base path is used to find site-packages instead of my environment. When I delete the PYTHONPATH environment variable, everything goes back to the way it should. And just to really confuse the issue, when I open Anaconda and activate the python37 environment, GMAT seems to find the correct site-packages as well, without PYTHONPATH.
This is primarily a question for the GMAT forum and I’ll make that my next stop, but I can’t explain this behavior.

Just to close this out… I was unable to resolve this and simply installed Python 3.7 and the needed libraries at the system level C:\ProgramFiles\Python3.7. GMAT works with this configuration but now my entire platform is locked into this specific configuration. GMAT has several open JIRA tickets that provide Anaconda support in GMAT 2022a.