简体   繁体   中英

A module is working in Anaconda prompt, but not in Spyder

I have been fighting with this problem for hours now, and it's a kind of complicated one. I'm on windows 7, Python 2.7, Spyder 3.2.6 I tried to install OSMNX through cygwin , however I faced many issues. Finally managed to install it through windows cmd. Through the anaconda prompt , I could import the osmnx with no error.
However, I'm trying to import it in spyder, but I keep receiving:
Traceback (most recent call last):

  File "<ipython-input-2-2b99ab66aebb>", line 1, in <module>
    import osmnx

ImportError: No module named osmnx

What is exactly wrong here? and how can I solve it?

The problem is the use of different environments for your anaconda prompt and your instance of spyder, as mentioned by @Simon. This problem and the different available solutions are reviewed here: GitHub discussion

You can solve the problem as follows. Provided that you have the package spyder-kernels already installed in your Anaconda prompt environment, run the following command in Anaconda prompt:

python -c "import sys; print(sys.executable)"

and copy the path returned to your console. Then, in Spyder go to Tools>Preferences>Python interpreter . Here you will see two options under Select the Python interpreter for all Spyder consoles . Check the second option and paste the path you copied from the Anaconda prompt. Close Spyder and open it again and now the import module command should work.

By doing this, Spyder will basically use the Python interpreter from the environment in which you have installed the new modules.

You need to sync the environment variables/path for both.

Just go to the anaconda promt and enter the command

> conda install spyder

It will automatically prepare the environment. Following that, just open up spyder and execute your code.

I have faced the same problem. I have installed the Spyder and Jupyter inside the conda environment. After that it's working fine for me.

source activate my_conda_env
conda install spyder
conda install jupyter notebook

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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