spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.2k stars 1.59k forks source link

An error ocurred while starting the kernel for system-wide Python installations on Windows #20968

Open bero4sc opened 1 year ago

bero4sc commented 1 year ago

Hi, I am facing error with kernels with my custom Python on Win 11. My setup is as follows. I have installed stand along Spyder 5.4.3 on Windows 11 and Python 3.11 as standalone (stand alone means, I am not using Conda/Anaconda environment). Python 3.11 version is installed in "C:/Program Files/Python311" Spyder is installed in "C:\Program Files\Spyder"

Since Spyder comes with older version of Python which is Python 3.8.10, I changed this from Tools>Python interpreter: Select "Use the following Python interpreter".

After the Spyder is restarted, the following error pops up: An error ocurred while starting the kernel **The Python environment or installation whose interpreter is located at C:\Program Files\Python311\python.exe doesn't have the spyder‑kernels module or the right version of it installed (>= 2.4.0 and < 2.5.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.4 or pip install spyder-kernels==2.4.*

From Command Prompt, I installed the spyder kernels using the pip install spyder-kernels==2.4.3 as suggested on Spder-IDE website. But the errors persists. Can you please help me to resolve this issue? PS. I tried to go through the wiki page and the youtube videos you have suggested earlier in this thread. But I could not find the solution for this issue.

Originally posted by @bero4sc in https://github.com/spyder-ide/spyder/issues/17339#issuecomment-1565423966

dalthviz commented 1 year ago

Hi @bero4sc thank you for the feedback! Could you try to create a Python virtual env with venv and check if that helps? Seems to me that this could be related to Spyder being unable to find the place spyder-kernels was installed

Let us know if the info above helps!

bero4sc commented 1 year ago

Hi @dalthviz , thank you. It works now. May be this can be included in the installation guide on wiki. And secondly, will this be considered as an issue and solved in future? As a user, why I need to install a virtual environment?

Just an extra information for others: To create a virtual environment on Windows command prompt using venv: c:\ (path to the folder where python is installed) > python -m venv (path to your "myvenv" folder) Eg: C:\programfiles\python311>python -m venv c:\username\documents\myvenv A virtual environment folder is created for you. In the Spyder use the path to python.exe in this folder (under scripts) to use the custom python version. (c:\username\documents\myvenv\scripts\python.exe) After restarting the Spyder (file>restart), an error pops us with message .. " .... the location does not have the spyder-kernels.....". This can be solved by installing the spyder-kernels in the virtual environment created (folder myvenv). To do so..

  1. open command prompt and go the scripts folder in myvenv folder and enter command line "activate.bat"
  2. This activates the myvenv and install the spyder-kernels using the pip .... pip install spyder-kernels==(version number)
  3. Now restarting the Spyder (file>restart) will get your custom python version ready on kernel to use.
dalthviz commented 1 year ago

Awesome @bero4sc ! Thank you for letting us know that creating the env helped! My guess regarding the need to create a env is that in a standalone Python installation the directory where the packages are installed is not inside the same place the python executable and Spyder doesn't have the logic to detect where this global packages are installed. Using a env ensures that Spyder is able to find the packages associated with an interpreter. Not sure if this is the case for sure so just in case, what do you think about this @ccordoba12 ?

Regarding the installation guide, maybe yes, adding a section for a setup like the one you have (a setup using standalone installations for Spyder and 'vanilla' Python without the need of other distributions that come with Python or that enable installing Python)

ccordoba12 commented 1 year ago

My guess regarding the need to create a env is that in a standalone Python installation the directory where the packages are installed is not inside the same place the python executable and Spyder doesn't have the logic to detect where this global packages are installed.

Yep, that's correct. If you installed Python for all users (i.e. in Program Files) and then want to install certain packages as a specific user, then their packages will be installed in their APPDATA directory because they don't have permissions to write to Program Files.

Using a env ensures that Spyder is able to find the packages associated with an interpreter. Not sure if this is the case for sure so just in case, what do you think about this @ccordoba12 ?

I think your interpretation of the situation is correct. But Python should add the user's APPDATA directory by default to sys.path to search for packages installed there. So we need to investigate why that's not happening in our kernel and then try to fix it.

Lorchi74 commented 2 months ago

Hello, I would like to contribute my 2c: I faced the same issue with Spyder IDE 5.5.3 and Python 3.12, both installed individually without Anaconda. I can cofirm: Creating a venv outside Spyder, installing the kernels and pointing to the contained runtime solved the problem (or worked around it).

Here are some suggestions:

  1. I don't know why Spyder needs to know the kernel installation directory, but assuming there are good reasons for it: To avoid assuming or duplicating the logic of the installation mechanisms, the location of the required modules could be probed by starting Python, have it import the module(s) and return or put out module.__path__.
  2. For convience only, but esp. for users new to Python, Spyder could offer a wizard that guides the user (during installation or selection of another runtime executable) through the process of:
    • choosing whether to work in the default environment or in a venv when using Spyder,
    • optionally installing virtualenv, and creating one, and
    • installing the kernel modules.

