0

Problem having two versions of python on my Mac and them interacting. I have the following python locations

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

python is /usr/bin/python

and when I try to run a script. I get the following error:

Fatal Python error: PyThreadState_Get: no current thread

Abort trap: 6

I have googled some solutions and have found some posts saying I should try

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

Harun Yilmaz
  • 8,281
  • 3
  • 24
  • 35
Kori
  • 111
  • 6

2 Answers2

1

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.

I also found https://github.com/enthought/mayavi/issues/552 which suggests pinning to a different version of 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:

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. It might also be possible to use a later version of python (I only tried 3.5.1).

James Brusey
  • 355
  • 3
  • 11
  • I think it is the dolphin. I will try it and update shortly – Kori Jun 12 '19 at 20:52
  • It did not help :( – Kori Jun 12 '19 at 21:12
  • Try looking through the suggestions in the link starting with the otool command. – James Brusey Jun 13 '19 at 04:43
  • If you want further help, can you give more detail about where you are installing dolfin from and if something like `python -c import dolfin` reproduces the problem. – James Brusey Jun 13 '19 at 08:10
  • when I copy and paste python -c import dolfin I get the error. File "", line 1 import ^ SyntaxError: invalid syntax – Kori Jun 13 '19 at 18:43
  • Apologies, I meant `python -c "import dolfin"` – James Brusey Jun 14 '19 at 06:25
  • Ty, when I try that I get the same error as before Fatal Python error: PyThreadState_Get: no current thread – Kori Jun 16 '19 at 05:43
  • That’s a good step because now you have a simple way to check if you still have the problem. Now we need to know how you are installing dolfin and from which repository. Please give as much detail here as you can. – James Brusey Jun 16 '19 at 05:48
  • So what I am doing is I am calling "conda activate fenicsproject" from the terminal . Which is a way to run this library/software FEniCS, but I am doing it thru anaconda. The weird thing is that this use to work well, but then one time I tried to run it from the anaconda/spyder IDE and then everything broke. – Kori Jun 16 '19 at 05:52
  • What does `cat ~/.condarc` give you? – James Brusey Jun 16 '19 at 06:00
  • ssl_verify: true channels: - defaults – Kori Jun 16 '19 at 06:06
  • Was hoping to see which channel you installed `fenicsproject` from. According to https://fenicsproject.org/qa/12494/fenics-on-anaconda/ the right way is to install `fenics` from `conda-forge`. You probably want to uninstall fenicsproject completely first. – James Brusey Jun 16 '19 at 06:18
  • I could not find exact directions how to uninstall FEniCS. What I did was uninstall anaconda and install everything a new, but that did not help. – Kori Jun 16 '19 at 06:27
  • From the terminal, use `conda uninstall fenicsproject` – James Brusey Jun 16 '19 at 06:35
  • This very weird when I tried this command I got WARNING: The conda.compat module is deprecated and will be removed in a future release. Collecting package metadata: done Solving environment: failed PackagesNotFoundError: The following packages are missing from the target environment: - fenicsproject – Kori Jun 16 '19 at 07:15
  • I did install fenics for sure following the commands from https://hippylib.readthedocs.io/en/latest/installation.html. – Kori Jun 16 '19 at 07:16
  • Thanks @Kori - this makes it a lot clearer. `fenicsproject` is the anaconda environment that you are installing in. To reinstall, based on these instructions, you need `conda remove -n fenicsproject fenics` and then `conda install -n fenicsproject fenics==2017.2.0` – James Brusey Jun 16 '19 at 07:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195022/discussion-between-kori-and-james-brusey). – Kori Jun 16 '19 at 17:57
0

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.

What you largely want to avoid is a situation where you are running Python scripts via your native system Python (2, likely).

Check which version of Python your IDE is using (from: How do I check what version of Python is running my script?):

import sys
print(sys.version)

Is the first number a 2? Did you want to use Python 2?

Next, let's check what version your system currently defaults to. If Ubuntu/Linux, use:

python -V

Is this expected? If not, you may need to change your system environmental variables to point to the correct Python version. 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; if Ubuntu/Linux, check your .bashrc file:

gedit ~/.bashrc

to see if the system points to the correct Python variable. If using a Mac, I formally apologize.

  • Mojave 10.14.5 and the python is 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 02:16:08) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] – Kori Jun 13 '19 at 18:38
  • And the default python is Python 3.6.7 . Which is what I want to use, I think the problem arises only when I call the dolfin – Kori Jun 13 '19 at 18:41