Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

python - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...