התקן את TensorFlow עם pip

מדריך זה מיועד לגרסה היציבה האחרונה של TensorFlow. לבניית התצוגה המקדימה (לילי) , השתמש בחבילת pip בשם tf-nightly . עיין בטבלאות אלה לדרישות גרסה ישנות יותר של TensorFlow. עבור ה-CPU בלבד, השתמש בחבילת pip בשם tensorflow-cpu .

להלן הגרסאות המהירות של פקודות ההתקנה. גלול מטה לקבלת הוראות שלב אחר שלב.

לינוקס

python3 -m pip install tensorflow[and-cuda]
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

MacOS

# There is currently no official GPU support for MacOS.
python3 -m pip install tensorflow
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

Windows Native

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
# Anything above 2.10 is not supported on the GPU on Windows Native
python -m pip install "tensorflow<2.11"
# Verify the installation:
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Windows WSL2

python3 -m pip install tensorflow[and-cuda]
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

מעבד

python3 -m pip install tensorflow
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

לֵילִי

python3 -m pip install tf-nightly
# Verify the installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

דרישות חומרה

ההתקנים הבאים התומכים ב-GPU נתמכים:

  • כרטיס NVIDIA® GPU עם ארכיטקטורות CUDA® 3.5, 5.0, 6.0, 7.0, 7.5, 8.0 ומעלה. עיין ברשימה של כרטיסי GPU התומכים ב-CUDA® .
  • עבור GPUs עם ארכיטקטורות CUDA® שאינן נתמכות, או כדי להימנע מהידור של JIT מ-PTX, או לשימוש בגרסאות שונות של ספריות NVIDIA®, עיין במדריך ה- Linux build ממקור .
  • חבילות אינן מכילות קוד PTX למעט ארכיטקטורת CUDA® הנתמכת העדכנית ביותר; לכן, TensorFlow נכשל בטעינת מעבדי GPU ישנים יותר כאשר CUDA_FORCE_PTX_JIT=1 מוגדר. (ראה תאימות יישומים לפרטים.)

דרישות מערכת

  • אובונטו 16.04 ומעלה (64 סיביות)
  • macOS 10.12.6 (Sierra) ומעלה (64 סיביות) (ללא תמיכה ב-GPU)
  • Windows Native - Windows 7 ומעלה (64 סיביות) (ללא תמיכה ב-GPU לאחר TF 2.10)
  • Windows WSL2 - Windows 10 19044 ומעלה (64 סיביות)

דרישות תוכנה

תוכנת NVIDIA® הבאה נדרשת רק לתמיכה ב-GPU.

הוראות שלב אחר שלב

לינוקס

1. דרישות המערכת

  • אובונטו 16.04 ומעלה (64 סיביות)

TensorFlow תומך רק באובונטו באופן רשמי. עם זאת, ההוראות הבאות עשויות לעבוד גם עבור הפצות לינוקס אחרות.

2. הגדרת GPU

אתה יכול לדלג על סעיף זה אם אתה מפעיל את TensorFlow רק במעבד.

התקן את מנהל ההתקן של NVIDIA GPU אם לא עשית זאת. אתה יכול להשתמש בפקודה הבאה כדי לוודא שהוא מותקן.

nvidia-smi

3. התקן את TensorFlow

TensorFlow דורשת גרסה עדכנית של pip, אז שדרג את התקנת ה-pip שלך כדי להיות בטוח שאתה מפעיל את הגרסה העדכנית ביותר.

pip install --upgrade pip

לאחר מכן, התקן את TensorFlow עם pip.

# For GPU users
pip install tensorflow[and-cuda]
# For CPU users
pip install tensorflow

4. ודא את ההתקנה

ודא את הגדרת המעבד:

python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

אם טנזור מוחזר, התקנת את TensorFlow בהצלחה.

אמת את הגדרת ה-GPU:

python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

אם מוחזרת רשימה של התקני GPU, התקנת את TensorFlow בהצלחה.

MacOS

1. דרישות המערכת

  • macOS 10.12.6 (סיירה) ומעלה (64 סיביות)

נכון לעכשיו אין תמיכה רשמית ב-GPU להפעלת TensorFlow ב-MacOS. ההוראות הבאות מיועדות להפעלה על מעבד.

2. בדוק את גרסת Python

בדוק אם סביבת Python שלך כבר מוגדרת:

python3 --version
python3 -m pip --version

3. התקן את TensorFlow

TensorFlow דורשת גרסה עדכנית של pip, אז שדרג את התקנת ה-pip שלך כדי להיות בטוח שאתה מפעיל את הגרסה העדכנית ביותר.

pip install --upgrade pip

לאחר מכן, התקן את TensorFlow עם pip.

pip install tensorflow

4. ודא את ההתקנה

python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

אם טנזור מוחזר, התקנת את TensorFlow בהצלחה.

Windows Native

1. דרישות המערכת

  • Windows 7 ומעלה (64 סיביות)

2. התקן את Microsoft Visual C++ Redistributable

