Changing Python environment in Spyder

I need to use python 3.8 on Spyder 4.2.5 for a coursework at university. I have managed to downgrade Spyder (from anaconda, but the environment is python 3.9.18, to change it says to change the interpreter but I’m not sure how to do this.
I have tried using the anaconda prompt terminal and downloading the Python 3.8 package from anaconda.org, and followed this video. https://youtu.be/Ul79ihg41Rs?t=308

(win-64_python-3.8.10-h7840368_2_cpython) C:\Users\admin>pip install win-64_python-3.8.10-h7840368_2_cpython
ERROR: Could not find a version that satisfies the requirement win-64_python-3.8.10-h7840368_2_cpython (fromm versions: none)
ERROR: No matching distribution found for win-64_python-3.8.10-h7840368_2_cpython

Any help is greatly appreciated x

I can’t understand. The video is explicitly titled “Spyder says: don’t mix pip and conda”, and at the timestamp you give, the presenter suggests getting the package from conda-forge. But here you show an attempt to use Pip to install the package in an anaconda environment. That is clearly not what the video is telling you to do.

When you use pip install, the next thing on the command line should be the name of the package you are trying to install. You cannot install Python from Pip. The purpose of Pip is to set up third-party packages, within a Python installation that already exists. You already have one of them here. In your command prompt, where it says (win-64_python-3.8.10-h7840368_2_cpython), that is showing you the name of the currently active virtual environment - a folder that contains a copy of Python taken from some base install.

This doesn’t clearly describe a problem. When you say “the environment”, it isn’t clear which environment you mean.

Please start the explanation over - to be able to help, I would have to understand:

  1. What operating system are you using?

  2. Before you did anything, what versions of Python do you believe were on the system? Was Anaconda already there? Was Spyder already there? What versions?

  3. Step by step, exactly what have you done since then in order to install, upgrade or downgrade new versions of related software? For example, did you get a stand-alone installer for Spyder? What came first?

  4. When you say “to change it says to change the interpreter” - what do you mean by “it”? What advice did you read, specifically, and who provided it to you?

  5. What concrete problem do you hope to solve by downgrading Python? “The course says I should use this version” probably does not qualify - there are very few issues today where using Python 3.9 would cause a problem, but 3.8 would work. At most, for any ordinary situation, some error messages will look different (and the 3.9 ones will probably be more helpful).

  6. Are you trying to downgrade Python system-wide? Or are you only trying to change what Spyder uses?

Thank you for the quick reply.

  1. I am using Windows 11 Pro with 64-bit OS

  2. I use the Anaconda Navigator, as instructed by my university course. I had previously used Jupyter Notebook through the Anaconda Navigator. So I don’t know what version of python I have had/used. This is a screenshot from the pdf of the class introducing Spyder:

  3. I downgraded Spyder from 5.4.2 to 4.2.5 with the anaconda navigator, when I opened Spyder 4.2.5, it says: conda (Python 3.9.18) in the bottom right corner. Clicking it gives me the option to ‘Change the default environment in Preferences’. looking online for how to change the environment, I found: Frequently Asked Questions — Spyder 5 documentation

I followed the video from the timestamp and first tried:
``
conda create -n win-64_python-3.8.10-h7840368_2_cpython -c conda-forge python=3

conda activate win-64_python-3.8.10-h7840368_2_cpython
``
this was all fine. I encountered a problem with:
conda install -c conda-forge win-64_python-3.8.10-h7840368_2_cpython
I got the error message the presenter mentioned,
PackagesNotFoundError:

so I moved on to step 4 and used pip install win-64_python-3.8.10-h7840368_2_cpython. I first tried it in the same terminal and got the error mentioned in the first post, then I tried using the Windows Command Prompt (should I have use the PowerShell Terminal?) but the Command Prompt couldn’t recognise pip.

  1. Everything I have tried I have found online.

  2. My coursework brief says this in regard to the programming:

  • To avoid compatibility issues when marking the Python code, please use Spyder
    4.2.5 (Python 3.8). (You can download Spyder through Anaconda navigator – see
    the webpage: Free Download | Anaconda).
  1. I am only trying to change what Spyder uses. I have to program a simulation of a system Euler and Heun’s Method.

Apologies if it all seems a bit chaotic and hard to follow, I have been trying anything and everything I come across to see if anything helps.
Thanks again.

To clarify upfront, there are at least two different “environments” that matter here: Spyder’s runtime environment (i.e. the [Python] environment Spyder itself runs in), and your working environment, the Python environment your code runs in.

With our standalone installers, which we recommend, Spyder installs and updates its runtime environment for you, so you only need to worry about your working environment(s). If Spyder is installed via Conda (Anaconda, Miniconda, Miniforge, Mambaforge, Maxiconda, etc) you’ll generally use the pre-installed Spyder in the default base environment, or (recommended) a dedicated Spyder environment (so you can install and update Spyder from Conda-Forge without risking any interference from or with your other packages). See our installation guide for more details on that.

However you install it, Spyder uses its own runtime environment to give you a default working environment out of the box, but we generally recommend using your own environments for non-trivial projects. Recent Spyder 5 versions will automatically detect your installed Conda environments and allow you to select them (after installing a compatible version of spyder-kernels via the command Spyder will provide you), while Spyder 6 (currently in alpha) with our standalone installers will allow you to create and manage your own working environments from right inside of Spyder’s interface, no separate Conda necessary.

To create a new Python environment with the Python version and packages you want, follow the steps in this FAQ question (which I recently revised to be simpler and easier to understand, and also has a dedicated video tutorial), making sure to add python=3.8 (or, better, 3.11, or whatever version you want) at end of the command beginning conda create, e.g.:

conda create -n python-3.8-env -c conda-forge spyder-kernels python=3.8

Spyder 4.2.5 is nearly 3 years old and Spyder 4 is long-unsupported; the current release is Spyder 5.5.0, while the first stable release of Spyder 6 just around the corner. There have been many improvements in recent versions to the functionality for connecting and using Spyder with different environments, so you should always use the latest version.

Furthermore, the assertion is wrong—it doesn’t make any sense to downgrade Spyder just to get an earlier version of Python, since the version of Python used to run your code is independent of the version Spyder is running with (as explained in more detail above—the latest Spyder 5.5.0 can be used with the latest Python 3.12 all the way back to Python 2.7). The FAQ and video you’re following is devoted to explaining exactly that. In fact, the version of Spyder is mostly independent of the version of Python even Spyder itself is running under, especially with Anaconda.

Yup, the whole reason Juanita and I poured dozens of hours of our blood, sweat and tears into making that video is to try to stem the tide of users messing their environments by, you guessed it, mixing pip and conda. So please, don’t, unless you (or whomever is instructing you) knows exactly what you’re doing. (Funny enough, it got so burned into our brains that we still quote the “unmess your mess” line from that video, which I in fact did to her when we were talking not an hour or two before I saw this question, haha).

Furthermore, in addition to being the name of a Conda environment that you apparently created, that looks like the full build string of the python package filename.

This isn’t what you pass to conda install, and in general when switching Python versions its basically always better to create a fresh, clean Python environment with conda create and the version of Python you want (e.g. 3.8, though for new code there isn’t much reason to be using a much newer and faster version at this point, like 3.11) instead of trying to switch the version of an existing environment, as it will be much faster, much more likely to be successful and keep your existing environment intact. See above for the command and resources on how to do that.

I assume you just used it with the default base environment; AFAIK, Jupyter must usually be installed in the same environment you run your code in, whereas one copy of Spyder can work with any environment, even one that’s part of a whole different Python installation (so long as the spyder-kernels support package is installed in the environment, which is what allows use of Spyder’s advanced features).

Yes, because win-64_python-3.8.10-h7840368_2_cpython is not a package at all, it is the name you chose for your environment (that also happens to be a form of the file identifier for a specific Conda package containing an old version of Python 3.8).

While you can usually get a way with switching it later, it is much better if you specify the version of Python you want installed in the conda create step, i.e. python=3.8 instead of just python=3.

As @kknechtel mentions, this won’t work because:

  1. This is not a package name/spec at all
  2. The package it actually refers to is specific to Conda, and
  3. You cannot install Python itself with pip

Instead, either run conda install -c conda-forge python=3.8 with your existing environment activated, or (recommended, and illustrated in the Spyder FAQs and above) create a new environment specifying python=3.8 instead of just python=3.

On Windows, the default Command Prompt (and PowerShell) don’t have Conda activated by default, whereas the Anaconda Prompt does, as the Spyder FAQs and videos instruct you to use.

This FAQ question directly addresses how to change Spyder’s working environment (though you’ll probably want to first create a new environment with the desired Python version, as the above explanation and linked FAQ question explain how to do).

If you run into further trouble, I’m happy to further assist, provided you are using a supported Spyder 5 version. Thanks, and best of luck!

1 Like

Wow, lots of info here, thank you for providing so much detail.

I have since downloaded Spyder from it’s website, I am using Spyder 5.5.0.
Am I right in saying that this is Spyder running my code in Python 3.8.10? If so I will use it as it is to write my simulation and i will not need to make any more changes:

Screenshot 2023-12-27 163316

Thanks again, in regards to using an unsupported version of Spyder, I will email my lecturer to let them know about the problem with the coursework.

Thank you.

Glad to hear :+1: Although, you must have downloaded it from the releases page or the link installed guide, as due to a bug the download button was not actually being displayed, and I haven’t yet merged my PR fixing it :slight_smile:

Yup, this is correct. In your screenshot of the Spyder statusbar, the version of Spyder is shown to the left (as well as whether any updates are available), while the current default working environment name, type and its Python version are shown to the right. You can right-click on the latter (or the "Completions entry to its right, if shown) to open the preferences pane to select a different one. As mentioned, out of the box Spyder defaults to opening new consoles in its own runtime environment, which in this case is the internal environment created by the installer.

This will work fine for basic scripts and such so long as the set of packages installed by default (numpy, pandas, matplotlib, scipy, etc) is sufficient for your needs. However, do note that if you need to install your own packages, you’ll need to create your own environment with Conda (e.g. using Anaconda Navigator or the conda command line interface, as detailed in the aforementioned FAQ question), or use an existing one, since Spyder’s own environment cannot be modified externally to avoid breaking Spyder itself with your own packages, follow best practices and make it easy to recover from any mistakes.

In the forthcoming Spyder 6 release, we have a new pane that allows you to create environments and install packages right inside of Spyder’s UI using Spyder’s built-in Python installation, without needing to install Anaconda, use Navigator or conda, or manually switch between environments.

Thanks. They are welcome to contact me or the Spyder team if they have further questions or would like additional advice.

Best of luck!