没有使用Spyder的名为"dolfin"的模块 [英] No module named 'dolfin' using Spyder
问题描述
在我的一生中,我无法让dolfin
与Spyder
一起运行.我一开始就是这么想的.我设法使其以某种方式运行,但不是以一种方便的方式运行.情况如下:
I can't, for the life of me, get dolfin
running 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 fenics
,spyder
,from dolfin import *
: No module named 'dolfin'
.
conda activate fenics
, spyder
, from dolfin import *
: No module named 'dolfin'
.
有效的方法
-
conda activate fenics
,python
,from dolfin import *
:首先起作用. -
conda activate fenics
,ipython
,from dolfin import *
:经过一些调整后可以正常工作. -
conda activate fenics
,spyder
,from 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 fenics
,conda install fenics
和conda 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
的产量分别为python
和ipthon
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 ipython
,ipython
和from dolfin import *
也可以工作! :)
Thus, conda install ipython
, ipython
and from dolfin import *
works as well! :)
运行spyder
和from dolfin import *
会引发与ipython
之前相同的错误:No module named 'dolfin'
.也许spyder
在fenics的环境中也不可用? conda list
...不,不在那里.现在开始有趣的部分... :(
. conda install spyder
和which 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 spyder
,spyder
至少使我返回了间谍.
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 fenics
,spyder
和sys.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 fenics
,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')
由于这只是暂时的解决方法(每次启动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:
-
激活您的环境
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屋!