<?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>pip Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/pip/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/pip/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Tue, 23 Dec 2025 07:36:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>Python Pipfile and pipenv</title>
		<link>https://creatronix.de/python-pipfile-and-pipenv/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Mon, 30 Jul 2018 08:31:58 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[lock file]]></category>
		<category><![CDATA[pip]]></category>
		<category><![CDATA[pipenv]]></category>
		<category><![CDATA[pipfile]]></category>
		<category><![CDATA[pycharm]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1827</guid>

					<description><![CDATA[<p>&#160; If You already read Python pip and virtualenv you are familiar with the way python handles requirements. but lo and behoild there is a new kid in town or actually two new kids on the block: Pipfile and Pipenv &#8211; both with with a capital &#8220;P&#8221;. If you are tired of creating and maintaining&#8230;</p>
<p>The post <a href="https://creatronix.de/python-pipfile-and-pipenv/">Python Pipfile and pipenv</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<p>If You already read <a href="https://creatronix.de/python-pip-and-virtualenv/">Python pip and virtualenv</a> you are familiar with the way python handles requirements. but lo and behoild there is a new kid in town or actually two new kids on the block: Pipfile and Pipenv &#8211; both with with a capital &#8220;P&#8221;.</p>
<p>If you are tired of creating and maintaining your virtual envrionments, requirements.txt and requirements_to_freeze.txts: Enter Pipenv!</p>
<h2>Prerequisites</h2>
<p>To install Pipenv you have to have</p>
<ul>
<li>Python 3.2 or greater installed and in your path. Check on your command line / shell:</li>
</ul>
<pre>$ python --version</pre>
<ul>
<li>pip installed</li>
</ul>
<pre>$ pip --version</pre>
<h2>Installation</h2>
<p>Now you can use pip to install Pipenv:</p>
<pre>$ pip install pipenv</pre>
<h2>Using Pipenv</h2>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1844" src="https://creatronix.de/wp-content/uploads/2018/07/too_damn_high.jpg" alt="" width="420" height="316" srcset="https://creatronix.de/wp-content/uploads/2018/07/too_damn_high.jpg 420w, https://creatronix.de/wp-content/uploads/2018/07/too_damn_high-300x226.jpg 300w" sizes="(max-width: 420px) 100vw, 420px" /></p>
<pre>$ pipenv install flask</pre>
<p>If You run this command it will do four things:</p>
<ul>
<li>create a virtual environment</li>
<li>create a Pipfile</li>
<li>create a Pipfile.lock</li>
<li>install the flask package into the virtual environment</li>
</ul>
<h2>The Pipfile</h2>
<p>Pipfile is the replacement for the requirements.txt. It only contains the high level dependencies.</p>
<pre>[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"

[dev-packages]

[requires]
python_version = "3.6"</pre>
<h3>Versions</h3>
<p>Under the section packages you can specify minimal, maximal or exact versions of a dependency.  The syntax looks a bit odd when you are used to pip&#8217;s / requirements.txt cleaner syntax e.g. <code>responder==2.3.4</code> but hey: roll with the punches 🙂</p>
<pre>[packages]
responder = "==0.1.0"  # exactly 0.1.0
responder = "&gt;0.1.0"   # newer -&gt; 0.1.4 as I'm writing this
responder = "&lt;0.1.0"   # released before 0.1.0 -&gt; 0.0.10</pre>
<h2>Pipfile.lock</h2>
<p><img decoding="async" class="alignnone size-full wp-image-1842" src="https://creatronix.de/wp-content/uploads/2018/07/not_simply.jpg" alt="" width="568" height="335" srcset="https://creatronix.de/wp-content/uploads/2018/07/not_simply.jpg 568w, https://creatronix.de/wp-content/uploads/2018/07/not_simply-300x177.jpg 300w" sizes="(max-width: 568px) 100vw, 568px" /></p>
<p>In the lockfile you can see all sub-dependencies of the flask package</p>
<pre>{
    "_meta": {
        "hash": {
            "sha256": "8ec50e78e90ad609e540d41d1ed90f3fb880ffbdf6049b0a6b2f1a00158a3288"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.6"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "click": {
            "hashes": [
                "sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d",
                "sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b"
            ],
            "version": "==6.7"
        },
        "flask": {
            "hashes": [
                "sha256:2271c0070dbcb5275fad4a82e29f23ab92682dc45f9dfbc22c02ba9b9322ce48",
                "sha256:a080b744b7e345ccfcbc77954861cb05b3c63786e93f2b3875e0913d44b43f05"
            ],
            "index": "pypi",
            "version": "==1.0.2"
        },
        "itsdangerous": {
            "hashes": [
                "sha256:cbb3fcf8d3e33df861709ecaf89d9e6629cff0a217bc2848f1b41cd30d360519"
            ],
            "version": "==0.24"
        },
        "jinja2": {
            "hashes": [
                "sha256:74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd",
                "sha256:f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4"
            ],
            "version": "==2.10"
        },
        "markupsafe": {
            "hashes": [
                "sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665"
            ],
            "version": "==1.0"
        },
        "werkzeug": {
            "hashes": [
                "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c",
                "sha256:d5da73735293558eb1651ee2fddc4d0dedcfa06538b8813a2e20011583c9e49b"
            ],
            "version": "==0.14.1"
        }
    },
    "develop": {}
}</pre>
<h2>Activate the virtual environment</h2>
<p><img decoding="async" class="alignnone size-full wp-image-1843" src="https://creatronix.de/wp-content/uploads/2018/07/only_one.jpg" alt="" width="500" height="348" srcset="https://creatronix.de/wp-content/uploads/2018/07/only_one.jpg 500w, https://creatronix.de/wp-content/uploads/2018/07/only_one-300x209.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></p>
<pre>$ pipenv shell</pre>
<p>activates the virtual environment</p>
<h2>Installing additional packages</h2>
<p>Like any good dependency manager Pipenv lets You install requirements pretty easily:</p>
<pre>$ pipenv install Flask-Login</pre>
<h2>Migrating your old projects</h2>
<p>If you already have a requirements.txt in your project you can run pipenv install and pipenv will convert your requirements.txt to a PipFile / Pipfile.lock</p>
<pre>pipenv install
requirements.txt found, instead of Pipfile! Converting...
Warning: Your Pipfile now contains pinned versions, if your requirements.txt did.
We recommend updating your Pipfile to specify the "*" version, instead.
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock (9832bf)!
Installing dependencies from Pipfile.lock (9832bf)...
================================ 6/6 - 00:00:04
To activate this project's virtualenv, run pipenv shell.</pre>
<h2>Helpful tools</h2>
<pre>$ pipenv graph
Flask-Login==0.4.1
  - Flask [required: Any, installed: 1.0.2]
    - click [required: &gt;=5.1, installed: 6.7]
    - itsdangerous [required: &gt;=0.24, installed: 0.24]
    - Jinja2 [required: &gt;=2.10, installed: 2.10]
      - MarkupSafe [required: &gt;=0.23, installed: 1.0]
    - Werkzeug [required: &gt;=0.14, installed: 0.14.1</pre>
<p>Voila, a dependency graph!</p>
<pre>$ pipenv check</pre>
<p>let&#8217;s You check your dependencies for security vulnerabilities.</p>
<h2>IDE support</h2>
<p>If you are using PyCharm (which You should of course) it&#8217;s already there with the 2018.2 release:</p>
<p><img decoding="async" class="alignnone size-full wp-image-2076" src="https://creatronix.de/wp-content/uploads/2018/07/pycharm_pipenv.png" alt="" width="779" height="491" srcset="https://creatronix.de/wp-content/uploads/2018/07/pycharm_pipenv.png 779w, https://creatronix.de/wp-content/uploads/2018/07/pycharm_pipenv-300x189.png 300w, https://creatronix.de/wp-content/uploads/2018/07/pycharm_pipenv-768x484.png 768w" sizes="(max-width: 779px) 100vw, 779px" /></p>
<p>Have fun using Pipenv!</p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/python-pipfile-and-pipenv/">Python Pipfile and pipenv</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Python pip and virtualenv</title>
		<link>https://creatronix.de/python-pip-and-virtualenv/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Fri, 04 May 2018 10:42:34 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[pip]]></category>
		<category><![CDATA[virtualenv]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1533</guid>

					<description><![CDATA[<p>After working for a couple of years with Python and external dependencies I&#8217;ve ran again and again into the same kind of problems. Bad habits Say you have a global python installation under e.g. C:\Python36 on Windows. When you start working on your first python project you want to use external packages and you encounter&#8230;</p>
<p>The post <a href="https://creatronix.de/python-pip-and-virtualenv/">Python pip and virtualenv</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After working for a couple of years with Python and external dependencies I&#8217;ve ran again and again into the same kind of problems.</p>
<h2>Bad habits</h2>
<p>Say you have a global python installation under e.g. C:\Python36 on Windows. When you start working on your first python project you want to use external packages and you encounter <a href="https://docs.python.org/2/installing/index.html">pip</a> as dependency management tool. (pip is part of the python installation since 2.7.9 / 3.4) So far so good.</p>
<p>But you keep installing all the packages into your global python installation.</p>
<p>This will work when you are working on just one project or when you have the strategy to always update all your projects to the latest version of the specific packages in use or never update at all.</p>
<p>As soon as you have two different projects where project A needs package X in version 1.2.3 and project B needs the same package in version 2.3.4 you run into trouble.</p>
<h2>And along comes &#8211; virtualenv</h2>
<p><a href="https://virtualenv.pypa.io/en/stable/">virtualenv</a> is short for virtual environment and is able to create local copies of your python installation. But first you have to install it globally once 🙂</p>
<pre>$ pip install virtualenv</pre>
<p>After that You can create a new environment via</p>
<pre>$ virtualenv &lt;Project_A&gt;/venv</pre>
<p>And activate it via</p>
<pre>$ cd &lt;Project_A&gt;/venv
$ source bin/activate
(venv)$</pre>
<p>Notes: You can create the virtual environments anywhere you like, but I consider it a good practice to place them under your project root directory.</p>
<p>When You are working with multiple venv for e.g. migrating from Python 2 to Python 3 you can also name them accordingly: venv27 and venv36 or the like.</p>
<p>The name in brackets in front of the prompt shows that you are in an active venv. With the command</p>
<pre>$ deactivate</pre>
<p>you can leave the environment.</p>
<h3>IDE Support</h3>
<p>When using the PyCharm IDE the new project wizard can help you setting up the venv:</p>
<p><img decoding="async" class="alignnone size-full wp-image-1537" src="https://creatronix.de/wp-content/uploads/2018/05/pycharm_venv.png" alt="" width="779" height="492" srcset="https://creatronix.de/wp-content/uploads/2018/05/pycharm_venv.png 779w, https://creatronix.de/wp-content/uploads/2018/05/pycharm_venv-300x189.png 300w, https://creatronix.de/wp-content/uploads/2018/05/pycharm_venv-768x485.png 768w" sizes="(max-width: 779px) 100vw, 779px" /></p>
<h2>A good requirement handling workflow</h2>
<p>Sooner or later you discover that you can place all your project dependencies in a text like requirements.txt and install them from there with:</p>
<pre>pip install -r requirements.txt</pre>
<p>But you have to decide if you want to add versions for the referenced packages or not.</p>
<p>Variant A</p>
<pre># requirements.txt
click==6.7
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.10
Werkzeug==0.14.1</pre>
<p>Variant B</p>
<pre># requirements.txt
click
Flask
itsdangerous
Jinja2
Werkzeug</pre>
<p>Variant A has the advantage that you have a reproducible environment, Variant B let&#8217;s you easily update to the latest versions of your packages (think: get security patches) Now you have to chose 🙂</p>
<p>But when there is an Option A and an option B there is always an option C as well.</p>
<p>A good approach comes from Kenneth Reitz:</p>
<blockquote><p>It’s very simple: instead of having one requirements file, you have two:</p></blockquote>
<ul>
<li>
<blockquote><p><code>requirements-to-freeze.txt</code></p></blockquote>
</li>
<li>
<blockquote><p><code>requirements.txt</code></p></blockquote>
</li>
</ul>
<p>In requirements_to_freeze.txt you just put the top level dependencies, requirements.txt will contain all dependencies with exact versions.</p>
<h3>Workflow for new projects</h3>
<ul>
<li>Create and activate virtual environment</li>
<li>Add dependencies to requirements_to_freeze.txt</li>
<li>
<pre>pip install -r requirements_to_freeze.txt</pre>
</li>
<li>
<pre>pip freeze &gt; requirements.txt</pre>
</li>
<li>Check both files into version control</li>
<li>Your colleague just runs
<ul>
<li>
<pre>pip install -r requirements.txt</pre>
</li>
</ul>
</li>
</ul>
<p>The big advantage of this approach: you have a kind of lockfile with the exact versions of your packages pinned down but you can easily update by installing from requirements_to_freeze.txt</p>
<h2>Automatic Dependency Tracking in PyCharm</h2>
<p>Again PyCharm is helpful when you already set up a project and you want to keep track of your dependencies:</p>
<p><img decoding="async" class="alignnone size-large wp-image-1541" src="https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking-1024x714.png" alt="" width="700" height="488" srcset="https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking-1024x714.png 1024w, https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking-300x209.png 300w, https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking-768x535.png 768w, https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking.png 1027w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>You can hint to your requirements file and PyCharm will tell You when You haven&#8217;t installed a listed requirement.</p>
<p><img decoding="async" class="alignnone size-full wp-image-1542" src="https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking_2.png" alt="" width="465" height="127" srcset="https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking_2.png 465w, https://creatronix.de/wp-content/uploads/2018/05/pycharm_requirements_tracking_2-300x82.png 300w" sizes="(max-width: 465px) 100vw, 465px" /></p>
<p>The post <a href="https://creatronix.de/python-pip-and-virtualenv/">Python pip and virtualenv</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>pip optional dependencies</title>
		<link>https://creatronix.de/pip-optional-dependencies/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Mon, 16 Apr 2018 12:11:48 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[optional]]></category>
		<category><![CDATA[pip]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1464</guid>

					<description><![CDATA[<p>Sometimes you want to make your python package usable for different situations, e.g. flask or bottle or django. If You want to minimize dependencies You can use an optional dependency in setup.py: extras_require={ 'flask': ['Flask&#62;=0.8', 'blinker&#62;=1.1'] } Now you can install the library with: pip install raven[flask] &#160;</p>
<p>The post <a href="https://creatronix.de/pip-optional-dependencies/">pip optional dependencies</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes you want to make your python package usable for different situations, e.g. flask or bottle or django.</p>
<p>If You want to minimize dependencies You can use an optional dependency in setup.py:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-python" data-lang="Python"><code>extras_require={ 
    'flask': ['Flask&gt;=0.8', 'blinker&gt;=1.1'] 
}</code></pre>
</div>
<p>Now you can install the library with:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-bash" data-lang="Bash"><code>pip install raven[flask]</code></pre>
</div>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/pip-optional-dependencies/">pip optional dependencies</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
