錯誤:python 套件安裝時的外部管理環境

DDD
發布: 2024-11-15 13:08:02
原創
153 人瀏覽過

Symptoms

I attempted to install a Python package using this command.

pip3 install [package-name]
登入後複製

And then this error was thrown.

Error: externally-managed-environment on python package installation

Error: externally-managed-environment on python package installation

Description

  • Two types of Python are used in a single MacOS machine - User-specific and System-wide packages.
  • System-wide packages are shared by all the users, and even system package managers like apt. Installing user-specific packages as system-wide packages is very dangerous because it can conflict with system package managers if they run some Python scripts.

Solution

  1. Create path/.config/pip/pip.conf and type this script.

    [global]
    break-system-packages = true
    user = true
    
    登入後複製
  2. Install pipenv to manage dependencies per project. The pip.conf file let the command run with --break-system-packages and --user options.

    pip3 install pipenv
    
    登入後複製
  3. Run a file with the all project dependencies in a virtual environment

    pipenv run python [file-name] .py
    
    登入後複製
  4. Otherwise, you could run up a virtual environment instance and run the python file.

    pipenv shell
    python [file-name].py
    
    登入後複製

以上是錯誤:python 套件安裝時的外部管理環境的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板