Python setuptools install windows

Last Updated :
31 Jan, 2022

Setuptools is a package development process library that is designed to make packaging Python projects easier by boosting the standard distutils (distribution utilities) library of Python. 

  • It includes Python package and module definitions
  • It includes distribution package metadata
  • It includes test hooks
  • It includes project installation
  • It also includes platform-specific details
  • It supports Python3.

In this article, we will learn how to install Setuptools for Python on Windows.

Installing Setuptools on Windows 

Method 1: Using pip to install Setuptools Package

Follow the below steps to install the Setuptools package on Windows using pip:

Step 1: Install the latest or current version of Python3 in Windows.

Step 2: Now check if pip and python are correctly installed in your system using the following commands.

python –version

pip –version

Checking-python-and-pip-version-in-Windows

Step 3: Upgrade pip to the latest version to avoid errors during installation.

pip install –upgrade pip

Upgrading-pip-in-Windows

Step 4: Enter the following command in the command prompt to install Setuptools using pip.

pip install setuptools

Installing-Setuptools-package

Method 2: Using setup.py to install Setuptools

Follow the below steps to install the Setuptools on Windows using the setup.py file:

Step 1: Download the latest source package of Setuptools for Python3 from here.

curl https://files.pythonhosted.org/packages/9b/be/13f54335c7dba713b0e97e11e7a41db3df4a85073d6c5a6e7f6468b22ee2/setuptools-60.2.0.tar.gz > setuptools-60.2.0.tar.gz

Downloading-the-source-package-for-Setuptools

Step 2: Extract the downloaded package using the given command.

tar -xzvf setuptools-60.2.0.tar.gz

Extracting-the-package

Step 3: Go to the setuptools-60.2.0 folder and enter the following command to install the package.

cd setuptools-60.2.0

python setup.py install

installing Setuptools on Windows using the setup.py file

Verifying Setuptools installation on Windows

Make the following import in your Python terminal to verify if the installation of the Setuptools package has been done properly:

import setuptools 

Verifying-Setuptools-installation

If there is any error while importing the module then the Setuptools package is not installed properly.

Installation¶

You can install the latest version of setuptools using pip:

pip install --upgrade setuptools[core]

Most of the times, however, you don’t have to…

Instead, when creating new Python packages, it is recommended to use
a command line tool called build. This tool will automatically download
setuptools and any other build-time dependencies that your project might
have. You just need to specify them in a pyproject.toml file at the root of
your package, as indicated in the following section.

You can also install build using pip:

pip install --upgrade build

This will allow you to run the command: python -m build.

Important

Please note that some operating systems might be equipped with
the python3 and pip3 commands instead of python and pip
(but they should be equivalent).
If you don’t have pip or pip3 available in your system, please
check out pip installation docs.

Every 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 tool that provides a build sdist-like
functionality.

Basic Use¶

When creating a Python package, you must provide a pyproject.toml file
containing a build-system section similar to the example below:

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

This section declares what are your build system dependencies, and which
library will be used to actually do the packaging.

Note

Package maintainers might be tempted to use setuptools[core] as the
requirement, given the guidance above. Avoid doing so, as the extra
is currently considered an internal implementation detail and is likely
to go away in the future and the Setuptools team will not support
compatibility for problems arising from packages published with this
extra declared. Vendored packages will satisfy the dependencies in
the most common isolated build scenarios.

Note

Historically this documentation has unnecessarily listed wheel
in the requires list, and many projects still do that. This is
not recommended, as the backend no longer requires the wheel
package, and listing it explicitly causes it to be unnecessarily
required for source distribution builds.
You should only include wheel in requires if you need to explicitly
access it during build time (e.g. if your project needs a setup.py
script that imports wheel).

In addition to specifying a build system, you also will need to add
some package information such as metadata, contents, dependencies, etc.
This can be done in the same pyproject.toml file,
or in a separated one: setup.cfg or setup.py [1].

The following example demonstrates a minimum configuration
(which assumes the project depends on requests and
importlib-metadata to be able to run):

pyproject.toml

[project]
name = "mypackage"
version = "0.0.1"
dependencies = [
    "requests",
    'importlib-metadata; python_version<"3.10"',
]

See Configuring setuptools using pyproject.toml files for more information.

setup.cfg

[metadata]
name = mypackage
version = 0.0.1

[options]
install_requires =
    requests
    importlib-metadata; python_version<"3.10"

