17

I created a conda environment called testenv in Windows 10 that contains Python 3.6 and Spyder. I also installed Selenium using the method described in this answer. I checked that these packages are installed with

conda list -n testenv

To run Spyder in that environment I followed the instructions in this answer and its related comments. So I activated the environment with

activate testenv

which modified the prompt to indicate that testenv is active. Then I typed

spyder

to launch Spyder. (When Spyder opens, my command window automatically closes, and if I open another one without closing Spyder, and I issue the command conda info -e, the output indicates that testenv is no longer active.) At this point, when I run code within Spyder that contains the line

from selenium import webdriver

the Spyder console reports

ModuleNotFoundError: No module named 'selenium'

My questions are:

Is Spyder really running in testenv? If so, why is this error being reported? If not, what am I doing wrong?


EDIT: Further research turned up the aptly-named thread "Spyder does not run in Anaconda virtual environment on Windows 10". I followed the suggestion, in the accepted answer, of installing Spyder after activating the environment, but that just returned the message

# All requested packages already installed.
# packages in environment at C:\Anaconda3\envs\testenv:
#
spyder                    3.2.2                    py36_0

One of that answer's comments suggests using where spyder within the active environment to check which executables are available. This returned

C:\Anaconda3\Scripts\spyder.exe
C:\Anaconda3\envs\testenv\Scripts\spyder.exe

So I tried starting Spyder by typing the full path of the second entry. Spyder opened, and my program ran without errors. This seems to have solved the problem.

Robert
  • 2,111
  • 4
  • 18
  • 32
  • Rather than editing your question with your solution, please add it as an answer below! :-) Thanks – darthbith Sep 12 '17 at 15:48
  • Does this answer your question? [How to run Spyder in virtual environment?](https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment) – questionto42 Oct 24 '20 at 10:32

2 Answers2

12

I issued the command where spyder within the active environment to check the locations of Spyder's executables. This returned

C:\Anaconda3\Scripts\spyder.exe
C:\Anaconda3\envs\testenv\Scripts\spyder.exe

So I started Spyder by typing the full path of the second entry, and my program ran without errors.

Robert
  • 2,111
  • 4
  • 18
  • 32
  • This solution works for me, but only with 2 modifications **(A)** My env's `python.exe` is at the path `\envs\`, and not at the path `\envs\\Scripts` **(B)** My switching from one `python.exe` to another seems to take effect only if I restart Spyder's kernel, using the option `Consoles==>Restart kernel`. I might add that I'm using Spyder version 3.3.2, and Anaconda version 1.6.2 – fountainhead Jul 03 '19 at 10:26
  • you can also look for the symbolic link created inside the environment, make a copy of it, an use it to launch spyder from wherever is convenient. – PatrickT May 24 '20 at 07:51
5

You can also use the Windows based link that is generated in the Windows menu. The steps:

  1. (in anaconda:) activate testenv

  2. (in anaconda testenv:) conda install spyder

  3. Look up the windows menu "recently added", find spyder (testenv) and [add that to taskbar] and / or [look up the file source location] and copy that to your desktop. In my case, the latter approach opened the directory C:\Users\USER\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) where the spyder links for any of my environments could be found; you can then copy them to your desktop for a direct start without the need to open anaconda prompt.

questionto42
  • 7,175
  • 4
  • 57
  • 90