- Installing pip/setuptools/wheel with Linux Package Managers¶
- Fedora¶
- CentOS/RHEL¶
- linux-notes.org
- Установка pip/setuptools/wheel в Unix/Linux
- Установка pip/setuptools/wheel в Fedora
- Установка pip/setuptools/wheel в CentOS/RHEL
- Установка pip/setuptools/wheel в openSUSE
- Установка pip/setuptools/wheel в Debian/Ubuntu
- Установка pip/setuptools/wheel в Arch Linux
- Установка pip/setuptools/wheel в Mac OS X
- Установка pip/setuptools/wheel с исходного кода.
- Установка pip/wheel с исходного кода
- Установка setuptools с исходного кода
- Установка easy_install с исходного кода
- Использование PIP
- Добавить комментарий Отменить ответ
- setuptools Quickstart¶
- Installation¶
- Python packaging at a glance¶
- Basic Use¶
- Automatic package discovery¶
- Entry points and automatic script creation¶
- Dependency management¶
- Including Data Files¶
- Development mode¶
- Uploading your package to PyPI¶
- Transitioning from setup.py to setup.cfg ¶
- Resources on Python packaging¶
- Installing Packages¶
- Requirements for Installing Packages¶
- Ensure you can run Python from the command line¶
- Ensure you can run pip from the command line¶
- Ensure pip, setuptools, and wheel are up to date¶
- Optionally, create a virtual environment¶
- Creating Virtual Environments¶
Installing pip/setuptools/wheel with Linux Package Managers¶
This section covers how to install pip , setuptools , and wheel using Linux package managers.
If you’re using a Python that was downloaded from python.org, then this section does not apply. See the Requirements for Installing Packages section instead.
Note that it’s common for the versions of pip , setuptools , and wheel supported by a specific Linux Distribution to be outdated by the time it’s released to the public, and updates generally only occur for security reasons, not for feature updates. For certain Distributions, there are additional repositories that can be enabled to provide newer versions. The repositories we know about are explained below.
Also note that it’s somewhat common for Distributions to apply patches for the sake of security and normalization to their own standards. In some cases, this can lead to bugs or unexpected behaviors that vary from the original unpatched versions. When this is known, we will make note of it below.
Fedora¶
To learn more about Python in Fedora, please visit the official Fedora docs, Python Classroom or Fedora Loves Python.
CentOS/RHEL¶
CentOS and RHEL don’t offer pip or wheel in their core repositories, although setuptools is installed by default.
To install pip and wheel for the system Python, there are two options:
Enable the EPEL repository using these instructions. On EPEL 7, you can install pip and wheel like so:
Since EPEL only offers extra, non-conflicting packages, EPEL does not offer setuptools, since it’s in the core repository.
Enable the PyPA Copr Repo using these instructions 1. You can install pip and wheel like so:
To additionally upgrade setuptools, run:
To install pip, wheel, and setuptools, in a parallel, non-system environment (using yum) then there are two options:
Use the “Software Collections” feature to enable a parallel collection that includes pip, setuptools, and wheel.
Be aware that collections may not contain the most recent versions.
Enable the IUS repository and install one of the parallel-installable Pythons, along with pip, setuptools, and wheel, which are kept fairly up to date.
For example, for Python 3.4 on CentOS7/RHEL7:
Источник
linux-notes.org
В этой статье «Установка pip/setuptools/wheel в Unix/Linux» описывается, как установить pip, setuptools и wheel в Unix/Linux ОС.
Установка pip/setuptools/wheel в Unix/Linux
Приведу установку на различные Unix/Linux ОС.
Установка pip/setuptools/wheel в Fedora
Чтобы установить Python 2 на Fedora 21, используйте следующие команды.
Для начала обновим тулзы:
Чтобы установить Python 3 на Fedora 21, используйте следующие команды:
Чтобы установить Python 2 на Fedora 22, используйте следующие команды.
Для начала обновим тулзы:
Чтобы установить Python 3 на Fedora 22, используйте следующие команды:
Чтобы получить новые версии pip, setuptools и wheel для Python 2, вы можете включить PyPA Copr репозиторий:
И после чего, выполнить:
Установка pip/setuptools/wheel в CentOS/RHEL
Чтобы установить pip и wheel, существует два варианта:
1. Включите репозиторий EPEL, используя эти инструкции:
После чего, вы можете установить pip следующим образом:
На EPEL 7 (но не EPEL 6), вы можете установить wheel следующим образом:
2. Включите репозиторий PyPA Copr репозиторий:
После чего, вы можете установить pip следующим образом:
Чтобы обновить setuptools, запустите:
Чтобы установить Python 3.4 на CentOS7/RHEL7, используйте:
Установка pip/setuptools/wheel в openSUSE
Чтобы установить Python 2:
Чтобы установить Python 3:
Установка pip/setuptools/wheel в Debian/Ubuntu
Чтобы установить Python:
Чтобы установить Python 3:
Установка pip/setuptools/wheel в Arch Linux
Чтобы установить Python 2:
Чтобы установить Python 3:
Установка pip/setuptools/wheel в Mac OS X
Добавляем HOMEBREW на Mac OS X ( устанавливаем его):
После чего, можно приступать к установке:
Или, чтобы установить python 3:
Установка pip/setuptools/wheel с исходного кода.
И, чтобы получить самое новое ПО, НЕОБХОДИМО КОМПИЛИРОВАТЬ ЕГО!
Установка pip/wheel с исходного кода
Очень простая установка:
Установка setuptools с исходного кода
Смотрим где лежит нужный питон (у меня это 3.4):
И выполняем сборку:
ИЛИ, все в одной строке:
Установка easy_install с исходного кода
easy_install позволяет установить pip и его компоненты.
Смотрим где лежит нужный питон (у меня это 3.4):
И выполняем сборку:
Использование PIP
Поиск пакета Python с помощью команды pip:
Установка пакета с помощью команды pip:
- Установка по имени пакета:
- Установка по имени пакета (но, определенной версии):
- Установка пакета по URL:
Список пакетов Python, которые уже установлены в системе, можно проверить с помощью команды pip:
Показать информацию о пакете Python:
Вот полезное чтиво:
А на этом, у меня все. Тема «Установка pip/setuptools/wheel в Unix/Linux» завершена.
Добавить комментарий Отменить ответ
Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.
Источник
setuptools Quickstart¶
Installation¶
To install the latest version of setuptools, use:
Python packaging at a glance¶
The landscape of Python packaging is shifting and Setuptools has evolved to only provide backend support, no longer being the de-facto packaging tool in the market. All python package must provide a pyproject.toml and specify the backend (build system) it wants to use. The distribution can then be generated with whatever tools that provides a build sdist -alike functionality. While this may appear cumbersome, given the added pieces, it in fact tremendously enhances the portability of your package. The change is driven under PEP 517. To learn more about Python packaging in general, navigate to the bottom of this page.
Basic Use¶
For basic use of setuptools, you will need a pyproject.toml with the exact following info, which declares you want to use setuptools to package your project:
Then, you will need a setup.cfg or setup.py to specify your package information, such as metadata, contents, dependencies, etc. Here we demonstrate the minimum
This is what your project would look like:
Then, you need an builder, such as PyPA build which you can obtain via pip install build . After downloading it, invoke the builder:
You now have your distribution ready (e.g. a tar.gz file and a .whl file in the dist directory), which you can upload to PyPI!
Of course, before you release your project to PyPI, you’ll want to add a bit more information to your setup script to help people find or learn about your project. And maybe your project will have grown by then to include a few dependencies, and perhaps some data files and scripts. In the next few sections, we will walk through those additional but essential information you need to specify to properly package your project.
Automatic package discovery¶
For simple projects, it’s usually easy enough to manually add packages to the packages keyword in setup.cfg . However, for very large projects , it can be a big burden to keep the package list updated. setuptools therefore provides two convenient tools to ease the burden: find: and find_namespace: . To use it in your project:
When you pass the above information, alongside other necessary ones, setuptools walks through the directory specified in where (omitted here as the package reside in current directory) and filters the packages it can find following the include (default to none), then remove those that match the exclude and return a list of Python packages. Note that each entry in the [options.packages.find] is optional. The above setup also allows you to adopt a src/ layout. For more details and advanced use, go to Package Discovery and Namespace Package
Entry points and automatic script creation¶
Setuptools support automatic creation of scripts upon installation, that runs code within your package if you specify them with the entry_points keyword. This is what allows you to run commands like pip install instead of having to type python -m pip install . To accomplish this, add the entry_points keyword in your setup.cfg :
When this project is installed, a main script will be installed and will invoke the some_func in the __init__.py file when called by the user. For detailed usage, including managing the additional or optional dependencies, go to Entry Points .
Dependency management¶
setuptools supports automatically installing dependencies when a package is installed. The simplest way to include requirement specifiers is to use the install_requires argument to setup.cfg . It takes a string or list of strings containing requirement specifiers (A version specifier is one of the operators , =, == or !=, followed by a version identifier):
When your project is installed, all of the dependencies not already installed will be located (via PyPI), downloaded, built (if necessary), and installed. This, of course, is a simplified scenarios. setuptools also provide additional keywords such as setup_requires that allows you to install dependencies before running the script, and extras_requires that take care of those needed by automatically generated scripts. It also provides mechanisms to handle dependencies that are not in PyPI. For more advanced use, see Dependencies Management in Setuptools
Including Data Files¶
The distutils have traditionally allowed installation of “data files”, which are placed in a platform-specific location. Setuptools offers three ways to specify data files to be included in your packages. For the simplest use, you can simply use the include_package_data keyword:
This tells setuptools to install any data files it finds in your packages. The data files must be specified via the distutils’ MANIFEST.in file. For more details, see Data Files Support
Development mode¶
setuptools allows you to install a package without copying any files to your interpreter directory (e.g. the site-packages directory). This allows you to modify your source code and have the changes take effect without you having to rebuild and reinstall. This is currently incompatible with PEP 517 and therefore it requires a setup.py script with the following content:
This creates a link file in your interpreter site package directory which associate with your source code. For more information, see “Development Mode” .
Uploading your package to PyPI¶
After generating the distribution files, next step would be to upload your distribution so others can use it. This functionality is provided by twine and we will only demonstrate the basic use here.
Transitioning from setup.py to setup.cfg ¶
To avoid executing arbitrary scripts and boilerplate code, we are transitioning into a full-fledged setup.cfg to declare your package information instead of running setup() . This inevitably brings challenges due to a different syntax. Here we provide a quick guide to understanding how setup.cfg is parsed by setuptool to ease the pain of transition.
Resources on Python packaging¶
Packaging in Python is hard. Here we provide a list of links for those that want to learn more.
Источник
Installing Packages¶
This section covers the basics of how to install Python 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:
You should get some output like Python 3.6.3 . If you do not have Python, please install the latest 3.x version from python.org or refer to the Installing Python 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.
If you’re using an enhanced shell like IPython or the Jupyter notebook, you can run system commands like those in this tutorial by prefacing them with a ! character:
It’s recommended to write
Due to the way most Linux distributions are handling the Python 3 migration, Linux users using the system Python without creating a virtual environment first should replace the python command in this tutorial with python3 and the python -m pip command with python3 -m pip —user . Do not run any of the commands in this tutorial with sudo : if you get a permissions error, come back to the section on creating virtual environments, set one up, and then continue with the tutorial as written.
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 you installed Python from source, with an installer from python.org, or via Homebrew you should already have pip. If you’re on Linux and installed using your OS package manager, you may have to install pip separately, see Installing pip/setuptools/wheel with Linux Package Managers .
If pip isn’t already installed, then first try to bootstrap it from the standard library:
If that still doesn’t allow you to run python -m pip :
Run python get-pip.py . 2 This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already.
Be cautious if you’re using a Python install that’s managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. You can use python get-pip.py —prefix=/usr/local/ to install in /usr/local which is designed for locally-installed software.
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¶
Python “Virtual Environments” allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally. If you are looking to safely install global command line tools, see Installing stand alone command line tools .
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.
virtualenv needs to be installed separately, but supports Python 2.7+ and Python 3.3+, and pip , setuptools and wheel are always installed into created virtual environments by default (regardless of Python version).
Источник