البرمجة

كيفية تثبيت Python 2 على macOS باستخدام Homebrew

To switch back to Python 2 on your Mac, you can follow these steps:

  1. Uninstall Anaconda: Since you’ve already deleted the Anaconda folder, you may want to check if there are any remaining traces of Anaconda or Python 3 and remove them. You can do this by checking your ~/.bash_profile, ~/.bashrc, and ~/.profile files for any Anaconda-related paths and removing them.

  2. Install Python 2:

    • Download the latest version of Python 2 for macOS from the official Python website.
    • Open the downloaded .dmg file and run the installer.
    • During the installation, make sure to select the option to install the command-line tools.
  3. Update Your Shell Profile:

    • Open a terminal window.
    • Edit your shell profile (.bash_profile, .bashrc, or .zshrc depending on your setup) using a text editor like nano or vim:
      bash
      nano ~/.bash_profile
    • Add the following line at the end of the file to ensure that Python 2 is used as the default Python interpreter:
      bash
      export PATH="/usr/local/bin:$PATH"
  4. Apply Changes:

    • Save the file and exit the text editor (Ctrl + X, then Y to confirm, then Enter).
    • Source the updated shell profile to apply the changes:
      bash
      source ~/.bash_profile
  5. Verify Installation:

    • Check if Python 2 is now the default Python interpreter by running:
      bash
      python --version
    • You should see the version of Python 2 you installed.

After following these steps, you should have Python 2 set up as your default Python interpreter on your Mac.

المزيد من المعلومات

بالتأكيد! إذا كنت تواجه مشكلة في تنزيل Python 2 من موقع Python الرسمي، يمكنك استخدام Homebrew لتثبيت Python 2 بسهولة. يمكنك اتباع الخطوات التالية:

  1. تثبيت Homebrew:

    • افتح محرر النصوص (مثل Terminal) وقم بتشغيل الأمر التالي:
      bash
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    • اتبع التعليمات على الشاشة لإكمال التثبيت.
  2. تثبيت Python 2 باستخدام Homebrew:

    • بمجرد تثبيت Homebrew، قم بتنفيذ الأمر التالي لتثبيت Python 2:
      bash
      brew install python@2
    • ستحتاج إلى تأكيد التثبيت بإدخال كلمة المرور الخاصة بك.
  3. تحديث ملفات النظام:

    • يجب عليك تحديث ملفات النظام لاستخدام Python 2 كافتراضي. قم بتحرير ملف .bash_profile باستخدام الأمر التالي:
      bash
      nano ~/.bash_profile
    • أضف السطر التالي في نهاية الملف:
      bash
      export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"
    • احفظ التغييرات وأغلق المحرر (Ctrl + X ثم Y ثم Enter).
  4. تطبيق التغييرات:

    • قم بتنفيذ الأمر التالي لتطبيق التغييرات:
      bash
      source ~/.bash_profile
  5. التحقق من التثبيت:

    • قم بالتحقق من أن Python 2 قد تم تثبيته بنجاح بواسطة الأمر:
      bash
      python2 --version
    • يجب أن تظهر إصدار Python 2 الذي قمت بتثبيته.

بعد اتباع هذه الخطوات، يجب أن يكون لديك Python 2 مثبتًا ومضبوطًا كافتراضي على نظام macOS الخاص بك.

مقالات ذات صلة

زر الذهاب إلى الأعلى

هذا المحتوى محمي من النسخ لمشاركته يرجى استعمال أزرار المشاركة السريعة أو تسخ الرابط !!