<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Arshan's blogs]]></title><description><![CDATA[Python | Django | DRF | React.js | Redux | Next.js | Software Engineer]]></description><link>https://blog.arshanaslam.me</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1719262361896/e8b5b4f3-0ac7-4046-8fca-a6251f47e8bb.png</url><title>Arshan&apos;s blogs</title><link>https://blog.arshanaslam.me</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 16:58:19 GMT</lastBuildDate><atom:link href="https://blog.arshanaslam.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Fixing “No module named 'pkg_resources'” After Setuptools 82 Removal]]></title><description><![CDATA[In February 2026, Setuptools v82.0.0 officially removed the pkg_resources module. Many existing Python projects still depend on pkg_resources, so upgrading to the latest Setuptools can suddenly cause the error:
ModuleNotFoundError: No module named 'p...]]></description><link>https://blog.arshanaslam.me/fixing-no-module-named-pkgresources-after-setuptools-82-removal</link><guid isPermaLink="true">https://blog.arshanaslam.me/fixing-no-module-named-pkgresources-after-setuptools-82-removal</guid><category><![CDATA[Pipeline]]></category><category><![CDATA[pip]]></category><category><![CDATA[Python]]></category><category><![CDATA[pkg_resources]]></category><category><![CDATA[setuptools]]></category><category><![CDATA[setup tools]]></category><dc:creator><![CDATA[Arshan Aslam]]></dc:creator><pubDate>Wed, 11 Feb 2026 22:07:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1770847557331/7a2f313a-2002-43b0-ac86-152569ac049c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In February 2026, <strong>Setuptools v82.0.0</strong> officially removed the <code>pkg_resources</code> module. Many existing Python projects still depend on <code>pkg_resources</code>, so upgrading to the latest Setuptools can suddenly cause the error:</p>
<pre><code class="lang-plaintext">ModuleNotFoundError: No module named 'pkg_resources'
</code></pre>
<p>This article explains <strong>why the error occurs</strong>, <strong>how to fix it immediately</strong>, and <strong>how to prevent it in future deployments</strong>.</p>
<hr />
<h1 id="heading-why-this-error-happens">Why This Error Happens</h1>
<p>Before <strong>Setuptools 82.0.0</strong>, the <code>pkg_resources</code> module was bundled with Setuptools and automatically available in Python environments.</p>
<p>Starting from <strong>v82.0.0 (Feb 2026)</strong>:</p>
<ul>
<li><p><code>pkg_resources</code> was <strong>removed</strong></p>
</li>
<li><p>Developers are encouraged to use:</p>
<ul>
<li><p><code>importlib.resources</code></p>
</li>
<li><p><code>importlib.metadata</code></p>
</li>
</ul>
</li>
</ul>
<p>However, many legacy libraries and internal tools still import:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pkg_resources
</code></pre>
<p>When environments install the <strong>latest Setuptools</strong>, the module is no longer present, resulting in the error.</p>
<hr />
<h1 id="heading-quick-fix-recommended-for-existing-projects">Quick Fix (Recommended for Existing Projects)</h1>
<p>If your project or dependencies still rely on <code>pkg_resources</code>, install a <strong>Setuptools version below 82</strong>.</p>
<h3 id="heading-requirementstxt-fix">requirements.txt fix</h3>
<pre><code class="lang-txt">setuptools&lt;=80.10.2
</code></pre>
<p>Then reinstall dependencies:</p>
<pre><code class="lang-bash">pip install -r requirements.txt
</code></pre>
<p>or manually:</p>
<pre><code class="lang-bash">pip install <span class="hljs-string">"setuptools&lt;=80.10.2"</span>
</code></pre>
<p>This restores the <code>pkg_resources</code> module.</p>
<hr />
<h1 id="heading-important-avoid-this-common-mistake">Important: Avoid This Common Mistake</h1>
<p>Do <strong>NOT</strong> use:</p>
<pre><code class="lang-txt">setuptools&gt;=80.10.2
</code></pre>
<p>because this allows pip to install <strong>Setuptools 82+</strong>, which removes <code>pkg_resources</code> and recreates the error.</p>
<p>Always pin using:</p>
<pre><code class="lang-txt">setuptools&lt;=80.10.2
</code></pre>
<p>(or any version <strong>below 82</strong>, depending on project compatibility)</p>
<hr />
<h1 id="heading-docker-fix-example">Docker Fix Example</h1>
<p>If using Docker, explicitly install the compatible version:</p>
<pre><code class="lang-dockerfile"><span class="hljs-keyword">RUN</span><span class="bash"> pip install --no-cache-dir <span class="hljs-string">"setuptools&lt;=80.10.2"</span></span>
</code></pre>
<p>This prevents future image rebuilds from breaking when newer versions are released.</p>
<hr />
<h1 id="heading-long-term-recommended-solution-future-proof">Long-Term Recommended Solution (Future-Proof)</h1>
<p>Since <code>pkg_resources</code> is now removed, projects should gradually migrate to:</p>
<h3 id="heading-instead-of">Instead of:</h3>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pkg_resources
version = pkg_resources.get_distribution(<span class="hljs-string">"mypackage"</span>).version
</code></pre>
<p>Use:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> importlib.metadata <span class="hljs-keyword">import</span> version
version = version(<span class="hljs-string">"mypackage"</span>)
</code></pre>
<p>For file access:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> importlib.resources <span class="hljs-keyword">import</span> files
</code></pre>
<p>This ensures compatibility with future Python environments.</p>
<hr />
<h1 id="heading-best-practice-for-production-systems">Best Practice for Production Systems</h1>
<p>To avoid unexpected dependency failures:</p>
<ol>
<li><p>Pin Setuptools in <strong>requirements.txt</strong></p>
</li>
<li><p>Lock dependencies using:</p>
<ul>
<li><p><code>pip freeze</code></p>
</li>
<li><p>Poetry lock file</p>
</li>
<li><p>pip-tools</p>
</li>
</ul>
</li>
<li><p>Rebuild Docker images regularly and test dependency upgrades safely</p>
</li>
</ol>
<hr />
<h1 id="heading-final-recommendation">Final Recommendation</h1>
<p>Until all dependent libraries migrate away from <code>pkg_resources</code>, use:</p>
<pre><code class="lang-txt">setuptools&lt;=80.10.2
</code></pre>
<p>instead of:</p>
<pre><code class="lang-txt">setuptools&gt;=80.10.2
</code></pre>
<p>This simple version pinning prevents the <strong>“No module named 'pkg_resources'”</strong> error across local environments, CI pipelines, and Docker deployments.</p>
<hr />
<p>Source: <a target="_blank" href="https://setuptools.pypa.io/en/stable/history.html#v82-0-0"><strong>https://setuptools.pypa.io/en/stable/history.html#v82-0-0</strong></a> <a target="_blank" href="https://setuptools.pypa.io/en/stable/history.html#v67-3-2"><strong>https://setuptools.pypa.io/en/stable/history.html#v67-3-2</strong></a></p>
]]></content:encoded></item><item><title><![CDATA[Getting Started with Django: A Comprehensive Guide to Your First App]]></title><description><![CDATA[Setting up and creating your first Django app is a foundational step in web development with Django. This guide will take you through the process from installation to creating a basic app, including advanced tips to enhance your development workflow....]]></description><link>https://blog.arshanaslam.me/getting-started-with-django-a-comprehensive-guide-to-your-first-app</link><guid isPermaLink="true">https://blog.arshanaslam.me/getting-started-with-django-a-comprehensive-guide-to-your-first-app</guid><category><![CDATA[Django]]></category><category><![CDATA[django orm]]></category><category><![CDATA[Developer]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Django Templates]]></category><dc:creator><![CDATA[Arshan Aslam]]></dc:creator><pubDate>Mon, 24 Jun 2024 21:05:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719260947422/e0f3d5bc-83e4-45f6-8ddc-d43b5527aead.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Setting up and creating your first Django app is a foundational step in web development with Django. This guide will take you through the process from installation to creating a basic app, including advanced tips to enhance your development workflow.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li><p>Python 3.6 or higher</p>
</li>
<li><p>pip (Python package installer)</p>
</li>
<li><p>Virtual environment management tool (optional but recommended)</p>
</li>
</ul>
<h3 id="heading-step-1-install-django">Step 1: Install Django</h3>
<p>First, ensure you have Python installed. Check your Python version:</p>
<pre><code class="lang-bash">python --version
</code></pre>
<p>Next, install Django using pip:</p>
<pre><code class="lang-bash">pip install django
</code></pre>
<p>Verify the installation:</p>
<pre><code class="lang-bash">django-admin --version
</code></pre>
<h3 id="heading-step-2-set-up-a-virtual-environment-optional-but-recommended">Step 2: Set Up a Virtual Environment (Optional but Recommended)</h3>
<p>Create a virtual environment to isolate your project dependencies:</p>
<pre><code class="lang-bash">python -m venv myenv
</code></pre>
<p>Activate the virtual environment:</p>
<ul>
<li><p>On Windows:</p>
<pre><code class="lang-bash">  myenv\Scripts\activate
</code></pre>
</li>
<li><p>On macOS/Linux:</p>
<pre><code class="lang-bash">  <span class="hljs-built_in">source</span> myenv/bin/activate
</code></pre>
</li>
</ul>
<h3 id="heading-step-3-create-a-django-project">Step 3: Create a Django Project</h3>
<p>Use <code>django-admin</code> to start a new project. Replace <code>myproject</code> with your project name:</p>
<pre><code class="lang-bash">django-admin startproject myproject
<span class="hljs-built_in">cd</span> myproject
</code></pre>
<h3 id="heading-step-4-create-a-django-app">Step 4: Create a Django App</h3>
<p>Inside your project directory, create a new app. Replace <code>myapp</code> with your app name:</p>
<pre><code class="lang-bash">python manage.py startapp myapp
</code></pre>
<h3 id="heading-step-5-configure-the-project-settings">Step 5: Configure the Project Settings</h3>
<p>Open <code>myproject/settings.py</code> and add your new app to the <code>INSTALLED_APPS</code> list:</p>
<pre><code class="lang-plaintext">INSTALLED_APPS = [
    # Default apps...
    'myapp',
]
</code></pre>
<h3 id="heading-step-6-create-a-simple-view">Step 6: Create a Simple View</h3>
<p>In your app directory (<code>myapp</code>), open <code>views.py</code> and create a basic view:</p>
<pre><code class="lang-bash">from django.http import HttpResponse

