7

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?

philippos
  • 881
  • 3
  • 14
  • 32
  • 2
    Have you created any other environments? Run `import sys` `print( sys.executable)` on both Spyder and Anaconda prompt and see if they both return the same path. – Simon Apr 26 '18 at 08:50
  • 1
    @Simon I run what you said. The Spyder and Anaconda run different paths. How can I move the module from the Anaconda path to Spyder path? Since I already installed many modules which I run on Spyder. – philippos Apr 26 '18 at 09:27
  • Not really sure how this problem has come about. Have you got a virtual environment activated that you forgot to deactivate? – Simon Apr 26 '18 at 09:39
  • 2
    https://conda.io/docs/user-guide/tasks/manage-environments.html – Simon Apr 26 '18 at 09:41
  • 1
    @Simon I never dealt with any environments (Honestly, I don't know how to do that). So basically I didn't change any default thing. – philippos Apr 26 '18 at 09:41
  • 1
    @Simon Thank a lot for the helpful link and hints. So now here is the issue: in spyder I have two environments, one has `osmnx`, and the other doesn't. Is it possible to move the module from an environment to another? or is it possible to specify to which environment I want to install a module? – philippos Apr 26 '18 at 11:24
  • No. You could clone the installation to build an entirely new, but exactly the same as the previous one. Or you would have to install it again. – Simon Apr 26 '18 at 11:27
  • 1
    but if I install it again, it would be exactly at the previous environment, that's why I asked about specifying the environment – philippos Apr 26 '18 at 11:29
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169851/discussion-between-simon-and-philippos). – Simon Apr 26 '18 at 11:30

2 Answers2

7

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.

Community
  • 1
  • 1
Bremsstrahlung
  • 495
  • 1
  • 6
  • 18
  • Thanks, It helped for me, with adding spyder kernel module to python (since spyder maybe wants spyder kernel module, to work) – Alon Samuel Jan 21 '19 at 01:41
  • I had to choose the appropriate interpreter as explained in this answer. If you're having a venv inside a conda env, ensure that you choose the interpreter of the venv. – Van Peer Apr 01 '19 at 16:01
  • 1
    This still didn't solve the issue sadly. – B.Quaink Jan 06 '21 at 10:05
2

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
Undo
  • 25,204
  • 37
  • 102
  • 124
Wasim
  • 119
  • 1
  • 3