0
votes

I am using Python 3.8 on a Ubuntu 20.04 computer. So far, I had no problem importing packages from either Spyder of Jupyter.

I have created a conda virtual environment called theory using Python 3.6, as confirmed by running python --version from within this conda environment.

conda list reveals that numpy is installed:

numpy 1.19.4 pypi_0 pypi

Opening a Python interactive session from the terminal and importing numpy in there works like a charm. However, when trying to import numpy from within Spyder, I am getting a "Module Not Found" error:

ModuleNotFoundError: No module named 'numpy'

Here is what I tried to fix this issue:

  • I tried uninstalling and reinstalling numpy using pip install numpy (and pip3 install numpy).
  • I tried updating conda following the answer provided in this GitHub post: conda update --prefix /home/sheldon/anaconda3 anaconda .
  • I tried specifying the path to the numpy package in the PYTHONPATH manager directly in Spyder, pointing to /home/sheldon/anaconda3/envs/

What am I doing wrong here?

EDIT: I checked that Numpy 1.9.4. actually supports Python 3.6

EDIT: Just recreated a new Python 3.6 environment from scratch and I can import numpy just fine...

1
Try this. Within Spyder, go to Tools-->Preferences-->PythonInterpreter, and choose the file called python.exe under envs/theory. Then close and re-open Spyder. The path to your envs folder depends upon your os, I think it is under your Anaconda folder. Note -- this worked for all my previous conda envs, but didn't work for my most recently created conda env, for some reason. For that, I had to actually install spyder-kernels package within the env itself, and run spyder from within that conda env (using conda command-line). Can't say I understand much, just thinking out loud.fountainhead
Thanks for your suggestion. I tried all possible interpreters (python, python3, python3.6, python3.6m) in anaconda3/envs/theory/bin but all of these made the kernel crash. I had to revert back to the default interpreter (i.e. the same as Spyder).Sheldon
The interesting thing is that in spite of having a Python 3.6 installed, Spyder indicates to be running under Python 3.8.5. I wonder if this could be the cause of my problem.Sheldon
Yes, showing the wrong version of Python could be the clue. My other suggestion might work. (Installing spyder-kernels within the env -- after activating the env. Then, running spyder from the conda env itself). Sorry to be throwing blind suggestions, without full knowledge. Just in case you're in the mood for it.fountainhead
This old question of yours and its answer seem to be still relevant for your current problem.fountainhead

1 Answers

0
votes

can you please try this :

uninstall numpy with pip uninstall and re install it with

conda install numpy

Not pip install..