-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Working with packages and environments in Spyder
While relatively straightforward once you're familiar with it, the interaction between Spyder and other packages and environments can sometimes be confusing for first-time users. Spyder 4 will make this process much easier with integrated, interactive GUI package and environment management, but in the meantime—particularly with the changes in released Spyder 3.3.0—we'd like to clarify how that relationship works.
Spyder is a Python package just like any other you may be used to, and so by default you can import
within Spyder any package you could from a regular Python or IPython terminal launched in the same environment as Spyder itself is installed and launched in:
- If Spyder is installed with Anaconda (as we recommend) and launched via a shortcut, from Anaconda Navigator or Anaconda Prompt without modifying anything, this will be the default
base
Anaconda environment. - If Spyder is installed via
pip
(experts only) and not into avirtualenv
/venv
, this will usually be whatever Python installationpip
itself belongs to. - If you use a system package manager (
apt-get
,dnf
,port
, etc) to install Spyder, this will typically be your system Python and its library of packages - If you installed Spyder into a specific environment (
conda-env
orvenv
), or it came with a preconfigured one (like those for Keras or TensorFlow) and launched it from there, it will only have access to packages from that environment
Therefore, if you'd like to use a package with an existing Spyder install (e.g. import
ing it into your scripts, packages or a Spyder IPython console), the simplest way to do so is to simply install the package into the same environment in which you installed Spyder, typically by the same means you installed the IDE (conda
, pip
, package manager, etc).
However, for more complex workflows involving environments or even totally separate Python installs, you have several other options.
If you have an existing preconfigured setup (such as for Keras or TensorFlow), are managing multiple environments (such as for development or testing packages), or even would like to work within a totally separate Python installation as that in which Spyder is installed (such as a system-installed Spyder with a separate Anaconda install, or vice-versa), you have two main options:
- First, you can simply install
spyder
into environment from which you'd like to use the packages in, and run it from there. This works with all Spyder versions, and should require no extra configuration once Spyder is install; however, it can result in multiple Spyder installs to manage and isn't as flexible or configurable as the alternative. - Starting with Spyder 3.3.0 (and Spyder 4), you can now just install the modular
spyder-kernels
package into a Python environment (conda-env
,venv
, system Python, or even an independent install) in which you wish to work, and then simply change thePreferences > Python interpreter
path in any running Spyder instance to point to the Python executable of that environment. This takes a small amount of preparation and configuration, but is much "lighter" and quicker than a full Spyder install into that environment, avoids dependency conflicts, and opens up new workflow possibilities.
Connect with Spyder through our social media channels and stay up to date with current developments!