Hướng dẫn remove python from usr/bin

DISCLAIMER: I've since learned a lot, and would recommend setting environment variables for a shell or shell session rather than use this answer. For example, if you manually relink the system's Python2 interpreter to a Python3 interpreter, you may wreak havoc on your system. Please use this answer with caution.

Just reset the symlink.

First, find out which python:

$ which python

In my case, I get:

/usr/local/bin/python

Then find where the symlink points to

$ file /usr/local/bin/python /usr/local/bin/python: symbolic link to `/usr/bin/python'

Then just repoint the symlink back to the default (in this case, I use the default: /usr/bin/python).

No uninstalls necessary.

Update

I've since found a lot of better ways to enact this exact same behavior, without having effects on the entire system.

Say I have an undesired python install in /usr/bin, and a desired python install in /opt/bin. Let's say for the point of comparison that the /usr/bin is Python 3.5, and the /opt/bin is Python 2.7. This would create immediate consequences for using the wrong Python interpreter, rather than subtle errors down the line.

Application Defaults

If you would like to (on Linux systems) change which interpeter runs Python scripts, you can change this either via a GUI, or via xdg-mime (a walkthrough can be found here). For macOS or Windows, this can be done easily through a GUI.

Interactive Shell

If you would like to change the default Python for a specific shell, I can see two good ways of doing this. One would be to change the default search PATH to set /opt/bin before usr/bin for a specific situation, however, if you have numerous alternative installs to system packages, this might pose issues too. Another would be to set an alias for Python to the version you want to use. This is the preferred solution, as it only changes the interpreter and is merely a shortcut to reference an existing command.

For example, to set the alias I could use:

alias python="/opt/bin/python"

And to change the default path, I could use:

export PATH=/opt/bin:$PATH

Adding these lines to ~/.bashrc or ~/.bash_aliases (the latter is Ubuntu-only by default) will make these shortcuts be the default on any interactive shell you start. Combining application defaults and interactive shell scripting allows you to have tight control over which interpreter runs your code, but does not require interfering with potentially crucial system files.

Xin chào các bạn. Mọi người khỏe không? Tôi hy vọng tất cả các bạn tốt. Hôm nay chúng ta sẽ tìm hiểu về Cách gỡ cài đặt hoàn toàn Python Từ Windows mà không mất thời gian, hãy tìm hiểu cách chúng tôi có thể gỡ cài đặt hoàn toàn python khỏi windows.

Nội dung chính

  • Phương pháp 1: Sử dụng bảng điều khiển
  • Phương pháp 2: Thủ công
  • Phương pháp 3: Sử dụng CMD
  • Sự kết luận
  • How to Uninstall Python From Windows, Mac, And Linux
  • How To Uninstall Python From Windows
  • Step #1: Navigate to the Control Panel
  • Step #2: Navigate to the Uninstall Menu
  • Step #3: Uninstall Python
  • Step #4: Remove Python from Path
  • How To Uninstall Python From Mac
  • Step #1: Remove Python from Applications
  • Step #2: Remove Python from /Library
  • Step #3: Remove Symbolic Links
  • How To Uninstall Python From Linux

  • Cách gỡ cài đặt hoàn toàn Python khỏi Windows
  • Phương pháp 1: Sử dụng bảng điều khiển
  • Phương pháp 2: Thủ công
  • Phương pháp 3: Sử dụng CMD
  • Sự kết luận
  1. Để gỡ cài đặt hoàn toàn Python khỏi Windows

    Để gỡ cài đặt hoàn toàn python khỏi windows, hãy sử dụng các bước sau. và sẽ có thể làm được điều đó. Trước hết, hãy mở bảng điều khiển của bạn. Sau đó bấm vào uninstall a program để gỡ cài đặt nó. Sau đó, chuyển đến Python và nhấp vào gỡ cài đặt cho từng phiên bản bạn không muốn nữa. từ các bước này, bạn hoàn toàn có thể gỡ cài đặt Python khỏi Windows. Tôi hy vọng nó sẽ giúp bạn.

  2. Gỡ cài đặt Python khỏi Windows

    Gỡ cài đặt Python khỏi Windows. Làm theo các bước sau để Gỡ cài đặt hoàn toàn Python khỏi Windows. Trước hết, hãy mở Command Prompt của bạn. Sau đó chạy cái này cd C:Users<you name>AppDataLocalMicrosoftWindowsAppssau đó del python.exesau đó del python3.exeSau bước này, bạn sẽ thấy python đã được gỡ cài đặt hoàn toàn.

  3. Gỡ cài đặt hoàn toàn Python khỏi Windows

    Gỡ cài đặt hoàn toàn Python khỏi Windows Làm theo các bước sau để gỡ cài đặt hoàn toàn Python khỏi Windows. Đầu tiên mở CMD. Sau đó, nó sẽ hiển thị tất cả các gói đã cài đặt, bấm vào đây: danh sách pip. Sau đó, sao chép tên gói vào một tệp: pip freeze > requirements.txt. Sau đó, xóa tất cả các gói bằng cách pip uninstall -r requirements.txt -y. Từ danh sách pip, hãy kiểm tra tất cả các gói đã được gỡ bỏ. Sau đó gỡ cài đặt pip và các gói còn lại khác. Nó sẽ giúp bạn.

Phương pháp 1: Sử dụng bảng điều khiển

Chỉ cần sử dụng các bước sau. và sẽ có thể làm được điều đó.

  1. Trước hết, hãy mở bảng điều khiển của bạn
  2. Sau đó bấm vào uninstall a program để gỡ cài đặt nó.
  3. Sau đó, chuyển đến Python và nhấp vào gỡ cài đặt cho từng phiên bản bạn không muốn nữa. từ các bước này, bạn hoàn toàn có thể gỡ cài đặt Python khỏi Windows.

Tôi hy vọng nó sẽ giúp bạn.

Phương pháp 2: Thủ công

Chỉ cần sử dụng bên dưới tất cả các bước.

  1. Trước hết, hãy mở Command Prompt của bạn.
  2. Sau đó chạy cái này cd C:Users<you name>AppDataLocalMicrosoftWindowsApps
  3. sau đó del python.exe
  4. sau đó del python3.exe

Sau bước này, bạn sẽ thấy python đã được gỡ cài đặt hoàn toàn.

Phương pháp 3: Sử dụng CMD

Làm theo các bước sau.

  1. Trước hết hãy mở CMD.
  2. Sau đó, nó sẽ hiển thị tất cả các gói đã cài đặt, nhấp vào đây: danh sách pip
  3. Sau đó, sao chép tên gói vào một tệp: pip freeze > requirements.txt
  4. Sau đó, xóa tất cả các gói bằng cách pip uninstall -r requirements.txt -y
  5. Từ danh sách pip, hãy kiểm tra tất cả các gói đã được gỡ bỏ.
  6. Sau đó gỡ cài đặt pip và các gói còn lại khác

Nó sẽ giúp bạn.

Sự kết luận

Đó là tất cả về Hướng dẫn này. Hy vọng tất cả các phương pháp đã giúp bạn rất nhiều. Bình luận bên dưới Suy nghĩ của bạn và truy vấn của bạn. Ngoài ra, hãy Bình luận bên dưới phương pháp nào hiệu quả với bạn?

"

This article is part of in the series

Published: Wednesday 21st July 2021

Last Updated: Wednesday 29th December 2021

Every version of Python comes with bug fixes and security patches. To ensure that you’re not affected by bugs and security issues that have been fixed, removing the old version is necessary.

While you can use more than one Python version on the same computer, installing a new version of Python before removing the old one sometimes breaks Python on the computer. 

Thankfully, uninstalling Python before installing the new version fixes it, and doing it isn’t very difficult. We’ve broken down how to remove Python on every operating system in this post.

How to Uninstall Python From Windows, Mac, And Linux

There is no standard way to uninstall Python on operating systems. You will need to follow uninstallation steps specific to the operating system on your computer. 

Note: If you want to remove Python packages from your computer, you do not need to uninstall Python from your computer. You can add, remove, and search for specific Python packages using the pip tool. If you don’t know how to use pip, our detailed guide will teach you what you need to know in a matter of minutes.

How To Uninstall Python From Windows

Windows makes it easy to uninstall Python. You can remove any version of Python installed on your computer in three simple steps.

Step #1: Navigate to the Control Panel

Press the Windows key on your keyboard or press the Windows button on the bottom-left of your screen to open the Start menu.

Type in “Control Panel” and find and launch the Control Panel from the list of options. 

After the Control Panel opens up, you must click on the “Uninstall a program” button under the “Programs” section on the bottom left.

A menu with all of the programs installed on the computer will open up.

Step #3: Uninstall Python

You must scroll down the list of programs and find the version(s) of Python installed on your computer. Next, select the program by left-clicking on it and click the “Uninstall” button.

The uninstallation wizard will launch, and after you confirm your decision to uninstall Python, it will be removed from your computer.

To remove Python from your computer completely, you will need to remove Python from Path.

Step #4: Remove Python from Path

The Python uninstaller automatically removes Python from Path when it runs. That said, it is best to check whether Python has been removed from Path. It’s easy to do and doesn’t take long:

  1. Press the Windows key and enter “environment variables.” Launch the settings menu in the Control Panel. 

  2. A “System Properties” menu will appear. Find and click the “Environment Variables” button.

  3. Highlight the “Path” variable in the system variable section by left-clicking it. Then press the “Edit” button.

  4. If you see a path of the Python bin folder in the menu, remove it by selecting it and pressing the “Delete” button on the right side of the menu.

And with that, you will have removed Python entirely from your Windows computer.

How To Uninstall Python From Mac

Uninstalling Python on a computer running macOS is not always a good idea. This is because macOS comes with Python pre-installed, and the operating system depends on Python for its inner workings.

The pre-installed Python framework appears in /System/Library/Frameworks/Python.framework. Several symlinks can be found in usr/bin/python.

Removing this version of Python will break macOS and may cause the OS to malfunction. You can read more about this at Stack Exchange’s Q&A site for programmers, Stack Overflow.

That said, if you’ve installed a third-party Python framework on your Mac, you can uninstall it safely. Here’s how you do it:

Step #1: Remove Python from Applications

Open up Finder, and navigate to the Applications folder. Here, you will find folders of the Python version(s) you have installed. You must move them to the Trash. 

If you only want to remove a specific version of Python from your Mac, make sure you only move the relevant Python folder into the Trash.

If a dialog box appears asking you to enter the password to your computer, enter the password and click “OK.”

The folders will have moved to the Trash. Next, you must navigate to the Trash, highlight the Python version(s), and right-click. From the options that appear, select the “Delete Immediately” option.

Deleting the folder will not remove Python from the computer completely. You must remove it from the Library directory and also remove the symbolic links.

Step #2: Remove Python from /Library

You will need to use the Terminal to remove Python from the Library directory. To open Terminal, press Cmd + Space and search for it, then launch it.

To remove the third-party frameworks from the directory, enter the following command into Terminal:

sudo rm -rf /Library/Frameworks/Python.framework

You may be asked to enter your system password. Enter it if prompted.

If you want to remove only a specific version of Python from your computer, specify the version by modifying the command like so:

sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.8

Step #3: Remove Symbolic Links

Steps #1 and #2 will have removed Python directories and files from your Mac. However, links that reference Python folders that have been deleted may remain on your computer. These links are called symbolic links (or symlinks).

There are two ways to remove these links from your computer:

#1 Manual Deletion

The links that reference Python folders are in /usr/local/bin. Since the folders that are referenced in the links no longer exist, these links will be broken. 

You can see all of the broken symlinks by entering the following command in the Terminal:

ls -l /usr/local/bin | grep ‘../Library/Frameworks/Python.framework’

If you’ve only removed a specific version of Python, make sure you replace the path in the above command with the path you used in step #2.

After you see all the broken links, use these commands to delete them:

To enter the directory:

To delete the broken links:

ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework' | awk '{print $9}' | tr -d @ | xargs rm*

If the path in the command above is different from the path you used in step #2, replace the path in the command above with the one you used.

After you run these commands, the installed Python version will be removed from your Mac.

#2 Using Homebrew

You can also remove the broken symlinks from your computer using Homebrew. If you don’t have it installed, run the following command to install it:

/bin/bash -c "$(curl -fsSL//raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Finding broken links is much easier with Homebrew. To find them, run this command:

A list of broken symlinks will appear. You can then use the following command to remove them:

How To Uninstall Python From Linux

Linux is similar to macOS – in that Python comes pre-installed on the operating system. Further, removing the pre-installed version of the software causes the OS to malfunction.

Typically, the Graphical Display Manager fails when Python is uninstalled from Linux.

For this reason, you can only uninstall the Python versions that you installed manually. 

To remove the version of Python you installed, use the following command on the Terminal:

sudo apt purge -y python2.x-minimal

You can remove Python 3 from Linux distros using this command:

sudo ln -s /usr/bin/python3 /usr/bin/python

To remove pip from the system:

sudo apt install -y python3-pip

sudo ln -s /usr/bin/pip3 /usr/bin/pip

If you find that the commands aren’t working, you may need to update your repo list using sudo apt get update.

Conclusion

And with that, you know how to uninstall Python from your computer completely. 

You can now install the latest version of Python on your computer without worrying about it breaking or dealing with bugs that have already been fixed. 

To ensure you install the new Python version on your computer safely, make sure you go through our Python installation guide. If this post helped or you think we can improve this answer, let us know in the comments.

  1. Home
  2. Python Tips and Tricks
  3. Python Library Tutorials
  4. Python How To's
  5. Python Tutorials

Chủ đề