How to install package python
How to install package python
How to Manually Install Python Packages?
Python is one of the most famous and powerful languages in the world. It is a dynamically typed, high-level interpreted language intended for general use. Python first made its public appearance in the year 1991, which means it is a fairly old language. It was designed by Guido Van Rossum and developed by a non-profit organization called the Python Software Foundation. Two reasons for its popularity are listed below:
To use these packages with python it first needs to be installed on the system. There are a couple of ways to do the same. The most popular one is with the help of pip (package manager). But is this article we are going to do it manually without the help of any package manager. Which can be helpful in case the package to be installed is not supported by pip or any other reason.
Step 1: Install Python
So, if we are supposed to install a python module manually the first obvious prerequisite would be to install the Python source code which comes along with its interpreter. To install Python we first, need to visit the website python.org and click on the downloads tab. From the downloads tab, we can get the latest version of python.
Once it is downloading is complete we need to click it open. Now once the installer is opened we can select the option accordingly and proceed by clicking the next button.
At we will be shown the default installation location for python. We can either change it or better leave it as it is. But we need to copy the path so as to use the further steps.
And at last, we can click on the install button.
Once the installation is complete we can open the command-line tool or terminal and run the command below to check the proper installation of the python.
If python has been installed properly it would return the version number.
Step 2: Download Python Package From Any Repository
Once we are done with python installation we can download any python package of our choice. Here we have downloaded puautogui which is a python package that helps developers instruct and automate certain aspects of GUI such as gesture detection and else.
We are downloading pyautogui package source code from github as a zip file.
Step 3: Extract The Python Package
After we have the zip file of the python package we need to extract it in the location of our choice and search for the main package folder inside, which shares the same name as the package itself.
Step 4: Copy The Package In The Site Package Folder
Once we have found the main package folder from the extracted repository we have to place it in the reach of the python so as to facilitate its interaction. And the location where we need to place this package folder is the site packages folder which one would find in the Lib folder at the location where the python is installed. The address is given below for your convenience:
All we need to do is to locate the address above and paste the python package folder there.
Step 5: Install The Package
After placing the package folder in the reach of python that is in the site packages folder, we have to tell python that a package has been served to its reach and it needs to import it for further use. And this can simply be done by running the below command in the terminal.
So the five steps that are mentioned above conclude all that is there in order to import a python package manually without using any package manager.
How to install package python
Copy raw contents
It’s important to note that the term «package» in this context is being used to describe a bundle of software to be installed (i.e. as a synonym for a :term:`distribution ` ). It does not to refer to the kind of :term:`package ` that you import in your Python source code (i.e. a container of modules). It is common in the Python community to refer to a :term:`distribution ` using the term «package». Using the term «distribution» is often not preferred, because it can easily be confused with a Linux distribution, or another larger software distribution like Python itself.
This section describes the steps to follow before installing other Python packages.
Before you go any further, make sure you have Python and that the expected version is available from your command line. You can check this by running:
` section of the Hitchhiker’s Guide to Python.
If you’re a newcomer and you get an error like this:
It’s because this command and other suggested commands in this tutorial are intended to be run in a shell (also called a terminal or console). See the Python for Beginners getting started tutorial for an introduction to using your operating system’s shell and interacting with Python.
It’s recommended to write
Additionally, you’ll need to make sure you have :ref:`pip` available. You can check this by running:
If pip isn’t already installed, then first try to bootstrap it from the standard library:
While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to ensure you can also install from source archives:
See :ref:`section below ` for details, but here’s the basic :doc:`venv
` [3] command to use on a typical Linux system:
This will create a new virtual environment in the tutorial_env subdirectory, and configure the current shell to use it as the default python environment.
Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python3.6/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.
Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.
Also, what if you can’t install :term:`packages ` into the global site-packages directory? For instance, on a shared host.
In all these cases, virtual environments can help you. They have their own installation directories and they don’t share libraries with other virtual environments.
Currently, there are two common tools for creating Python virtual environments:
The basic usage is like so:
For more information, see the :doc:`venv
The use of :command:`source` under Unix shells ensures that the virtual environment’s variables are set within the current shell, and not in a subprocess (which then disappears, having no useful effect).
In both of the above cases, Windows users should _not_ use the :command:`source` command, but should rather run the :command:`activate` script directly from the command shell like so:
:ref:`pip` is the recommended installer. Below, we’ll cover the most common usage scenarios. For more detail, see the :doc:`pip docs
The most common usage of :ref:`pip` is to install from the :term:`Python Package Index
To install the latest version of «SomeProject»:
To install a specific version:
To install greater than or equal to one version and less than another:
To install a version that’s :pep:`»compatible» ` with a certain version: [4]
In this case, this means to install any version «==1.4.*» version that’s also «>=1.4.2».
If :ref:`pip` does not find a wheel to install, it will locally build a wheel and cache it for future installs, instead of rebuilding the source distribution in the future.
Upgrade an already installed SomeProject to the latest from PyPI.
For more information see the User Installs section from the pip docs.
expanded to the absolute path to your home directory) so you’ll need to add
Install a list of requirements specified in a :ref:`Requirements File
Install a project from VCS in «editable» mode. For a full breakdown of the syntax, see pip’s section on :ref:`VCS Support
Install from an alternate index
Search an additional index during install, in addition to :term:`PyPI
You can also install normally from src
Install a particular source archive file.
Install from a local directory containing archives (and don’t check :term:`PyPI
Find pre-release and development versions, in addition to stable versions. By default, pip only finds stable versions.
How to Install Python Packages
Python is a general-purpose programming language designed for various uses. For example, websites, industrial robotics, and even games all use the same core technology.
Python’s syntax is easy to learn, focusing on readability and reducing the maintenance of your created programs. In addition, it supports packages and modules, promoting modular programming and the reuse of code.
In this article, we will be discussing how to install a Python package. We will discuss Python packages, the requirements needed to install a software title, and the many other options available when setting up a new Python program.
What is a Python Package?
A Python package is a collection of modules located within a structured directory that provides a mechanism to run a piece of software. In this context, we reference a Python package as a type of distribution or a bundle of installed software on a system.
Additionally, we must differentiate between a module and a package. A module is a single file imported into Python instead of groups of modules bundled into a program. A type of package also exists where the Python source code is referenced and included in an entity. This is not the type of package we are referring to here.
Requirements
Python
Before installing packages in Python, we must first ensure the installation of Python on the system. We can verify this by running the following command in a terminal.
Pip is the default package manager for Python, used for installing and managing Python software from the command line. You can check the version you have installed using the following command.
Python Package Index (PyPi)
Python Package Index (PyPi) is a software repository that contains applications used by the Python programming language. PyPi supports installing software from distribution files and local projects. It can also utilize version control features.
In addition, PyPi also uses requirement specifiers to better define specific versions and variants and supports the url_req form specs. Currently, PyPI houses more than 200,000 Python projects.
Install options for PyPi include the following commands.
Setuptools
Setuptools is a stable and fully featured Python library intended to assist with the packaging of Python projects.
Wheel
To install the wheels and setuptools Python libraries, we need to run the following command.
Venv (Optional)
Venv is a Python module used to build and manage isolated, lightweight virtual environments to use differing Python versions and modules.
Install Mediums
Python has multiple methods and options available for installing software. For example, you can install packages for Python via the following methods.
Installing Packages¶
It’s important to note that the term “package” in this context is being used to describe a bundle of software to be installed (i.e. as a synonym for a distribution ). It does not to refer to the kind of package that you import in your Python source code (i.e. a container of modules). It is common in the Python community to refer to a distribution using the term “package”. Using the term “distribution” is often not preferred, because it can easily be confused with a Linux distribution, or another larger software distribution like Python itself.
Requirements for Installing Packages¶
This section describes the steps to follow before installing other Python packages.
Ensure you can run Python from the command line¶
Before you go any further, make sure you have Python and that the expected version is available from your command line. You can check this by running:
If you’re a newcomer and you get an error like this:
It’s because this command and other suggested commands in this tutorial are intended to be run in a shell (also called a terminal or console). See the Python for Beginners getting started tutorial for an introduction to using your operating system’s shell and interacting with Python.
It’s recommended to write
Ensure you can run pip from the command line¶
Additionally, you’ll need to make sure you have pip available. You can check this by running:
If pip isn’t already installed, then first try to bootstrap it from the standard library:
Ensure pip, setuptools, and wheel are up to date¶
While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to ensure you can also install from source archives:
Optionally, create a virtual environment¶
See section below for details, but here’s the basic venv 3 command to use on a typical Linux system:
This will create a new virtual environment in the tutorial_env subdirectory, and configure the current shell to use it as the default python environment.
Creating Virtual Environments¶
Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python3.6/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.
Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.
Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.
In all these cases, virtual environments can help you. They have their own installation directories and they don’t share libraries with other virtual environments.
Currently, there are two common tools for creating Python virtual environments:
venv is available by default in Python 3.3 and later, and installs pip and setuptools into created virtual environments in Python 3.4 and later.
How do I install Python packages on Windows?
I’m having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don’t have an executable for Python 2.6.
For instance to install Mechanize, I’m just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!
12 Answers 12
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Newer versions of Python for Windows come with the pip package manager. (source)
pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4
Use that to install packages:
So in your case it’d be:
This is a good tutorial on how to get easy_install on windows. The short answer: add C:\Python26\Scripts (or whatever python you have installed) to your PATH.
You don’t need the executable for setuptools. You can download the source code, unpack it, traverse to the downloaded directory and run python setup.py install in the command prompt
Starting with Python 2.7, pip is included by default. Simply download your desired package via
Packaging in Python is dire. The root cause is that the language ships without a package manager.
Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby’s Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.
So the right thing to do is to install pip. However if you can’t be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/
In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.
I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.
That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.
Источники информации:
- http://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst
- http://www.liquidweb.com/kb/how-to-install-python-packages/
- http://packaging.python.org/en/latest/tutorials/installing-packages/?highlight=pip
- http://stackoverflow.com/questions/1449494/how-do-i-install-python-packages-on-windows