<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>migrating Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/migrating/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/migrating/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Thu, 30 Oct 2025 06:55:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Distributing your own package on PyPi</title>
		<link>https://creatronix.de/distributing-your-own-package-on-pypi/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 01 Nov 2018 18:40:25 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[bdsit]]></category>
		<category><![CDATA[distutils]]></category>
		<category><![CDATA[migrating]]></category>
		<category><![CDATA[pypi]]></category>
		<category><![CDATA[sdist]]></category>
		<category><![CDATA[setuptools]]></category>
		<category><![CDATA[twine]]></category>
		<category><![CDATA[wheel]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1473</guid>

					<description><![CDATA[<p>In Regular Expressions Demystified I developed a little python package and distributed it via PyPi. I wanted to publish my second self-written package as well, but coming back after almost a year, some things have changed in the world of PyPi, i.e. the old tutorials aren&#8217;t working anymore. So I wrote this article to bring&#8230;</p>
<p>The post <a href="https://creatronix.de/distributing-your-own-package-on-pypi/">Distributing your own package on PyPi</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://creatronix.de/regular-expressions-demystified/">Regular Expressions Demystified</a> I developed a little python package and distributed it via <a href="https://pypi.org/">PyPi.</a></p>
<p>I wanted to publish my second self-written package as well, but coming back after almost a year, some things have changed in the world of PyPi, i.e. the old tutorials aren&#8217;t working anymore.</p>
<p>So I wrote this article to bring some clarity into this topic.</p>
<h2>Distutils vs Setuptools</h2>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2303" src="https://creatronix.de/wp-content/uploads/2018/04/distutils_vs_setuptools.jpg" alt="" width="500" height="756" srcset="https://creatronix.de/wp-content/uploads/2018/04/distutils_vs_setuptools.jpg 500w, https://creatronix.de/wp-content/uploads/2018/04/distutils_vs_setuptools-198x300.jpg 198w" sizes="(max-width: 500px) 100vw, 500px" /></p>
<h3>Distutils</h3>
<p>Distutils is still the standard tool for packaging in Python. It comes pre-installed with Python2 and Python3. Although it is still &#8216;standard&#8217; it has some disadvantages tbc</p>
<p>for the case you stumble upon Distutils2: It was an attempt to combine the best from distutils and setuptools.</p>
<p>tl;dr; development of distutils2 has stopped, <strong>you shouldn&#8217;t use it!</strong></p>
<h3>Setuptools</h3>
<p>As far as I can see <a href="https://pypi.org/project/setuptools/">setuptools</a> is becoming the new de facto standard for packaging Python projects.</p>
<h3>Wheel</h3>
<p>A <a href="https://pypi.org/project/wheel/">wheel</a> is a</p>
<ol>
<li>setuptools extension for building wheels that provides the <tt>bdist_wheel</tt> setuptools command</li>
<li>A command line tool for working with wheel files</li>
</ol>
<p id="advantages">The Advantages of wheels</p>
<ul>
<li>Faster installation for pure Python and native C extension packages.</li>
<li>Avoids arbitrary code execution for installation. (Avoids setup.py)</li>
<li>Installation of a C extension does not require a compiler on Linux, Windows or macOS.</li>
<li>Allows better caching for testing and continuous integration.</li>
<li>Creates .pyc files as part of installation to ensure they match the Python interpreter used.</li>
<li>More consistent installs across platforms and machines.</li>
</ul>
<h3>Twine</h3>
<p><a href="https://pypi.org/project/twine/">Twine</a> is a library / tool for publishing Python packages on PyPI.</p>
<p>You should favor using twine over <code>python setup.py upload</code> for the following reasons:</p>
<ul>
<li>Verified HTTPS connections</li>
<li>Uploading doesn’t require executing <tt>setup.py</tt></li>
<li>Uploading files that have already been created, allowing testing of distributions before release</li>
<li>Supports uploading any packaging format (including wheels)</li>
</ul>
<p><strong>For the next steps we are using all three &#8211; setuptools, wheel and twine.</strong></p>
<h2>Setup a project for packaging</h2>
<p>Depending if your using pip or pipenv you have to either</p>
<pre>pip install setuptools wheel twine</pre>
<p>or</p>
<pre>pipenv install setuptools wheel twine</pre>
<p>The most basic project setup for a distribution looks like this:</p>
<pre>/example_pkg
  /example_pkg
    __init__.py
    main.py
  setup.py</pre>
<p>The setup.py contains the following lines:</p>
<pre>import setuptools

setuptools.setup(
    name='example_pkg',
    version='0.0.1',
    packages=['example_pkg'],
    author='Joern Boegeholz',
    author_email='boegeholz.joern@gmail.com',
    description='An example Package',
)</pre>
<h2>Source Distribution</h2>
<p>Having created the above setup, you can now build a distribution with the following command:</p>
<pre>python setup.py sdist
</pre>
<p>Your project folder will now look like this:</p>
<pre>/example_pkg 
  /dist
    example_pkg-0.0.1.tar.gz
  /example_pkg 
    __init__.py 
    main.py 
  setup.py</pre>
<p>This command will create a example_pkg-0.0.1.tar.gz in a dist folder file which contains the source code of your package hence source distribution or sdist.</p>
<p>You can now distribute your package as a zip file. A user can download and unpack it.</p>
<p>With</p>
<pre><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">install</span></pre>
<p>from inside the package folder, it will be installed into your Python site-packages.</p>
<h2>Built Distribution with Wheel</h2>
<p>With</p>
<pre>python setup.py bdist_wheel</pre>
<p>you can create a wheel.</p>
<p>Your dist folder now contains a  example_pkg-0.0.1-py3-none-any.whl</p>
<p>That&#8217;s a funny filename <strong>py3-none-any.whl</strong>,  so let&#8217;s decompose it:</p>
<ul>
<li>py3 -&gt; meant for usage with Python 3</li>
<li>none -&gt; not OS-specific</li>
<li>any -&gt; suitable to run on any processor architecture</li>
</ul>
<p>If your package doesn&#8217;t contain any C extension and is compatible with Python2 as well, you can add a setup.cfg file to your project folder and insert these lines:</p>
<pre>[bdist_wheel]
universal = 1</pre>
<p>After running <code>python setup.py bdist_wheel</code> again the file</p>
<p>example_pkg-0.0.1-py2.py3-none-any.whl is created.</p>
<p>It is recommended to always create both: sdist and bdist_wheel</p>
<h2>Uploading to PyPi</h2>
<pre>twine upload dist/*</pre>
<p>The complete guide can be found <a href="https://packaging.python.org/tutorials/distributing-packages/#source-distributions">here.</a></p>
<h2>Migrating from distutils to setuptools</h2>
<p>If You are using distutils and want to migrate here is the workflow in a nutshell:</p>
<h3>Step 1 &#8211; Install requirements</h3>
<pre>pip install setuptools wheel twine</pre>
<h3>Step 2 &#8211; Change setup.py</h3>
<p>Instead of</p>
<pre>from distutils.core import setup
setup(...)</pre>
<p>write</p>
<pre>import setuptools
setuptools.setup(...)</pre>
<h3>Step 3 &#8211; Adding / updating setup.cfg</h3>
<pre>[bdist_wheel]
universal = 1</pre>
<h2>Dependencies</h2>
<p>If your package requires other packages to work, you have to add the requirements to the setup.py as well:</p>
<pre>setup(
...
    install_requires=[
        'pip',
        'pipdeptree'
    ],
...)</pre>
<h2>Further readings</h2>
<p><a href="https://creatronix.de/distributing-your-python-package-part2/">Distributing your own package on PyPi &#8211; Part 2</a></p>
<p>https://python-packaging.readthedocs.io/en/latest/index.html</p>
<p>https://setuptools.readthedocs.io/en/latest/setuptools.html</p>
<p>The post <a href="https://creatronix.de/distributing-your-own-package-on-pypi/">Distributing your own package on PyPi</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
