pythonnlopt

I have nlopt installed but get the message: no module named 'nlopt'


I have installed nlopt with the: conda install -c conda-forge nlopt

and I can see the package installed when I do: conda list

but when I try to import it on Spyder, I get the message: No module named 'nlopt'. I'm running it on Windows 10, if that is any help, and I'm completely new to python!

Anyone have any idea on how to solve it? Thanks in advance :)


Solution

  • It usually happens while working in several environments.

    1. Check the environment in which nlopt is installed.
    2. Check if Spyder is in the same environment. To do that, you can go to Spyder > Tools > Python interpreter > Use the following Python interpreter and browse to the python.exe of the environment where nlopt is installed. (anaconda3/envs/your_env/python.exe)
    3. You can also activate the environment and do a where spyder which will give you instances of Spyder.

    ...\anaconda3\envs\your_env\Scripts\spyder.exe ...\Anaconda3\Scripts\spyder.exe

    You can copy and run the exe file corresponding to your environment (here, the first one) and it will launch Spyder in that specific environment.