See Configuring setuptools using setup.cfg files for more information.

setup.py [1]

from setuptools import setup

setup(
    name='mypackage',
    version='0.0.1',
    install_requires=[
        'requests',
        'importlib-metadata; python_version<"3.10"',
    ],
)

See Keywords for more information.

Finally, you will need to organize your Python code to make it ready for
distributing into something that looks like the following
(optional files marked with #):

mypackage
├── pyproject.toml  # and/or setup.cfg/setup.py (depending on the configuration method)
|   # README.rst or README.md (a nice description of your package)
|   # LICENCE (properly chosen license information, e.g. MIT, BSD-3, GPL-3, MPL-2, etc...)
└── mypackage
    ├── __init__.py
    └── ... (other Python files)

With build installed in your system, you can then run:

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 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 the additional but essential information you need
to specify to properly package your project.

Info: Using setup.py

Setuptools offers first class support for setup.py files as a configuration
mechanism.

It is important to remember, however, that running this file as a
script (e.g. python setup.py sdist) is strongly discouraged, and
that the majority of the command line interfaces are (or will be) deprecated
(e.g. python setup.py install, python setup.py bdist_wininst, …).

We also recommend users to expose as much as possible configuration in a
more declarative way via the pyproject.toml or
setup.cfg, and keep the setup.py minimal
with only the dynamic parts (or even omit it completely if applicable).

See Why you shouldn’t invoke setup.py directly for more background.

Overview¶

Package discovery¶

For projects that follow a simple directory structure, setuptools should be
able to automatically detect all packages and
namespaces. However, complex projects might include
additional folders and supporting files that not necessarily should be
distributed (or that can confuse setuptools auto discovery algorithm).

Therefore, setuptools provides a convenient way to customize
which packages should be distributed and in which directory they should be
found, as shown in the example below:

pyproject.toml

# ...
[tool.setuptools.packages]
find = {}  # Scan the project directory with the default parameters

# OR
[tool.setuptools.packages.find]
# All the following settings are optional:
where = ["src"]  # ["."] by default
include = ["mypackage*"]  # ["*"] by default
exclude = ["mypackage.tests*"]  # empty by default
namespaces = false  # true by default

setup.cfg

[options]
packages = find: # OR `find_namespace:` if you want to use namespaces

[options.packages.find]  # (always `find` even if `find_namespace:` was used before)
# This section is optional as well as each of the following options:
where=src  # . by default
include=mypackage*  # * by default
exclude=mypackage.tests*  # empty by default

setup.py [1]

from setuptools import setup, find_packages  # or find_namespace_packages

setup(
    # ...
    packages=find_packages(
        # All keyword arguments below are optional:
        where='src',  # '.' by default
        include=['mypackage*'],  # ['*'] by default
        exclude=['mypackage.tests'],  # empty by default
    ),
    # ...
)

When you pass the above information, alongside other necessary information,
setuptools walks through the directory specified in where (defaults to .) and filters the packages
it can find following the include patterns (defaults to *), then it removes
those that match the exclude patterns (defaults to empty) and returns a list of Python packages.

For more details and advanced use, go to Package Discovery and Namespace Packages.

Tip

Starting with version 61.0.0, setuptools’ automatic discovery capabilities
have been improved to detect popular project layouts (such as the
flat-layout and src-layout) without requiring any
special configuration. Check out our reference docs
for more information.

Entry points and automatic script creation¶

Setuptools supports automatic creation of scripts upon installation, that run
code within your package if you specify them as entry points.
An example of how this feature can be used in pip:
it allows you to run commands like pip install instead of having
to type python -m pip install.

The following configuration examples show how to accomplish this:

pyproject.toml

[project.scripts]
cli-name = "mypkg.mymodule:some_func"

setup.cfg

[options.entry_points]
console_scripts =
    cli-name = mypkg.mymodule:some_func

setup.py [1]

setup(
    # ...
    entry_points={
        'console_scripts': [
            'cli-name = mypkg.mymodule:some_func',
        ]
    }
)

When this project is installed, a cli-name executable will be created.
cli-name will invoke the function some_func in the
mypkg/mymodule.py file when called by the user.
Note that you can also use the entry-points mechanism to advertise
components between installed packages and implement plugin systems.
For detailed usage, go to Entry Points.

Dependency management¶

Packages built with setuptools can specify dependencies to be automatically
installed when the package itself is installed.
The example below shows how to configure this kind of dependencies:

pyproject.toml

[project]
# ...
dependencies = [
    "docutils",
    "requests <= 0.4",
]
# ...

setup.cfg

[options]
install_requires =
    docutils
    requests <= 0.4

setup.py [1]

setup(
    # ...
    install_requires=["docutils", "requests <= 0.4"],
    # ...
)

Each dependency is represented by a string that can optionally contain version requirements
(e.g. one of the operators <, >, <=, >=, == or !=, followed by a version identifier),
and/or conditional environment markers, e.g. sys_platform == "win32"
(see Version specifiers for more information).

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 scenario. You can also specify groups of
extra dependencies that are not strictly required by your package to work, but
that will provide additional functionalities.
For more advanced use, see Dependencies Management in Setuptools.

Including Data Files¶

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:

pyproject.toml

[tool.setuptools]
include-package-data = true
# This is already the default behaviour if you are using
# pyproject.toml to configure your build.
# You can deactivate that with `include-package-data = false`

setup.cfg

[options]
include_package_data = True

setup.py [1]

setup(
    # ...
    include_package_data=True,
    # ...
)

This tells setuptools to install any data files it finds in your packages.
The data files must be specified via the MANIFEST.in
file or automatically added by a Revision Control System plugin.
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.
Here’s how to do it:

See Development Mode (a.k.a. “Editable Installs”) for more information.

Tip

Prior to pip v21.1, a setup.py script was
required to be compatible with development mode. With late
versions of pip, projects without setup.py may be installed in this mode.

If you have a version of pip older than v21.1 or is using a different
packaging-related tool that does not support PEP 660, you might need to keep a
setup.py file in your repository if you want to use editable
installs.

A simple script will suffice, for example:

from setuptools import setup

setup()

You can still keep all the configuration in
pyproject.toml and/or
setup.cfg

Note

When building from source code (for example, by python -m build
or pip install -e .)
some directories hosting build artefacts and cache files may be
created, such as build, dist, *.egg-info [2].
You can configure your version control system to ignore them
(see GitHub’s .gitignore template
for an example).

Uploading your package to PyPI¶

After generating the distribution files, the next step would be to upload your
distribution so others can use it. This functionality is provided by
twine and is documented in the Python packaging tutorial.

Transitioning from setup.py to declarative config¶

To avoid executing arbitrary scripts and boilerplate code, we are transitioning
from defining all your package information by running setup() to doing this
declaratively — by using pyproject.toml (or older setup.cfg).

To ease the challenges of transitioning, we provide a quick
guide to understanding how pyproject.toml
is parsed by setuptools. (Alternatively, here is the
guide for setup.cfg).

Note

The approach setuptools would like to take is to eventually use a single
declarative format (pyproject.toml) instead of maintaining 2
(pyproject.toml / setup.cfg). Yet, chances are, setup.cfg will
continue to be maintained for a long time.

Resources on Python packaging¶

Packaging in Python can be hard and is constantly evolving.
Python Packaging User Guide has tutorials and
up-to-date references that can help you when it is time to distribute your work.


Notes

Project description

See the Quickstart
and the User’s Guide for
instructions on how to use Setuptools.

Questions and comments should be directed to GitHub Discussions.
Bug reports and especially tested patches may be
submitted directly to the bug tracker.

Code of Conduct

Everyone interacting in the setuptools project’s codebases, issue trackers,
chat rooms, and fora is expected to follow the
PSF Code of Conduct.

For Enterprise

Available as part of the Tidelift Subscription.

Setuptools and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

Learn more.

Download files

Download the file for your platform. If you’re not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file setuptools-80.3.1.tar.gz.

File metadata

  • Download URL:
    setuptools-80.3.1.tar.gz

  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for setuptools-80.3.1.tar.gz

Algorithm Hash digest
SHA256 31e2c58dbb67c99c289f51c16d899afedae292b978f8051efaf6262d8212f927
MD5 def5e5a92579663416097d8b22bb539d
BLAKE2b-256 70dc3976b322de9d2e87ed0007cf04cc7553969b6c7b3f48a565d0333748fbcd

See more details on using hashes here.

File details

Details for the file setuptools-80.3.1-py3-none-any.whl.

File metadata

  • Download URL:
    setuptools-80.3.1-py3-none-any.whl

  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for setuptools-80.3.1-py3-none-any.whl

Algorithm Hash digest
SHA256 ea8e00d7992054c4c592aeb892f6ad51fe1b4d90cc6947cc45c45717c40ec537
MD5 b7333fedac1d02e63d51fab59e41acb8
BLAKE2b-256 537e5d8af3317ddbf9519b687bd1c39d8737fde07d97f54df65553faca5cffb1

See more details on using hashes here.

Python is a versatile and powerful programming language that is widely used for various purposes, including web development, data analysis, and automation. To enhance the functionality of Python, there are numerous third-party libraries and packages available. One such essential package is SetupTools, which provides a convenient way to distribute, install, and manage Python packages.

What is SetupTools?

SetupTools is a collection of utilities and extensions for Python’s distutils, a module that facilitates the packaging and distribution of Python projects. It simplifies the process of installing, upgrading, and uninstalling Python packages, making it easier for developers to manage dependencies and ensure compatibility across different environments.

SetupTools also provides a command-line interface (CLI) tool called easy_install, which automates the process of fetching and installing packages from the Python Package Index (PyPI) or other sources. This tool resolves dependencies, downloads the required packages, and installs them in the appropriate location.

Installing SetupTools on 64-bit Windows

To install SetupTools on a 64-bit Windows system using Python 3, follow these steps:

1. Open a web browser and navigate to the official Python website (https://www.python.org).
2. Download the latest version of Python 3.x for Windows (64-bit) from the Downloads section.
3. Run the downloaded installer and follow the on-screen instructions to install Python on your system.
4. Open the command prompt by pressing the Windows key + R, typing "cmd," and pressing Enter.
5. In the command prompt, type "python" and press Enter to start the Python interpreter.
6. Once in the Python interpreter, type the following command to install SetupTools:

   python -m ensurepip --upgrade

7. After ensuring pip is up to date, install SetupTools by running the following command:

   python -m pip install setuptools

8. Wait for the installation to complete. You should see output indicating the successful installation of SetupTools.
9. Verify the installation by typing the following command:

   python -m easy_install --version

   If the version number is displayed, SetupTools has been successfully installed on your system.

Using SetupTools

Once SetupTools is installed, you can start using it to manage Python packages. The most common use case is installing packages from the Python Package Index (PyPI). To install a package, open the command prompt and use the following command:

python -m pip install package_name

Replace “package_name” with the name of the package you want to install. SetupTools will automatically download the package and its dependencies, if any, and install them in the appropriate location.

You can also use SetupTools to upgrade or uninstall packages. To upgrade a package, use the following command:

python -m pip install --upgrade package_name

To uninstall a package, use the following command:

python -m pip uninstall package_name

Installing SetupTools on 64-bit Windows using Python 3 is a straightforward process that allows developers to easily manage Python packages and their dependencies. By following the steps outlined in this article, you can ensure that SetupTools is correctly installed on your system and start leveraging its capabilities to enhance your Python development workflow.

Example 1: Installing SetupTools on 64-bit Windows using Python 3

To install SetupTools on a 64-bit Windows machine using Python 3, you can follow these steps:

# Step 1: Download the SetupTools package from the official Python website
# Go to https://pypi.org/project/setuptools/#files and download the latest version of SetupTools for Windows.

# Step 2: Open a command prompt
# Open the command prompt by pressing Windows key + R, typing "cmd", and pressing Enter.

# Step 3: Navigate to the directory where the downloaded SetupTools package is located
# Use the "cd" command to navigate to the directory where the downloaded SetupTools package is located.
# For example, if the package is in the Downloads folder, type "cd Downloads" and press Enter.

# Step 4: Install SetupTools using the Python package installer (pip)
# Type "pip install .whl" and press Enter.
# Replace  with the actual name of the downloaded SetupTools package.
# For example, if the downloaded package is "setuptools-58.0.4-py3-none-any.whl", type "pip install setuptools-58.0.4-py3-none-any.whl" and press Enter.

# Step 5: Verify the installation
# Type "pip show setuptools" and press Enter.
# If the installation was successful, you should see information about the installed version of SetupTools.

# Step 6: Test SetupTools
# Open a Python interpreter by typing "python" in the command prompt and pressing Enter.
# Type "import setuptools" and press Enter.
# If no error is displayed, SetupTools has been successfully installed on your 64-bit Windows machine using Python 3.

Reference Links:

  • SetupTools on PyPI
  • Installing Python Packages with pip

Conclusion:

Installing SetupTools on a 64-bit Windows machine using Python 3 is a straightforward process. By following the steps outlined above, you can easily download and install SetupTools using the Python package installer (pip). Once installed, you can verify the installation and test SetupTools by importing it in a Python interpreter. SetupTools is a useful tool for managing and distributing Python packages, and its installation allows you to take advantage of its features and functionalities in your Python projects.

pip install setuptools

The Python setuptools library is among the top 100 Python libraries, with more than 103,209,780 downloads. This article will show you everything you need to get this installed in your Python environment.

  • Library Link
  1. Type "cmd" in the search bar and hit Enter to open the command line.
  2. Type “pip install setuptools” (without quotes) in the command line and hit Enter again. This installs setuptools for your default Python installation.
  3. The previous command may not work if you have both Python versions 2 and 3 on your computer. In this case, try "pip3 install setuptools" or “python -m pip install setuptools“.
  4. Wait for the installation to terminate successfully. It is now installed on your Windows machine.

Here’s how to open the command line on a (German) Windows machine:

Open CMD in Windows

First, try the following command to install setuptools on your system:

pip install setuptools

Second, if this leads to an error message, try this command to install setuptools on your system:

pip3 install setuptools

Third, if both do not work, use the following long-form command:

python -m pip install setuptools

The difference between pip and pip3 is that pip3 is an updated version of pip for Python version 3. Depending on what’s first in the PATH variable, pip will refer to your Python 2 or Python 3 installation—and you cannot know which without checking the environment variables. To resolve this uncertainty, you can use pip3, which will always refer to your default Python 3 installation.

How to Install setuptools on Linux?

You can install setuptools on Linux in four steps:

  1. Open your Linux terminal or shell
  2. Type “pip install setuptools” (without quotes), hit Enter.
  3. If it doesn’t work, try "pip3 install setuptools" or “python -m pip install setuptools“.
  4. Wait for the installation to terminate successfully.

The package is now installed on your Linux operating system.

How to Install setuptools on macOS?

Similarly, you can install setuptools on macOS in four steps:

  1. Open your macOS terminal.
  2. Type “pip install setuptools” without quotes and hit Enter.
  3. If it doesn’t work, try "pip3 install setuptools" or “python -m pip install setuptools“.
  4. Wait for the installation to terminate successfully.

The package is now installed on your macOS.

How to Install setuptools in PyCharm?

Given a PyCharm project. How to install the setuptools library in your project within a virtual environment or globally? Here’s a solution that always works:

  • Open File > Settings > Project from the PyCharm menu.
  • Select your current project.
  • Click the Python Interpreter tab within your project tab.
  • Click the small + symbol to add a new library to the project.
  • Now type in the library to be installed, in your example "setuptools" without quotes, and click Install Package.
  • Wait for the installation to terminate and close all pop-ups.

Here’s the general package installation process as a short animated video—it works analogously for setuptools if you type in “setuptools” in the search field instead:

Make sure to select only “setuptools” because there may be other packages that are not required but also contain the same term (false positives):

How to Install setuptools in a Jupyter Notebook?

To install any package in a Jupyter notebook, you can prefix the !pip install my_package statement with the exclamation mark "!". This works for the setuptools library too:

!pip install my_package

This automatically installs the setuptools library when the cell is first executed.

How to Resolve ModuleNotFoundError: No module named ‘setuptools’?

Say you try to import the setuptools package into your Python script without installing it first:

import setuptools
# ... ModuleNotFoundError: No module named 'setuptools'

Because you haven’t installed the package, Python raises a ModuleNotFoundError: No module named 'setuptools'.

To fix the error, install the setuptools library using “pip install setuptools” or “pip3 install setuptools” in your operating system’s shell or terminal first.

See above for the different ways to install setuptools in your environment.

Improve Your Python Skills

If you want to keep improving your Python skills and learn about new and exciting technologies such as Blockchain development, machine learning, and data science, check out the Finxter free email academy with cheat sheets, regular tutorials, and programming puzzles.

Join us, it’s fun! 🙂

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как настроить точку доступа wifi на компьютере windows 7
  • Windows сервер для чего нужна
  • Как сделать так чтобы в названии файла отображался его формат windows 10
  • Файл слишком велик для конечной файловой системы что делать windows 10
  • Windows 10 by den torrent