Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Python Spyder can't see spyder-kernels in virtual environment #21864

Open
saraahmed88 opened this issue Mar 7, 2024 · 9 comments
Open

Comments

@saraahmed88
Copy link

Problem description:

1- I am using Python 3.6 in the default environment (C:\Users\sedm6111\Anaconda3\envs\windturbine) and have created a new environment for Python 3.11 as I wanted to use it for certain libraries while maintaining my old Python version.
I have followed exactly the steps in (https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#the-modular-approach) but it didn't work, and I have also tried the solution in (https://stackoverflow.com/questions/28190500/virtualenv-ipython-in-spyder-not-working) and it didnt work.

The Python environment or installation whose interpreter is located at
C:\Users\sedm6111\Anaconda3\envs\mypy11env\python.exe

I get the below path when I run:
from jupyter_core import paths
paths.jupyter_runtime_dir()

C:\Users\sedm6111\AppData\Roaming\jupyter\runtime

I have tried a lot of lines to instal kernalls but non of them works:
pip install spyder‑kernels==1.9
pip install spyder‑kernels==1.9.*
pip install spyder‑kernels==2.0.*

The python -m spyder_kernels.console
0.01s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
NOTE: When using the ipython kernel entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see ipython/ipython#2049

To connect another client to this kernel, use:
--existing kernel-51924.json

The error I get:

Your Python environment or installation doesn't have the spyder‑kernels module or the right version of it installed (>= 1.8.0 and < 2.0.0). Without this module is not possible for Spyder to create a console for you.
You can install it by running in a system terminal:
conda install spyder‑kernels
or
pip install spyder‑kernels

(mypy11env) C:\Users\sedm6111>pip list
Package Version


asttokens 2.4.1
cloudpickle 3.0.0
colorama 0.4.6
comm 0.2.1
debugpy 1.8.1
decorator 5.1.1
executing 2.0.1
ipykernel 6.29.3
ipython 8.22.2
jedi 0.19.1
jupyter_client 8.6.0
jupyter_core 5.7.1
matplotlib-inline 0.1.6
nest-asyncio 1.6.0
packaging 23.2
parso 0.8.3
pip 24.0
platformdirs 4.2.0
prompt-toolkit 3.0.43
psutil 5.9.8
pure-eval 0.2.2
Pygments 2.17.2
python-dateutil 2.9.0.post0
pywin32 306
pyzmq 25.1.2
setuptools 69.1.1
six 1.16.0
spyder-kernels 2.0.0
stack-data 0.6.3
tornado 6.4
traitlets 5.14.1
wcwidth 0.2.13
wheel 0.42.0

@dalthviz
Copy link
Member

dalthviz commented Mar 7, 2024

Hi @saraahmed88 what version of Spyder are you using? Seems like you ended up in your mypy11env env with spyder-kernels 2.0.0 which is incompatible with the Spyder version you are running since the error message says you need spyder-kernels>=1.8.0,<2.0.0. Also, what happens if you try changing the spyder-kernels version in your mypy11env with something like pip install spyder-kernels==1.8.*? Let us know!

@saraahmed88
Copy link
Author

Hi @dalthviz, I am using spyder 4.0.1, py37_0
I have tried (pip install spyder-kernels==1.8.*) When I restarted my kernel, then spyder portal I got the same error (kernels>=1.8.0,<2.0.0)
Thank you

@dalthviz
Copy link
Member

dalthviz commented Mar 8, 2024

Thank you for the new info @saraahmed88 I would say that such an old version of Spyder could be having troubles to properly detect the custom interpreter then 🤔 Also, just to see if I'm fully understanding your current setup: you are launching Spyder 4.0.1 from an env with Python 3.7 (the Spyder version you mentioned has the py37 build string that identifies as build for Python 3.7) but also you have an env (windturbine) with Python 3.6 which you were using before as the interpreter and then you wanted to use another custom interpreter from a new env (mypy11env) with Python 3.11, right?

Just in case, as a workaround to try, could it be possible for you to start manually the kernel from your mypy11env with python -m spyder_kernels.console and then use the Connect to an existing kernel dialog (https://docs.spyder-ide.org/current/panes/ipythonconsole.html#using-external-kernels)?

Any other info to further understand what could be happening is greatly appreciated. Let us know!

@saraahmed88
Copy link
Author

Thank you so much @dalthviz for your answer. I am launching Spyder 4.0.1 with the default Python 3.7 that comes with it. I am sorry, the env (windturbine) is not used. I set up a custom interpreter from a new env (mypy11env) with Python 3.11.

I have used (python -m spyder_kernels.console) in the Anaconda prompt, and it gives:
(mypy11env) C:\Users\sedm6111>python -m spyder_kernels.console
0.05s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.01s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
NOTE: When using the ipython kernel entry point, Ctrl-C will not work.
To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.
To read more about this, see ipython/ipython#2049
To connect another client to this kernel, use:
--existing kernel-6068.json

And then I connected to the kernal 6068 and it works, I didnt know that to make it work, I needed to leave the anaconda prompt with the (python -m spyder_kernels.console) running while connecting to the kernal. its working now.

Many thanks @dalthviz

@Isaac000
Copy link

Isaac000 commented Apr 26, 2024

I believe I have the same issue. Spyder 5.5.4, but this showed up in earlier 5.x versions as well. Windows 10 with Python 3.10.x (but same with 3.11, 3.12)
I am sure pip install is run with the same Python 3.10 that I want to use.

The Python environment or installation whose interpreter is located at
    C:\Program Files\Python310\python.exe
doesn't have the spyder‑kernels module or the right version of it installed (>= 2.5.0 and < 2.6.0). Without this module is not possible for Spyder to create a console for you.

You can install it by activating your environment first (if necessary) and then running in a system terminal:
    conda install spyder-kernels=2.5
or
    pip install spyder-kernels==2.5.*

I have already done the pip install and verified the packages are installed and correct version (says version 2.5.1) and it still gets the same error message.
I have tried to "manually" start Spyder from the same command-line session as the pip install with to use 3.10 kernel
"C:\Program Files\Python310\pythonw.exe" "C:\Program Files\Spyder\Spyder.launch.pyw"
but the IDE won't start up. Blank, no splash screen or anything. It only starts if I used the pythonw.exe version that comes with Spyder, but then of course, it complains my Python version doesn't have the spyder-kernels installed

@ccordoba12
Copy link
Member

ccordoba12 commented May 2, 2024

@Isaac000, did you install spyder-kernels as your user? Or in a console with admin privileges?

@Isaac000
Copy link

Isaac000 commented May 2, 2024

I have tried both. pip install with both normal user and admin and also running Spyder as normal user and admin. All combinations.
Every case still gives the same error.

@ccordoba12
Copy link
Member

It shouldn't give an error if you installed Spyder-kernels as admin. But to be sure, you need to uninstall it first, be sure that it's really not present in your system, and then install it as admin.

@Isaac000
Copy link

Isaac000 commented May 2, 2024

Behaviour seems inconsistent. I have tried this many, many times with various Python versions (admin & normal user) and it always complains that the spyder kernels are missing. I had one last go at it:

  1. I uninstalled the spyder kernels from my alternate Python kernel and tried again (as Admin). This time spyder seemed to be ok with it and no complaints. Hurray!
  2. I immediately quit Spyder, re-start and point it to a 3rd alternate Python version.
  3. Re-start Spyder and it again complains that the spyder kernels are not installed, so I quit it
  4. Now I go back (as admin) to console and pip install the spyder kernels in that 3rd Python version, but it tells me that everything is already installed so it didn't do anything (nope, not a single thing got installed, it skipped everything)
  5. Re-start Spyder again and it doesn't complain this time.

Weird...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants