Kali linux python version
In December of 2019 we released a blog post talking about how we will deal with Python 2’s End-of-Life. Since then there has been quite a lot of tools that users use that have not been ported to Python 3, causing issues when they try to use them. This page will cover a way of using the depreciated version in a safe way.
pyenv
Python 2 is no longer being maintained in the Debian repositories. This means that we must find a way to work around this issue. pyenv solves this problem by allowing us to install multiple versions of Python that do not conflict with each other. Currently it is not in the Debian or Kali repository, so we will need to install it from source. Thankfully, there is a handy installation script that the authors have released. Let’s go through the installation and setup together:
[email protected]:~$ sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git [. ] [email protected]:~$
We will next be quickly running the bash install script. If ZSH is the default shell we will have to edit the .zshrc file after this:
[email protected]:~$ curl https://pyenv.run | bash [. ] [email protected]:~$
If we are using ZSH then we will now add the proper lines to our .zshrc :
[email protected]:~$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc [email protected]:~$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc [email protected]:~$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.zshrc
Lets continue with the setup
[email protected]:~$ exec $SHELL [email protected]:~$ [email protected]:~$ pyenv pyenv 1.2.20 Usage: pyenv [] Some useful pyenv commands are: activate Activate virtual environment commands List all available pyenv commands deactivate Deactivate virtual environment doctor Verify pyenv installation and development tools to build pythons. exec Run an executable with the selected Python version global Set or show the global Python version(s) help Display help for a command hooks List hook scripts for a given pyenv command init Configure the shell environment for pyenv install Install a Python version using python-build local Set or show the local application-specific Python version(s) prefix Display prefix for a Python version rehash Rehash pyenv shims (run this after installing executables) root Display the root directory where versions and shims are kept shell Set or show the shell-specific Python version shims List existing pyenv shims uninstall Uninstall a specific Python version --version Display the version of pyenv version Show the current Python version(s) and its origin version-file Detect the file that sets the current pyenv version version-name Show the current Python version version-origin Explain how the current Python version is set versions List all Python versions available to pyenv virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin virtualenv-delete Uninstall a specific Python virtualenv virtualenv-init Configure the shell environment for pyenv-virtualenv virtualenv-prefix Display real_prefix for a Python virtualenv version virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'. whence List all Python versions that contain the given executable which Display the full path to an executable See `pyenv help ' for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme [email protected]:~$
We can now install Python 2 and set it as our default Python version:
[email protected]:~$ pyenv install 2.7.18 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. Installed Python-2.7.18 to /home/kali/.pyenv/versions/2.7.18 [email protected]:~$ [email protected]:~$ pyenv global 2.7.18 [email protected]:~$ [email protected]:~$ pyenv versions system * 2.7.18 (set by /home/kali/.pyenv/version) [email protected]:~$ [email protected]:~$ python Python 2.7.18 (default, Apr 20 2020, 20:30:41) [GCC 9.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [email protected]:~$
We can now install dependencies as needed for whatever tools we are using. When we want to swap back to Python 3, we just need to set the global to be system.
One thing to keep in mind is to stick with installing the dependencies via pip . apt will not be very kind if you are trying to install Python 2 dependencies through it and through pip, so just stick with pip in this case.
Updated on: 2023-Mar-06
Author: gamb1t
Packages and Binaries:
Starting with the Debian 11 (bullseye) and Ubuntu 20.04 LTS (focal) releases, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python-config at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python-config.
This is a convenience package which ships a symlink to point /usr/bin/python-config script at the current default python3. It may improve compatibility with other modern systems, whilst breaking some obsolete or 3rd-party software.
No packages may declare dependencies on this package.
Installed size: 13 KB
How to install: sudo apt install python-dev-is-python3
pdb
[email protected]:~# pdb -h usage: pdb.py [-c command] . [-m module | pyfile] [arg] . Debug the Python program given by pyfile. Alternatively, an executable module or package to debug can be specified using the -m switch. Initial commands are read from .pdbrc files in your home directory and in the current directory, if they exist. Commands supplied with -c are executed after commands from .pdbrc files. To let the script run until an exception occurs, use "-c continue". To let the script run up to a given line X in the debugged file, use "-c 'until X'".
python-config
Output build options for python C/C++ extensions or embedding
[email protected]:~# python-config --help Usage: /usr/bin/python-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed
python-is-python3
Starting with the Debian 11 (bullseye) and Ubuntu 20.04 LTS (focal) releases, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all. Some third-party code is now predominantly python3 based, yet may use /usr/bin/python.
This is a convenience package which ships a symlink to point the /usr/bin/python interpreter at the current default python3. It may improve compatibility with other modern systems, whilst breaking some obsolete or 3rd-party software.
No packages may declare dependencies on this package.
Installed size: 15 KB
How to install: sudo apt install python-is-python3
pydoc
The Python documentation tool
[email protected]:~# pydoc -h pydoc - the Python documentation tool pydoc . Show text documentation on something. may be the name of a Python keyword, topic, function, module, or package, or a dotted reference to a class or function within a module or module in a package. If contains a '/', it is used as the path to a Python source file to document. If name is 'keywords', 'topics', or 'modules', a listing of these things is displayed. pydoc -k Search for a keyword in the synopsis lines of all available modules. pydoc -n Start an HTTP server with the given hostname (default: localhost). pydoc -p Start an HTTP server on the given port on the local machine. Port number 0 can be used to get an arbitrary unused port. pydoc -b Start an HTTP server on an arbitrary unused port and open a web browser to interactively browse documentation. This option can be used in combination with -n and/or -p. pydoc -w . Write out the HTML documentation for a module to a file in the current directory. If contains a '/', it is treated as a filename; if it names a directory, documentation is written for all the contents.
python
An interpreted, interactive, object-oriented programming language
[email protected]:~# python -h usage: python [option] . [-c cmd | -m mod | file | -] [arg] . Options (and corresponding environment variables): -b : issue warnings about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str. (-bb: issue errors) -B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x -c cmd : program passed in as string (terminates option list) -d : turn on parser debugging output (for experts only, only works on debug builds); also PYTHONDEBUG=x -E : ignore PYTHON* environment variables (such as PYTHONPATH) -h : print this help message and exit (also -? or --help) -i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x -I : isolate Python from the user's environment (implies -E and -s) -m mod : run library module as a script (terminates option list) -O : remove assert and __debug__-dependent statements; add .opt-1 before .pyc extension; also PYTHONOPTIMIZE=x -OO : do -O changes and also discard docstrings; add .opt-2 before .pyc extension -P : don't prepend a potentially unsafe path to sys.path -q : don't print version and copyright messages on interactive startup -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE -S : don't imply 'import site' on initialization -u : force the stdout and stderr streams to be unbuffered; this option has no effect on stdin; also PYTHONUNBUFFERED=x -v : verbose (trace import statements); also PYTHONVERBOSE=x can be supplied multiple times to increase verbosity -V : print the Python version number and exit (also --version) when given twice, print more information about the build -W arg : warning control; arg is action:message:category:module:lineno also PYTHONWARNINGS=arg -x : skip first line of source, allowing use of non-Unix forms of #!cmd -X opt : set implementation-specific option --check-hash-based-pycs always|default|never: control how Python invalidates hash-based .pyc files --help-env : print help about Python environment variables and exit --help-xoptions : print help about implementation-specific -X options and exit --help-all : print complete help information and exit Arguments: file : program read from script file - : program read from stdin (default; interactive mode if a tty) arg . arguments passed to program in sys.argv[1:]