Why this issue is coming in kali linux?

The message “Externally-managed-environment” is not a Python error; rather, it informs you that the Python environment you are attempting to use has been externally managed, which means that it was created or modified by a tool other than the Python interpreter itself.

Whether you are utilising a virtual environment or a container that was built using a programme like Docker or Kubernetes, this may occur. Under these circumstances, the tool is in charge of managing the environment’s configuration, and attempting to change it manually might result in problems.

If you are attempting to run a Python script and seeing this warning, it could be because you are attempting to make changes to the environment that are not permitted in an environment that is maintained externally, such as installing a package or changing a system variable. Use the tools offered by the environment management system you are using to make any necessary changes to the environment setup in order to prevent this problem.

How to fix this issue?

To fix this problem, you have to run some commands in your machine which are given below:

Command 1:
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

With this command, you may create and install a variety of software packages, including Python, on a Linux system. These packages and libraries are installed.

Command 2:
sudo curl https://pyenv.run/ | bash

This command downloads and executes the pyenv script. Run from https://pyenv.run/ to set up the pyenv utility on your computer.

A well-liked utility for controlling various Python versions on a single system is called pyenv. You may install several Python versions, switch between them quickly, and build virtual environments with certain Python versions using pyenv.

Command 3:
sudo echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc

The PYENV ROOT environment variable is set to the location "$HOME/.pyenv" by the addition of a line to the user’s home directory’s .zshrc file by use of this command.

To indicate the location of its installation directory, the pyenv utility uses the environment variable PYENV ROOT. The default installation location for the pyenv utility is /.pyenv, therefore by setting PYENV ROOT to $HOME/.pyenv, the tool will be installed there.

Keep in mind that this command only works with the zsh shell. You may need to adjust the command if you’re using a different shell (for example, by replacing .zshrc with .bashrc if you are using the Bash shell).

Command 4:
sudo echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc

This command adds a line to the user’s home directory’s .zshrc file that adds the "$PYENV ROOT/bin" directory to the start of the PATH environment variable.

When you run a command, the shell looks in the folders listed by the PATH environment variable. The shell will look for pyenv commands in this directory first before looking in the other directories in the PATH if the "$PYENV ROOT/bin” directory is added to the PATH’s beginning.

Keep in mind that this command only works with the zsh shell. You may need to adjust the command if you’re using a different shell (for example, by replacing .zshrc with .bashrc if you are using the Bash shell).

Command 5:
sudo echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.zshrc

This command adds a block of code that initialises pyenv and adds its shims directory to the start of the PATH environment variable to the user’s home directory's .zshrc file.

To determine whether the pyenv command is accessible, the code block utilises the command command. The result of pyenv init —path, which creates the pyenv environment and adds its shims directory to the start of the PATH, is run using the eval command if pyenv is present.

The if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init —path)"nfi is output to the console using the echo command. The output is then appended to the end of the .zshrc file in the user’s home directory using the >> operator.

Keep in mind that this command only works with the zsh shell. You may need to adjust the command if you’re using a different shell (for example, by replacing .zshrc with .bashrc if you are using the Bash shell).

Command 6:
exec $SHELL

The user’s default shell is launched by this command in a new instance.

The $SHELL variable is used to give the path to the user’s default shell, and the exec command is used to replace the current shell process with a new shell process.

Use this command to prevent the need to log out and back in before any modifications to the .zshrc (or equivalent) file take effect.

Command 7:
pyenv install 3.11.2

Using the pyenv tool, this command installs a specified version of Python, in this case version 3.11.2.

Command 8:
pyenv global 3.11.2

Using the pyenv tool, this command changes the system’s default installation of Python to the given version, in this instance version 3.11.2.

When you use this command, pyenv will modify the system’s environment variables to make sure that any Python programmes or scripts automatically utilise the given version of Python.

To switch between multiple Python versions installed on your system and to make sure the right version is used by default, use the pyenv global command.

Command 9:
pyenv versions

Using pyenv, this programme lists every version of Python that has been installed on the system.

Pyenv will go through all versions of Python that are currently installed and display their version numbers and installation locations when you issue this command.

This command might be helpful for determining which Python versions are currently on the system and for confirming that a particular version of Python has been appropriately installed.

Thanks.

That’s all! Thank you for getting this far. I hope you find this article useful. If you did find this article valuable.

Toss us a follow for more amazing articles on Linux, Networking etc

And be sure to share with other Linux folks who you think it might be useful to them.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here