0

I have Anaconda installed in Ubuntu (followed the instructions on the Anaconda site: https://docs.anaconda.com/free/anaconda/install/linux/) and I am trying to import the fenics module in Spyder. While I am able to import fenics from the terminal, I am not able to do so on Spyder (opened from the same environment) or IPython.

I have the environment named fenicsproject created with a fenics installation and activated in Anaconda:

conda create -n fenicsproject -c conda-forge fenics
source activate fenicsproject

I am able to import fenics if I type python in the terminal while in the fenicsproject environment.

Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or license for more information.

>>> import fenics

However, when I type

spyder

while also in the fenicsproject environment, to open the Spyder IDE, it seems to open a different environment where fenics is not installed. Running the command

import fenics

from either the console or editor results in the

No module named 'fenics'

error. The console in the Spyder IDE shows the header text

Python 3.11.4 (main, Jul 5 2023, 14:15:25) [GCC 11.2.0]
Type "copyright", "credits" or "license" for more information.

IPython 8.12.0 -- An enhanced Interactive Python

Notice that the GCC version is different in the Spyder console than the terminal.

Conda info: conda version: 23.7.2 conda-build version: 3.26.0 python version: 3.11.4.final.0

Tzane
  • 2,752
  • 1
  • 10
  • 21
user279043
  • 111
  • 1

1 Answers1

1

It turns out that I did not have Spyder or IPython installed in the fenicsproject environment, so it defaulted to the installations in the base environment. To install in the fenicsproject environment, I first made sure this environment is activated:

conda activate fenicsproject

and then ran:

conda install ipython

and

conda install -c conda-forge spyder

Tzane
  • 2,752
  • 1
  • 10
  • 21
user279043
  • 111
  • 1
  • (*Spyder maintainer here*) Another, simpler option, is to change the Python interpreter Spyder uses to create new consoles, as described in [our documentation](http://docs.spyder-ide.org/current/faq.html#using-existing-environment). That way you won't need to install Spyder in every env you create and want to use with it. – Carlos Cordoba Aug 21 '23 at 17:44