TOP

2020年9月12日 星期六

[Python] pip 套件管理


 


PyPI (Python Package Index)

https://pypi.org/

pip (The Python Package Installer)

https://pypi.org/project/pip/

https://github.com/pypa/pip

 

root@moonshine:/home/qoo/Downloads# python3 --version

Python 3.7.3

 

 

[get-pip.py]

https://pip.pypa.io/en/stable/installing/

 

 

[Install PIP]

[1] @Linux

python3 get-pip.py

root@moonshine:/home/qoo/Downloads# python3 get-pip.py

Traceback (most recent call last):

  File "get-pip.py", line 22711, in <module>

    main()

  File "get-pip.py", line 198, in main

    bootstrap(tmpdir=tmpdir)

  File "get-pip.py", line 82, in bootstrap

    from pip._internal.cli.main import main as pip_entry_point

  File "/tmp/tmp_vmeihhh/pip.zip/pip/_internal/cli/main.py", line 10, in <module>

  File "/tmp/tmp_vmeihhh/pip.zip/pip/_internal/cli/autocompletion.py", line 9, in <module>

  File "/tmp/tmp_vmeihhh/pip.zip/pip/_internal/cli/main_parser.py", line 7, in <module>

  File "/tmp/tmp_vmeihhh/pip.zip/pip/_internal/cli/cmdoptions.py", line 19, in <module>

ModuleNotFoundError: No module named 'distutils.util'

=> 出現 ModuleNotFoundError: No module named 'distutils.util'  錯誤, 需修正:

sudo apt-get install python3-distutils

root@moonshine:/home/qoo/Downloads# apt-get install python3-distutils

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following additional packages will be installed:

  python3-lib2to3

The following NEW packages will be installed:

  python3-distutils python3-lib2to3

0 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.

Need to get 219 kB of archives.

After this operation, 1,086 kB of additional disk space will be used.

Do you want to continue? [Y/n]

Get:1 http://deb.debian.org/debian buster/main amd64 python3-lib2to3 all 3.7.3-1 [76.7 kB]

Get:2 http://deb.debian.org/debian buster/main amd64 python3-distutils all 3.7.3-1 [142 kB]

Fetched 219 kB in 1s (432 kB/s)       

Selecting previously unselected package python3-lib2to3.

(Reading database ... 359231 files and directories currently installed.)

Preparing to unpack .../python3-lib2to3_3.7.3-1_all.deb ...

Unpacking python3-lib2to3 (3.7.3-1) ...

Selecting previously unselected package python3-distutils.

Preparing to unpack .../python3-distutils_3.7.3-1_all.deb ...

Unpacking python3-distutils (3.7.3-1) ...

Setting up python3-lib2to3 (3.7.3-1) ...

Setting up python3-distutils (3.7.3-1) ...

 

再次執行 python3 get-pip.py 可安裝成功

root@moonshine:/home/qoo/Downloads# python3 get-pip.py

Collecting pip

  Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB)

     |████████████████████████████████| 1.4 MB 749 kB/s

Collecting setuptools

  Downloading setuptools-45.2.0-py3-none-any.whl (584 kB)

     |████████████████████████████████| 584 kB 2.0 MB/s

Collecting wheel

  Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)

Installing collected packages: pip, setuptools, wheel

Successfully installed pip-20.0.2 setuptools-45.2.0 wheel-0.34.2

 

[2] @Windows

下載 pip C:\Users\Qoo\Downloads

PS C:\Users\Qoo> cd C:\Users\Qoo\Downloads

PS C:\Users\Qoo\Downloads> python .\get-pip.py

Collecting pip

  Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB)

     |████████████████████████████████| 1.4 MB 656 kB/s

Collecting wheel

  Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)

Installing collected packages: pip, wheel

  Attempting uninstall: pip

    Found existing installation: pip 19.2.3

    Uninstalling pip-19.2.3:

      Successfully uninstalled pip-19.2.3

Successfully installed pip-20.0.2 wheel-0.34.2

 

 

[pip version]

[Win7X64]

#pip --version

pip 20.0.2 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

[Termux]

$pip --version

pip 19.0.3 from /data/data/com.termux/files/usr/lib/python3.7/site-packages/pip (python 3.7)

 

 

[Upgrading pip]

python -m pip install –upgrade pip

=> python -m pip install --upgrade pip -i https://pypi.douban.com/simple

pip install -U pip

pip install --upgrade pip

 

 

[Upgrading other package]

pip install --upgrade xxx

 

 

[Uninstall]

pip uninstall xxx

 

 

[syntax]

PS C:\Users\qoo> pip

 

Usage:

  pip <command> [options]

 

Commands:

  install                     Install packages.

  download                    Download packages.

  uninstall                   Uninstall packages.

  freeze                      Output installed packages in requirements format.

  list                        List installed packages.

  show                        Show information about installed packages.

  check                       Verify installed packages have compatible dependencies.

  config                      Manage local and global configuration.

  search                      Search PyPI for packages.

  cache                       Inspect and manage pip's wheel cache.

  wheel                       Build wheels from your requirements.

  hash                        Compute hashes of package archives.

  completion                  A helper command used for command completion.

  debug                       Show information useful for debugging.

  help                        Show help for commands.

 

General Options:

  -h, --help                  Show help.

  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.

  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.

  -V, --version               Show version and exit.

  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to

                              WARNING, ERROR, and CRITICAL logging levels).

  --log <path>                Path to a verbose appending log.

  --no-input                  Disable prompting for input.

  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.

  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).

  --timeout <sec>             Set the socket timeout (default 15 seconds).

  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.

  --trusted-host <hostname>   Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.

  --cert <path>               Path to alternate CA bundle.

  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.

  --cache-dir <dir>           Store the cache data in <dir>.

  --no-cache-dir              Disable the cache.

  --disable-pip-version-check

                              Don't periodically check PyPI to determine whether a new version of pip is available for

                              download. Implied with --no-index.

  --no-color                  Suppress colored output

  --no-python-version-warning

                              Silence deprecation warnings for upcoming unsupported Pythons.

  --use-feature <feature>     Enable new functionality, that may be backward incompatible.

  --use-deprecated <feature>  Enable deprecated functionality, that will be removed in the future.

 

 

沒有留言:

張貼留言