No module named 'dolfin' using Spyder

有些话、适合烂在心里 提交于 2021-02-09 07:23:24

问题


I can't, for the life of me, get dolfinrunning with Spyder. That's what I thought at first. I managed to get it running somehow, but not in a convenient way. Here is the situation:

The error

conda activate fenics, spyder, from dolfin import *: No module named 'dolfin'.

What works

  • conda activate fenics, python, from dolfin import *: worked in the first place.
  • conda activate fenics, ipython, from dolfin import *: worked after some tweaking.
  • conda activate fenics, spyder, from dolfin import *: worked after some tweaking.

What I've done so far

I installed anaconda using the suggested download from conda.

Running conda create -n fenics -c conda-forge fenics, conda install fenics and conda activate fenics to install and activate the fenics environment.

Then starting python and executing from dolfin import * works. :)

Running the same command in ipython doesn't work. Using conda list I found out that

    ...
    hdf5
    hypre
    icu
    isl
    jedi
    ...

there is no ipython in the list and which with python and ipthon yields

    /home/hannes/anaconda3/envs/fenics/bin/python
    /home/hannes/anaconda3/bin/python

Thus, conda install ipython, ipython and from dolfin import * works as well! :)

Running spyder and from dolfin import * throws the same error as with ipython before: No module named 'dolfin'. Maybe spyder isn't available in fenics' environment as well? conda list ... nope, not there. Now begins the fun part ... :(. conda install spyder and which spyder yields

    /home/hannes/anaconda3/envs/fenics/bin/spyder

However, running spyder throws the error

    libGL error: unable to load driver: r600_dri.so
    libGL error: driver pointer missing
    libGL error: failed to load driver: r600
    libGL error: unable to load driver: r600_dri.so
    libGL error: driver pointer missing
    libGL error: failed to load driver: r600
    libGL error: unable to load driver: swrast_dri.so
    libGL error: failed to load driver: swrast
    Segmentation fault (core dumped)

That seems to be some opengl issues. The solution from github issue 6968, conda install pyopengl, didn't help :(; still the same libGL errors. Therefore, conda uninstall spyder, spyder at least gave me back spyder.

My best clue so far

I tried adding the module to PYTHONPATH by adding

    export PYTHONPATH="$PYTHONPATH:/home/hannes/anaconda3/envs/fenics/lib/python3.6/site-packages/"

to .bashrc and running a Spyder that is not inside the fenics environment. No success, although I am not sure whether I did this step correctly. Why, conda activate fenics, spyder and sys.path spits out:

    /home/hannes/anaconda3/lib/python3.6/site-packages/spyder
    /home/hannes/anaconda3/lib/python36.zip
    /home/hannes/anaconda3/lib/python3.6
    /home/hannes/anaconda3/lib/python3.6/lib-dynload
    /home/hannes/.local/lib/python3.6/site-packages
    /home/hannes/anaconda3/lib/python3.6/site-packages
    /home/hannes/anaconda3/lib/python3.6/site-packages/IPython/extensions
    /home/hannes/.ipython

Since that didn't work I got from dolfin import * working after running conda activate fenics, ipython

    import sys
    sys.path.append('/home/hannes/anaconda3/envs/fenics/lib/python3.6/site-packages')

Since this is only a temporarily workaround (I have to add it every time I start Spyder) I am interested in a permanent fix.

I'd appreciate any help :).

Hannes


回答1:


(Spyder maintainer here) Since Spyder 3.3.1 (to be released in a couple of days), the solution is the following:

  1. Activate your environment

  2. Install the spyder-kernels package there, with the following command:

    conda install spyder-kernels=0.*

  3. Also run there (in a system terminal)

    python -c "import sys; print(sys.executable)"

    and copy the path returned by that command.

  4. Deactivate your environment and start Spyder from your root or base one.

  5. Go to

    Tools > Preferences > Python Interpreter > Use the following interpreter

    and paste there the path you got in step 3.

  6. Start a new IPython console and run

    from dolfin import *

    It should work now.



来源:https://stackoverflow.com/questions/51466931/no-module-named-dolfin-using-spyder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!