Add python2.7 in jupyter lab

Hi,
I want to add python2.7 kernel in Jupyter lab. How can i do it?

    ~  python --version                                                 ✔ 
Python 3.12.3
    ~  python2.7 -m pip install ipykernel                               ✔ 
zsh: command not found: python2.7
    ~                   

What is it that you actually want to do?
What is it that you want achieve in the end?

I have python 3.12.3 as default in my PC but i want to use python 2.7 . How can i use python 2.7 in my PC?

not sure - I’m no expert in this
I have heard of virtual environments
pyenv
where you can use other versions than the system python

There are threads about this here - and probably many wikis/guides

These links should be useful:

Cheers.

2 Likes

I tried using pyenv but there is no change in default version of python.

    ~  pyenv install 2.7                                                ✔ 
pyenv: /home/raman/.pyenv/versions/2.7.18 already exists
continue with installation? (y/N) y
Downloading Python-2.7.18.tar.xz...
-> https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz
Installing Python-2.7.18...
patching file configure
patching file configure.ac
patching file setup.py
patching file Mac/Tools/pythonw.c
patching file setup.py
patching file Doc/library/ctypes.rst
patching file Lib/test/test_str.py
patching file Lib/test/test_unicode.py
patching file Modules/_ctypes/_ctypes.c
patching file Modules/_ctypes/callproc.c
patching file Modules/_ctypes/ctypes.h
patching file Modules/_ctypes/callproc.c
patching file setup.py
patching file Mac/Modules/qt/setup.py
patching file setup.py
Installed Python-2.7.18 to /home/raman/.pyenv/versions/2.7.18
    ~  pyenv global 2.7.18                                   ✔  4m 54s  
    ~  python                                                           ✔ 
Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

the default version won’t change - but you can use the other version in the virtual environment

is the question …

can i use that python 2.7.18 version in jupyter lab? I don’t see it in Jupyter lab.

someone else may be able to answer that - I do not know what jupyter lab is

You likely need to spend more than five minutes learning how to use pyenv; in particular, how to use a specific version you have installed.

All the answers are available in the documentation and various online resources; and specifically, in the links I’ve already given.

Cheers.

This is the documentation on how to install additional kernels.

https://ipython.readthedocs.io/en/latest/install/kernel_install.html

It looks okay to me.

(Are you really sure that the outdated 2.7 version is good for you?)

I couldn’t solve it

python -m pip --2.7.18                                           ✔ 

Usage:   
  /usr/bin/python -m pip <command> [options]

no such option: --2.7.18
    ~  python -m pip --version                                        2 ✘ 
pip 24.0 from /usr/lib/python3.12/site-packages/pip (python 3.12)
    ~  python -m pip install ipykernel                                  ✔ 
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
    python-xyz', where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Arch-packaged Python package,
    create a virtual environment using 'python -m venv path/to/venv'.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-Arch packaged Python application,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. Make sure you have python-pipx
    installed via pacman.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
    ~  python2 -m pip install ipykernel                               1 ✘ 
python2 -m ipykernel install --user

zsh: correct 'python2' to 'python3' [nyae]? n
zsh: correct 'python2' to 'python3' [nyae]? n
zsh: command not found: python2
zsh: command not found: python2
    ~  python2 -m pip --version                                     127 ✘ 
zsh: correct 'python2' to 'python3' [nyae]? n
zsh: command not found: python2
    ~                                                               127 ✘ 
    ~                                                               127 ✘ 


Please help me as i have to use python 2.7 for running old code.

    ~  sudo pacman -S python2                                         1 ✘ 
[sudo] password for raman: 
error: target not found: python2
warning: 'python2' is a file, did you mean -U/--upgrade instead of -S/--sync?
    ~  python2 -m pip --version                                1 ✘  3s  
zsh: command not found: python2
    ~                            

I have tried all those as you can see my above posts.

Sorry, we can’t do this for you. The link with the :eyes: gives full instructions for managing multiple python versions using pyenv - you just need to read and understand it - or, search for more information if you need to. As far as Jupyter is concerned, that’s not a Manjaro related issue to be solved.

While I wish you well with your learning, I’m not here to teach.

Good luck.

I tried using it many times but it is not working. See there is no change in python version.

    ~  pyenv install 2.7.18                                             ✔ 
pyenv: /home/raman/.pyenv/versions/2.7.18 already exists
continue with installation? (y/N) n
    ~  pyenv global 2.7.18                                     1 ✘  5s  
    ~  python                                                           ✔ 
Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 


pyenv install 2.7.18                                             ✔ 
pyenv: /home/raman/.pyenv/versions/2.7.18 already exists

It seems to be installed. Why are you trying to install it again?

See: Installing and Switching Between Python Versions, Setting a Local Python Version, Installation Problems, Issues with Switching Python Versions, etc.

Again, good luck.

1 Like

Yes , it is installed but it is not available in jupyter. How can i switch to that version in Jupyter?

    ~  eval "$(pyenv init -)"                               ✔  20m 30s  
    ~  pyenv global 2.7.18                                              ✔ 
    ~  python                                                           ✔ 
Python 2.7.18 (default, May 25 2024, 11:26:23) 
[GCC 13.2.1 20240417] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

but when i reopen terminal and type python it shows again python 3.12.3 version:

    ~  python                                                           ✔ 
Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

It is a virtual environment. Either enter it with some command or with environment variable per app. I do not think it is possible to change the version globally in manjaro - it will break the system after all, so be thankful it did not work.

So you have to figure out hot to start your app in the container, maybe install it there, or start it with a variable prefix, or change its startup script…but that can be better said by someone actually knowing that piece of software. I just gave you 3 ideas.

See this as how to use pyenv

https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell