Search code examples
pythonspyder

Stop Spyder from importing modules like `numpy`, `pandas`, etc


When I start Spyder, it automatically imports pandas and numpy. Is it possible to have Spyder ignore these modules?

I see these are imported in multiple Spyderlib files. For example, pandas gets imported in spyderlib/widgets/importwizard.py, spyderlib/baseconfig.py, etc.

(I'm trying to debug something in pandas and I'd like to import it for the first time in a debugging session in Spyder)


Solution

  • (Spyder dev here) This is not possible. If Pandas is installed on the same Python installation where Spyder is, then Spyder will import Pandas to: a) report to its users the minimal version needed to view DataFrames in the Variable Explorer and b) import csv files as DataFrames.

    The only solution I can suggest you is this:

    1. Create a new virtualenv or conda environment

    2. Install there Spyder and its dependencies, but not Pandas. Spyder dependencies can be checked under the menu Help > Optional dependencies

    3. Start your virtualenv/conda env Spyder

    4. Go to

      Tools > Preferences > Console > Advanced Settings > Python executable

      select the option Use the following Python interpreter and write (or select) there the path to the interpreter where you have Pandas installed (e.g. /usr/bin/python)

    5. Start a new Python/IPython console and import pandas there.