How To Install Packages In Python Using Cmd
The Pip Package Manager is the de facto standard for managing Python distributions, and is recommended for installing Python packages for Windows.
Pip is installed automatically with Python 2 (>=2.7.9) and Python 3 (>=3.4) installations. The pip command has options for installing, upgrading and deleting packages, and can be run from the Windows command line. By default, pip installs packages located in the Python Package Index (PyPI), but can also install from other indexes. For more information on how to use pip, see the Pip Package Installation instructions below.
Wheels and Windows
Python packages installed with pip on Windows are typically bundled into 'wheels' prior to installation. A wheel is a zip-style archive that contains all the files necessary for a typical package installation. Wheels have a .whl extension, and provide a simpler installation than 'non-wheel' packages.
Depending on the operating system that a package was built for and built on, the resulting wheel may not include file requirements for Windows. Appveyor offers a hosted continuous integration service that developers can use to package Python code for Windows deployments. Wheels built with Appveyor incorporate Windows support by default, and are usually recognizable by their name, e.g. packagename-2.8-cp37-cp37m-win_amd64.whl.
Installation Requirements
Before packages can be installed, ensure that your existing Python installation meets the requirements. Requirements will differ depending on whether you installed Python into a virtual environment using venv or virtualenv:
- Venv automatically installs pip into Python 3.4+ virtual environments
- Virtualenv automatically installs pip and wheel into Python 2.7+ and Python 3.3+ virtual environments
Note: If you're using some form of enhanced shell such as IPython, then prefix the command with the ! character, e.g. !pip install < packagename >
- Verify that Python is installed:
Open a Windows command window and run the following command to check that a suitable Python version is installed:
python --version
Output should be similar to:
Python 3.6.6 .
If Python is not installed, you can download a copy of ActiveState's Python, ActivePython , for free.
- Verify that Pip is installed:
pip --version
Output should be similar to pip 19.3.1 from c:\python36\lib\site-packages\pip (python 3.6)
- Update Pip and Wheel to ensure you have the latest version installed:
pip install --upgrade pip wheel
Pip Package Installation
To install a package:
pip install < packagename >
To install a package from a repository other than PyPI, for instance, Github:
pip install -e git+< https://github.com/myrepo.git#egg=packagename >
To upgrade a package that is already installed:
pip install --upgrade < packagename >
To uninstall a package:
pip uninstall < packagename >
To show help for pip, including complete command usage and options:
pip -h pip --help
Pipenv
Pipenv is a new tool for managing dependencies. It uses pip and virtualenv under the hood, and simplifies their usage with a single command line syntax. Like venv , pipenv automatically creates a separate virtual environment for each project.
To install, upgrade or uninstall packages within pipenv, just replace the pip command with pipenv. For example, the following command installs a named package from PyPI:
pipenv install < packagename >
You can also install packages from locations other than PyPI. For example, the following command installs the requests package from a Github repository:
pipenv install -e git+https://github.com/requests/requests.git#egg=requests
Manual Package Installation
Most Python packages are now designed to be compatible with pip. If you have a package that's not compatible, then you'll need to do a manual installation.
How to manually install a Python package:
- Download the package and extract it into a local directory.
2a. If the package came with its own set of installation instructions, they should be followed.
2b. If not, then open a command window and cd into the directory, and enter:
python setup.py install
How ActiveState Can Help
ActiveState provides a unified cross-platform toolchain for modern Python package management. It can replace the complex and hard-to-maintain in-house solutions built from multiple package managers, environment management tools and other solutions.
By adopting the ActiveState Platform, developers can:
- Automated building of packages from source, including link C libraries without the need for a local build environment.
- Automated resolution of dependencies (or suggestions on how to manually resolve conflicts), ensuring that your environment always contains a set of known good dependencies that work together.
- Central management of a single source of truth for your environment that can be deployed with a single command to all development and CI/CD environments, ensuring consistent reproducibility.
- Automated installation of virtual Python environments on Windows or Linux without requiring prior setup.
- The ability to find, fix and automatically rebuild vulnerable environments, thereby enhancing security and dramatically reducing time and effort involved in resolving CVEs.
- Visually seeing which versions of which packages are approved for use, thereby taking the guesswork out of development.
Those that prefer to work from the command line can leverage the ActiveState Platform's CLI, the State Tool, which acts as a universal package manager for Python, and provides access to most of the features offered by the Platform.
Modern Python Package Management
ActiveState provides a unified cross-platform toolchain for modern Python package management. It can replace the complex and hard-to-maintain in-house solutions built from multiple package managers, environment management tools and other solutions.
By adopting the ActiveState Platform, developers can:
- Increase the security of Python environments
- Improve the transparency of your open source supply chain
- Dramatically reduce package and environment management overhead
- Eliminate dependency hell
- Reduce "works on my machine" issues
Ultimately, developers that are willing to adopt the ActiveState Platform will spend less time wrestling with tooling and more time focused on doing what they do best: coding.
To try the ActiveState Platform for yourself, sign-up for a free account.
Recommended Reads
How to Manually Install Python Packages
Data Sheet: ActiveState Platform's Hosted Artifact Repository
How To Install Packages In Python Using Cmd
Source: https://www.activestate.com/resources/quick-reads/python-package-installation-on-windows/
Posted by: jarrettsearpon.blogspot.com
0 Response to "How To Install Packages In Python Using Cmd"
Post a Comment