def home(request):
    <span class="hljs-built_in">return</span> HttpResponse(<span class="hljs-string">"Hello, world! This is my first Django app."</span>)
</code></pre>
<h3 id="heading-step-7-map-the-view-to-a-url">Step 7: Map the View to a URL</h3>
<p>Create a new file called <code>urls.py</code> in your app directory (<code>myapp</code>):</p>
<pre><code class="lang-plaintext">from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
]
</code></pre>
<p>Include your app's URLs in the project's URL configuration. Open <code>myproject/urls.py</code> and modify it:</p>
<pre><code class="lang-plaintext">from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('myapp.urls')),
]
</code></pre>
<h3 id="heading-step-8-run-the-development-server">Step 8: Run the Development Server</h3>
<p>Run the development server to see your app in action:</p>
<pre><code class="lang-plaintext">python manage.py runserver
</code></pre>
<p>Open your web browser and navigate to <code>http://127.0.0.1:8000/</code>. You should see "Hello, world! This is my first Django app."</p>
<h3 id="heading-advanced-tips">Advanced Tips</h3>
<h4 id="heading-1-using-class-based-views">1. Using Class-Based Views</h4>
<p>Class-based views (CBVs) provide more structure and reusability. Here’s how to convert your view to a CBV:</p>
<p>In <code>views.py</code>:</p>
<pre><code class="lang-plaintext">from django.views import View