Best regards

Prasannakoduru-123456 commented 1 month ago

Hi, I am facing error with kernels with my custom Python on Win 11. My setup is as follows. I have installed stand along Spyder 5.5 on Windows 11 and Python 3.12.8 as standalone (stand alone means, I am not using Conda/Anaconda environment).for 3rd party application , I have created virtual environment, afterwards I activated my venv all these things done in OFFLine mode only, After the Spyder is restarted, the following error pops up: An error ocurred while starting the kernel **The Python environment or installation whose interpreter is located at C:\Program Files\Python311\python.exe doesn't have the spyder‑kernels module or the right version of it installed (>= 2.5.2 and < 2.5.6). 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.2 or pip install spyder-kernels==2.5.6*

I downloaded spyder kernel 5.5.2 from online and installed that one in offline mode as suggested on Spder-IDE website From Command Prompt, I installed the spyder kernels using the pip install spyder-kernels==2.5.2.

But the errors persists. Can you please help me to resolve this below issue ?

(NOTE:I AM DOING IN OFFLINE MODE ONLY)

(MYENV)C:\PROGRAMFILES\ESI GROUP\VAONE\2023\BIN\MYENV\SCRIPTS>PIP INSTALL SPYDER_KERNALS-2.5.2-PY2-PY3 WARNING:RETRYING(RETRY(TOTAL=4,CONNECT=NONE,READ=NONE,REDIRECT=NONE,STATUS=NONE))AFTER CONNECTION BROKEN BY 'NEWCONNECTIONERROR('<PIP_VENDOR.URLLIB3.CONNECTION.HTTPSCONNECTION OBJECT AT 0X0000027159DC8C40>:FAILED TO ESTABLISH A NEW CONNECTION:[ERRNO 11001]GETADDRINFO FAILED '):/SIMPLE/SPYDER-KERNALS-2.-5-2-PY2-PY3/ ERROR:COULD NOT FIND A VERSION THAT SATSIFIES THE REQUIREMENT SPYDER_KERNALS-2.5.2-PY2.PY3(FROM VERSIONS:NONE) ERROR:NO MATCHONG DISTRIBUTION FOUND FOR SPYDER=2.5.2-PY2.PY3

Thanks in advance Prasanna.

ccordoba12 commented 1 month ago

@Prasannakoduru-123456, I think the command you need to run to install spyder-kernels is

pip install spyder_kernels-2.5.2-py2.py3-none-any.whl

Let us know if it works for you.

Prasannakoduru-123456 commented 1 month ago

Hi thankyou for your reply tried with that one also but not working

On Mon, Jul 22, 2024, 10:16 PM Carlos Cordoba @.***> wrote:

@Prasannakoduru-123456 https://github.com/Prasannakoduru-123456, I think the command you need to run to install spyder-kernels is

pip install spyder_kernels-2.5.2-py2.py3-none-any.whl

Let us know if it works for you.

— Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/20968#issuecomment-2243392519, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEVMWGJAIGFIVD225YCA44LZNUZONAVCNFSM6AAAAABKEBMAROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBTGM4TENJRHE . You are receiving this because you were mentioned.Message ID: @.***>

ccordoba12 commented 1 month ago

You need to download that file from here and place it in the directory where you're going to run the command I posted above. But you'll need to also download all the 40+ packages that spyder-kernels and its dependencies depend on for that to work offline.

Prasannakoduru-123456 commented 1 month ago

Earlier I followed that one only i placed that file in my directory where i need to run my CMD . If possible can you please provide all 40+packages downloadable files and installation procedure too Thank You

On Tue, 23 Jul 2024 at 20:41, Carlos Cordoba @.***> wrote:

You need to download that file from here https://pypi.org/project/spyder-kernels/#files and place it in the directory where you're going to run the command I posted above. But you'll need to also download all the 40+ packages that spyder-kernels and its dependencies depend on for that to work offline.

— Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/20968#issuecomment-2245521022, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEVMWGMILN3QDB3U54ACFYLZNZXDBAVCNFSM6AAAAABKEBMAROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBVGUZDCMBSGI . You are receiving this because you were mentioned.Message ID: @.***>

bero4sc commented 1 month ago

@Prasannakoduru-123456 After going through your ealier description where you explained the scenario of your installation, I think there might be 2 issues with your installation.

  1. You have created a virtual environment, but did you include the path to the virtual envivronment?
  2. After that, did you install Spyder-kernels in your virtual environment, after activating the virtual environment? Then it should work without any further hurdles. If you did these already, please ignore my comments.