没有使用Spyder的名为"dolfin"的模块 [英] No module named 'dolfin' using Spyder

查看:176
本文介绍了没有使用Spyder的名为"dolfin"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一生中,我无法让dolfinSpyder一起运行.我一开始就是这么想的.我设法使其以某种方式运行,但不是以一种方便的方式运行.情况如下:

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:

错误

conda activate fenicsspyderfrom dolfin import *: No module named 'dolfin' .

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

有效的方法

  • conda activate fenicspythonfrom dolfin import *:首先起作用.
  • conda activate fenicsipythonfrom dolfin import *:经过一些调整后可以正常工作.
  • conda activate fenicsspyderfrom dolfin import *:经过一些调整后可以正常工作.
  • 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.

我到目前为止所做的事情

我使用从conda建议的下载安装了anaconda.

I installed anaconda using the suggested download from conda.

运行conda create -n fenics -c conda-forge fenicsconda install fenicsconda activate fenics以安装并激活fenics环境.

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

然后启动python并执行from dolfin import *即可. :)

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

ipython中运行相同的命令不起作用.使用conda list我发现了

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

    ...
    hdf5
    hypre
    icu
    isl
    jedi
    ...

列表中没有ipython,并且which的产量分别为pythonipthon

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

因此,conda install ipythonipythonfrom dolfin import *也可以工作! :)

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

运行spyderfrom dolfin import *会引发与ipython之前相同的错误:No module named 'dolfin'.也许spyder在fenics的环境中也不可用? conda list ...不,不在那里.现在开始有趣的部分... :(. conda install spyderwhich spyder产量

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

但是,运行spyder会引发错误

    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)

这似乎是一些opengl问题. github问题6968 conda install pyopengl的解决方案没有帮助:(;仍然是相同的libGL错误.因此,conda uninstall spyderspyder至少使我返回了间谍.

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.

到目前为止我最好的线索

我尝试通过添加将模块添加到PYTHONPATH中

I tried adding the module to PYTHONPATH by adding

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

.bashrc并运行不在fenics环境内的Spyder.没有成功,尽管我不确定我是否正确执行了此步骤.为什么conda activate fenicsspydersys.path吐出来:

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

由于无法正常工作,我在运行conda activate fenicsipython

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')

由于这只是暂时的解决方法(每次启动Spyder时我都必须添加它),我对永久性修复很感兴趣.

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

我将不胜感激:).

Hannes

推荐答案

(此处为 Spyder维护者)自Spyder 3.3.1 起(将在几天后发布) ),解决方法如下:

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

  1. 激活您的环境

  1. Activate your environment

使用以下命令在其中安装spyder-kernels软件包:

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

conda install spyder-kernels=0.*

也在此运行(在系统终端中)

Also run there (in a system terminal)

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

并复制该命令返回的路径.

and copy the path returned by that command.

停用您的环境,然后从根目录或基础目录启动Spyder.

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

转到

Tools > Preferences > Python Interpreter > Use the following interpreter

并在其中粘贴您在第3步中获得的路径.

and paste there the path you got in step 3.

启动新的IPython控制台并运行

Start a new IPython console and run

from dolfin import *

现在应该可以使用.

这篇关于没有使用Spyder的名为"dolfin"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