התקן את Microsoft Visual C++ הניתן להפצה מחדש עבור Visual Studio 2015, 2017 ו-2019 . החל מגירסת TensorFlow 2.1.0, הקובץ msvcp140_1.dll נדרש מחבילה זו (שאולי לא מסופקת מחבילות ישנות יותר שניתן להפצה מחדש). ההפצה מחדש מגיעה עם Visual Studio 2019 אך ניתן להתקין אותה בנפרד:

  1. עבור אל ההורדות של Microsoft Visual C++ .
  2. גלול למטה בעמוד לקטע Visual Studio 2015, 2017 ו-2019 .
  3. הורד והתקן את Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 ו-2019 עבור הפלטפורמה שלך.

ודא שנתיבים ארוכים מופעלים ב-Windows.

3. התקן מיניקונדה

Miniconda היא הגישה המומלצת להתקנת TensorFlow עם תמיכה ב-GPU. זה יוצר סביבה נפרדת כדי להימנע משינוי כל תוכנה מותקנת במערכת שלך. זוהי גם הדרך הקלה ביותר להתקין את התוכנה הנדרשת במיוחד עבור הגדרת ה-GPU.

הורד את Miniconda Windows Installer . לחץ פעמיים על הקובץ שהורד ובצע את ההוראות שעל המסך.

4. צור סביבת קונדה

צור סביבת conda חדשה בשם tf עם הפקודה הבאה.

conda create --name tf python=3.9

אתה יכול לבטל ולהפעיל אותו באמצעות הפקודות הבאות.

conda deactivate
conda activate tf

ודא שהוא מופעל למשך שאר ההתקנה.

5. הגדרת GPU

אתה יכול לדלג על סעיף זה אם אתה מפעיל את TensorFlow רק במעבד.

תחילה התקן את מנהל ההתקן של NVIDIA GPU אם לא עשית זאת.

לאחר מכן התקן את ה-CUDA, cuDNN עם conda.

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0

6. התקן את TensorFlow

TensorFlow דורשת גרסה עדכנית של pip, אז שדרג את התקנת ה-pip שלך כדי להיות בטוח שאתה מפעיל את הגרסה העדכנית ביותר.

pip install --upgrade pip

לאחר מכן, התקן את TensorFlow עם pip.

# Anything above 2.10 is not supported on the GPU on Windows Native
pip install "tensorflow<2.11" 

7. ודא את ההתקנה

ודא את הגדרת המעבד:

python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

אם טנזור מוחזר, התקנת את TensorFlow בהצלחה.

אמת את הגדרת ה-GPU:

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

אם מוחזרת רשימה של התקני GPU, התקנת את TensorFlow בהצלחה.

Windows WSL2

1. דרישות המערכת

  • Windows 10 19044 ומעלה (64 סיביות). זה מתאים לגרסה 21H2 של Windows 10, העדכון של נובמבר 2021.

עיין במסמכים הבאים כדי:

2. הגדרת GPU

אתה יכול לדלג על סעיף זה אם אתה מפעיל את TensorFlow רק במעבד.

התקן את מנהל ההתקן של NVIDIA GPU אם לא עשית זאת. אתה יכול להשתמש בפקודה הבאה כדי לוודא שהוא מותקן.

nvidia-smi

3. התקן את TensorFlow

TensorFlow דורשת גרסה עדכנית של pip, אז שדרג את התקנת ה-pip שלך כדי להיות בטוח שאתה מפעיל את הגרסה העדכנית ביותר.

pip install --upgrade pip

לאחר מכן, התקן את TensorFlow עם pip.

# For GPU users
pip install tensorflow[and-cuda]
# For CPU users
pip install tensorflow

4. ודא את ההתקנה

ודא את הגדרת המעבד:

python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

אם טנזור מוחזר, התקנת את TensorFlow בהצלחה.

אמת את הגדרת ה-GPU:

python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

אם מוחזרת רשימה של התקני GPU, התקנת את TensorFlow בהצלחה.

מיקום החבילה

כמה מנגנוני התקנה דורשים את כתובת האתר של חבילת TensorFlow Python. הערך שתציין תלוי בגרסת Python שלך.

גִרְסָה כתובת אתר
לינוקס
תמיכה ב-Python 3.9 GPU https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-2.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Python 3.9 למעבד בלבד https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.15.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
תמיכה ב-Python 3.10 GPU https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-2.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Python 3.10 למעבד בלבד https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.15.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
תמיכה ב-Python 3.11 GPU https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-2.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Python 3.11 למעבד בלבד https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.15.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
macOS (מעבד בלבד)
פייתון 3.9 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.15.0-cp39-cp39-macosx_10_15_x86_64.whl
פייתון 3.10 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.15.0-cp310-cp310-macosx_10_15_x86_64.whl
פייתון 3.11 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.15.0-cp311-cp311-macosx_10_15_x86_64.whl
חלונות
Python 3.9 למעבד בלבד https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.15.0-cp39-cp39-win_amd64.whl
Python 3.10 למעבד בלבד https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.15.0-cp310-cp310-win_amd64.whl
Python 3.11 למעבד בלבד https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.15.0-cp311-cp311-win_amd64.whl