1

This post is related to my other one where I was told to use lmfit to fix my problem.

I installed lmfit in anaconda Prompt with conda install --channel "conda-forge" lmfit which worked. But now when I try to use it in my Programm I get the following error:

ModuleNotFoundError: No module named 'lmfit.model'; 'lmfit' is not a package

Thats how the beginning of my Program looks like:

import numpy as np
import math
import scipy    #I dont need scipy, but I read, that lmfit needs scipy. It doesn't change anything when its there or not.
import matplotlib.pyplot as plt
from lmfit.model import GaussianModel

I also tried to import lmfit seperatly like:

import lmfit
from lmfit.model import GaussianModel

But it doesn't work either...

I tried everything from the lmfit website, but using the "git"-thing in Anaconda Prompt gives me an error (something like command doesn't exist)

I also found this post, and importing from lmfit import * works. Now I have the problem that I somehow need to import the GaussianModel, which I don't know how to do. If I just add from lmfit import GaussianModel I get the Error

ImportError: cannot import name 'GaussianModel'

I also read something about the order of importing packages and modules is important - is this what the problem is about? How can I fix this?

I work on windows with anaconda/spider.

Marco
  • 2,007
  • 17
  • 28
Carina
  • 217
  • 4
  • 11
  • It's plural: `from lmfit.models import GaussianModel`. –  Feb 20 '18 at 21:31
  • That, however, does not explain the error message you quote. Check that you're not running this in a directory where you have an `lmfit` directory or `lmfit.py` file, since in that case, Python will attempt to import that (which is likely not the installed package). –  Feb 20 '18 at 21:32
  • Just to be sure if I understand you correctly: I need to go to preferences - Current Working directory and need to choos the directory where lmfit (lmfit-0.9.7-py36_0.json) is (which would be Anaconda/ conda-meta for me)? Or did I missunderstand you? – Carina Feb 20 '18 at 22:24
  • Either `pip install lmfit` or `conda install -c gsecars lmfit` should work. After seeing one of those work, verify that you can do `import lmfit` from the python or ipython prompt in spyder or from a python session started in the "anaconda prompt". You do NOT need to be in the folder where `lmfit` got unpacked. In fact, you don't want a folder or file named `lmfit` in your working directory -- that will cause the confusion Evert is talking about. – M Newville Feb 21 '18 at 00:03
  • No, you want to avoid the directory where you downloaded lmfit, and where it's installed. I don't know how Spyder usually works with directories, since I'm used to the command line, but it seems likely there's a clash between filenames. –  Feb 21 '18 at 02:38
  • Here's a thing to try: *only* `import lmfit`, then `print(lmfit.__file__`) will tell you what file (with its full path) it is using. See if that looks like the correct file, or an incorrect file. –  Feb 21 '18 at 02:39
  • @MNewville @Evert Thank you very much, now it works! I did everything you told me, i guess that `conda install -c gsecars lmfit` made it work :) The path of my file is the following (for others which have the same problem): _C:\Users\Carina\Anaconda3\lib\site-packages\lmfit-0.9.8-py3.6.egg\lmfit\__init__.py_ – Carina Feb 21 '18 at 12:01

0 Answers0