Mike Lanza
Mike Lanza

Reputation: 67

Working with Spyder IDE and virtualenv. Changing interpreter but does not seem to update

I'm currently working with Spyder version 3.2.8 and Python 3.6. I have created a virtual base python environment using virtualenv. Within that virtual environment, I have installed a few packages including ipykernel and cloudpickle to work in Spyder.

When I open up Spyder and change the interpreter to the location of the virtualenv, I do not see this update in the console. I tried restarted spyder and it appears to be launch a default generic ipython console. If I try to import a package that I installed in the virtual environment, I get the typical "no module" error. If I perform this same function within the virtualenv in the cmd window, I get no error.

What am I doing wrong? Any help understanding the difference between the virtual environments and these ipykernels would be helpful, it's all still new and confusing.

Upvotes: 1

Views: 4262

Answers (1)

Mike Lanza
Mike Lanza

Reputation: 67

I solved this by running Spyder from the virtual environment after activating it. To do this run

activate myenv
pip install spyder
spyder3

For whatever reason, Spyder was not pulling in the right environment even after changing the interpreter in the program. By opening spyder through the virtual environment, it ran correctly.

One final thing to note, when switching between virtual environments and running them this way, you still need to update the interpreter to point to the virtual environment to avoid confusion.

UPDATE So after doing more digging I found that the reason I was having so many issues with the Spyder installed with Anaconda is because it utilizes the site-packages folder that is installed with Anaconda. I could not find out how to get Spyder to not look at these site packages even AFTER point to different interpreters. It would be great if someone has a better solution to this but for right now, f you want to work with Spyder with a truly fresh install, I suggest creating a virtualenv spcific for this and installing spyder via the code above. For simplicity, I then created a shortcut to the spyder3 app that was installed and will be opening spyder from there.

NOTE: You still need to update your interpreter if you have specific packages installed across them. You will also need to install packages to environment where Spyder is installed to view data objects correctly in the variable explorer (ie: pandas to view dataframes). Be sure to reset spyder after doing this for changes to take place.

Upvotes: 3

Related Questions