class HomeView(View):
    def get(self, request):
        return HttpResponse("Hello, world! This is my first Django app using a class-based view.")
</code></pre>
<p>In <code>urls.py</code>:</p>
<pre><code class="lang-plaintext">from django.urls import path
from .views import HomeView

urlpatterns = [
    path('', HomeView.as_view(), name='home'),
]
</code></pre>
<h4 id="heading-2-template-system">2. Template System</h4>
<p>Instead of returning raw HTML, use Django’s templating system. Create a <code>templates</code> directory inside <code>myapp</code> and a file called <code>home.html</code>:</p>
<p><code>myapp/templates/home.html</code>:</p>
<pre><code class="lang-plaintext">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;My First Django App&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;Hello, world! This is my first Django app.&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Modify the view to render this template:</p>
<p>In <code>views.py</code>:</p>
<pre><code class="lang-plaintext">from django.shortcuts import render

def home(request):
    return render(request, 'home.html')
</code></pre>
<h4 id="heading-3-models-and-database">3. Models and Database</h4>
<p>Django's ORM (Object-Relational Mapping) allows you to interact with your database using Python classes. Define models in <code>models.py</code>:</p>
<p><code>myapp/models.py</code>:</p>
<pre><code class="lang-plaintext">from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()

    def __str__(self):
        return self.title
</code></pre>
<p>Apply the model changes to the database:</p>
<pre><code class="lang-bash">epython manage.py makemigrations
python manage.py migrate
</code></pre>
<p>Use the Django admin interface to manage your models. Register your model in <code>admin.py</code>:</p>
<p><code>myapp/admin.py</code>:</p>
<pre><code class="lang-plaintext">from django.contrib import admin
from .models import Post

admin.site.register(Post)
</code></pre>
<p>Create a superuser to access the admin:</p>
<pre><code class="lang-bash">python manage.py createsuperuser
</code></pre>
<p>Start the server and navigate to <code>http://127.0.0.1:8000/admin</code> to log in with your superuser credentials.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>You’ve now set up a Django project, created an app, and explored basic and advanced concepts. This foundational knowledge will enable you to build more complex applications. Remember to refer to the <a target="_blank" href="https://docs.djangoproject.com/en/stable/">Django documentation</a> for more detailed information and best practices.</p>
]]></content:encoded></item></channel></rss>