简体   繁体   English

有两个版本的python问题

[英]Issue with two versions of python

Problem having two versions of python on my Mac and them interacting. 在我的Mac上有两个版本的python以及它们交互时出现问题。 I have the following python locations 我有以下python位置

python is /anaconda3/envs/fenicsproject/bin/python python是/anaconda3/envs/fenicsproject/bin/python

python is /usr/bin/python python是/usr/bin/python

and when I try to run a script. 当我尝试运行脚本时。 I get the following error: 我收到以下错误:

Fatal Python error: PyThreadState_Get: no current thread 致命的Python错误:PyThreadState_Get:当前没有线程

Abort trap: 6 中止陷阱:6

I have googled some solutions and have found some posts saying I should try 我在Google上搜索了一些解决方案,并发现了一些帖子说我应该尝试

env PYTHON_CONFIGURE_OPTS="--enable-framework"  #or 
env PYTHON_CONFIGURE_OPTS="--enable-shared" 

This is they type of code I try to run 这是我尝试运行的代码类型

#Import packages 
import dolfin as dl

I installed the env fenics by following the directions here 我按照这里的指示安装了env fenics

The google search possibly found Homebrew + Python on mac os x 10.8: Fatal Python error: PyThreadState_Get: no current thread importing mapnik however I was unable to find the library that links to a wrong version of python using otool . 谷歌搜索可能在Mac OS X 10.8上发现了Homebrew + Python:致命的Python错误:PyThreadState_Get:当前没有导入mapnik的线程,但是我找不到使用otool链接到错误版本的python的otool

I also found https://github.com/enthought/mayavi/issues/552 which suggests pinning to a different version of python. 我还发现https://github.com/enthought/mayavi/issues/552 ,它建议固定到其他版本的python。

Based on the install notes for hippy, https://hippylib.readthedocs.io/en/latest/installation.html then where they say conda create -n fenicproject ... you need to substitute the following: 根据嬉皮士的安装说明, https: conda create -n fenicproject ... ,然后在他们说conda create -n fenicproject ...您需要替换以下内容:

conda create -n fenicsproject python==3.5.1
conda install -n fenicsproject -c conda-forge fenics==2017.2.0 \
               mpi4py matplotlib scipy sympy==1.1.1 jupyter

After this, python -c 'import dolfin' no longer fails. 之后, python -c 'import dolfin'不再失败。 It might also be possible to use a later version of python (I only tried 3.5.1). 也可以使用更高版本的python(我只尝试了3.5.1)。

What OS are you using? 您正在使用什么操作系统? That will largely determine the specifics of how to go about correcting this issue, but the key here is which Python version the system path points to and what Python version your IDE is pointing to. 这将在很大程度上确定如何解决此问题的细节,但是这里的关键是系统路径指向哪个Python版本以及您的IDE指向哪个Python版本。

What you largely want to avoid is a situation where you are running Python scripts via your native system Python (2, likely). 您要避免的情况是您通过本机系统Python(可能为2)运行Python脚本。

Check which version of Python your IDE is using (from: How do I check what version of Python is running my script? ): 检查您的IDE正在使用哪个Python版本(来自: 如何检查正在运行脚本的Python版本? ):

import sys
print(sys.version)

Is the first number a 2? 第一个数字是2吗? Did you want to use Python 2? 您是否要使用Python 2?

Next, let's check what version your system currently defaults to. 接下来,让我们检查系统当前默认使用的版本。 If Ubuntu/Linux, use: 如果是Ubuntu / Linux,请使用:

python -V

Is this expected? 这是预期的吗? If not, you may need to change your system environmental variables to point to the correct Python version. 如果不是,则可能需要更改系统环境变量以指向正确的Python版本。 The solution to this is OS dependent. 解决方案取决于操作系统。 If Windows, search "Edit Environmental Variables for Your Account" -> "Environmental Variables" -> "Path" , be sure it either points to Anaconda or the correct Python version; 如果是Windows,请搜索“为您的帐户编辑环境变量”->“环境变量”->“路径”,确保它指向Anaconda或正确的Python版本。 if Ubuntu/Linux, check your .bashrc file: 如果是Ubuntu / Linux,请检查您的.bashrc文件:

gedit ~/.bashrc

to see if the system points to the correct Python variable. 查看系统是否指向正确的Python变量。 If using a Mac, I formally apologize. 如果使用Mac,我正式道歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM