Python Windows 10

Python Path to Windows 10 PATH



Installing Pip on Windows




Upgrading Pip


python -m pip install --upgrade pip


Downgrading Pip


python -m pip install pip==18.0


Install Python Packages


Requirements

Python

When installing a package, we must first ensure that Python is installed on the system. We can verify this by running the following command in a terminal.

root@host [~]# python --version

Pip

Pip is the default package manager for python. It is used to install and manage python software from the command line.

root@host [~]# python -m pip --version
pip 19.3.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)

root@host [~]# python -m ensurepip --default-pip

PyPi

PyPi or the “Python Package Index” is a software repository that contains applications used by the python programming language. PyPi supports installing software from distribution files, local projects, and can utilize version control features. It also uses “requirement specifiers” to better define specific versions, variants, and also supports the url_req-form specs. Currently, PyPI houses more than 200,000 python projects. Install options include:

root@host [~]# pip install software
root@host [~]# pip install software == 1.5
root@host [~]# pip install software >=1.3,<3.0 
root@host [~]# pip install software[foo, bar] 
root@host [~]# pip install software ~=1.4.5  

Setuptools

Setuptools is a stable and fully featured python library intended to assist with the packaging of Python projects.

Wheel

Wheel is a Python library used as an extension of setuptools intended for working with wheel files. To install these two libraries, we need to run the following command.

root@host [~]# python -m pip install --upgrade pip setuptools wheel 

Venv (Optional)

Venv is a python module used to build and manage isolated, lightweight virtual environments in which differing python versions and modules can be utilized.

root@host [~]# python3 -m venv
root@host [~]# source /bin/activate

Install Mediums

Python has multiple methods and options available for installing software. Packages can be installed via the following methods:

  • From the PyPI repository:
 root@host:~# pip install package1
  • From VCS: (Version Control System)
root@host:~# pip install -e git+https://git.repo/package1
  • From other Indexes: (sources other than PyPi)
 root@host:~# pip install --index-url http://git.repo/package1
  • From a local src tree:
root@host:~# pip install -e /path/package1
  • From a local archive: (/mydrive/downloads/project.1.2.3)
root@host:~# pip install /path/package1
  • From other sources: (e.g., Amazon S3)
root@host:~# /s3helper --port=9999
root@host:~# pip install --extra-index-url http://localhost:9999
  • From Pre-releases:
    (when installing a beta version, python defaults to the stable version)
root@host:~# pip install --pre package1

In a Virtual Environment

As a quick overview, installing Python packages can be accomplished using this quick three-step process.

Step 1. Create a virtual environment

python3 -m venv .myvenv

Step 2. Activate the virtual environment

source .myvenv/bin/activate

Step 3. Install your package

python3 -m pip install package1

Using this method, we contain our installed package to a virtual environment that does not make any system-wide changes. Should we actually want to implement a Python package system-wide, we dispense with Steps 1 and 2.

Using venv

root@host [~]# python3 -m venv .myvenv
root@host [~]# source .myvenv/bin/activate

Using virtualenv

root@host [~]# virtualenv .myvenv
root@host [~]# source .myvenv/bin/activate

Installing from PyPI

To install a package from PyPi, we run the following command.

root@host [~]# pip install "myproject"

To install a specific version, we run:

root@host [~]# pip install "myproject==1.4"

To install a package that is greater than or equal to one version and less than another, we can run:

root@host [~]# pip install "myproject>=1,<3"

To install a version that is “compatible” with a specific version, run:

root@host [~]# pip install "myproject~=1.2.3" 

In this scenario, this indicates that Python will install any version “==1.4.*” or a version that’s also “>=1.4.2”.

Upgrading packages

To upgrade a package to the latest version from PyPI that is already installed, we run:

root@host [~]# pip install --upgrade "myproject"

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

สอนเขียน Python เพื่อใช้ SSH ด้วย Paramiko และ Netmiko แบบรวบรัด

เริ่มพัฒนา Web Application กับภาษา Python ด้วย Django Framework

ตัวอย่างที่น่าสนใจ