<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oktapian Candra</title>
    <description>The latest articles on DEV Community by Oktapian Candra (@oktapiancaw).</description>
    <link>https://dev.to/oktapiancaw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F533457%2Fd120e72b-bec2-4c07-9048-0ff318cb0f4e.jpeg</url>
      <title>DEV Community: Oktapian Candra</title>
      <link>https://dev.to/oktapiancaw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oktapiancaw"/>
    <language>en</language>
    <item>
      <title>Change the Python Version as You Like: Become the Python Wizard with pyenv</title>
      <dc:creator>Oktapian Candra</dc:creator>
      <pubDate>Tue, 25 Feb 2025 07:15:46 +0000</pubDate>
      <link>https://dev.to/oktapiancaw/change-the-python-version-as-you-like-become-the-python-wizard-with-pyenv-jb0</link>
      <guid>https://dev.to/oktapiancaw/change-the-python-version-as-you-like-become-the-python-wizard-with-pyenv-jb0</guid>
      <description>&lt;p&gt;Ah, Python developers—always on the cutting edge of innovation, until the day you clone a repository and realize &lt;em&gt;it only works with Python 3.8&lt;/em&gt;. You’re running Python 3.10 or, worse, Python 3.11, and now all your hopes and dreams are dashed by an infuriating error message that might as well say, &lt;em&gt;“Sorry, pal. Wrong Python.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But fear not, for today we’re diving into &lt;strong&gt;&lt;a href="https://github.com/pyenv/pyenv" rel="noopener noreferrer"&gt;pyenv&lt;/a&gt;&lt;/strong&gt;, the magical tool that lets you change Python versions the way you’d change socks (though hopefully, you do that daily). By the end of this article, you’ll be switching Python versions like a pro, showing off to your colleagues, and maybe even naming yourself the “Keeper of the Snakes.”&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Does Python Versioning Even Matter?
&lt;/h2&gt;

&lt;p&gt;Let’s face it: Python developers have trust issues with versioning. It all started with the split between Python 2 and Python 3 (RIP Python 2, we’ll always remember your &lt;code&gt;print&lt;/code&gt; statements without parentheses). Fast forward to today, and Python releases new versions faster than you can debug your latest &lt;code&gt;TypeError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here’s the thing: not all Python projects are created equal. Some depend on older versions for compatibility reasons, while others thrive on the bleeding edge. And let’s not forget the chaos when you’re juggling multiple projects, each screaming for a different Python version.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;pyenv&lt;/strong&gt; swoops in to save the day, like a superhero with a cape made of Python syntax.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is pyenv?
&lt;/h2&gt;

&lt;p&gt;In simple terms, &lt;strong&gt;&lt;a href="https://github.com/pyenv/pyenv" rel="noopener noreferrer"&gt;pyenv&lt;/a&gt;&lt;/strong&gt; is a Python version management tool that allows you to install, switch, and manage multiple Python versions on the same machine. It’s like a magical wardrobe that lets you choose the Python version you need for the job at hand.&lt;/p&gt;

&lt;p&gt;Key Features of pyenv:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Install Multiple Versions&lt;/strong&gt;: Easily install any version of Python, from the ancient days of 2.7 to the shiny new releases of 3.x.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version Switching&lt;/strong&gt;: Switch between global, local (project-specific), or shell-specific Python versions effortlessly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No More Conflicts&lt;/strong&gt;: No more fighting with your system Python installation or accidentally breaking things your operating system depends on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of pyenv as your personal Python librarian. You ask for Python 3.8.10? It hands it to you on a silver platter. Need Python 3.11 for another project? No problem—it’s like having every Python version in your back pocket.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: Installing pyenv (Let’s Get This Party Started)
&lt;/h3&gt;

&lt;p&gt;Before we start swapping Python versions like Pokémon cards, we need to install pyenv. Here’s how to do it:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Install Required Dependencies
&lt;/h4&gt;

&lt;p&gt;First, let’s make sure we have all the necessary tools for building Python versions. Run the following commands based on your operating system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update  
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \  
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \  
xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Install pyenv
&lt;/h4&gt;

&lt;p&gt;Now, let’s install pyenv itself. Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://pyenv.run | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Update Your Shell Configuration
&lt;/h4&gt;

&lt;p&gt;Next, we need to add pyenv to your shell startup file so it runs automatically when you open a terminal. If you’re using &lt;code&gt;bash&lt;/code&gt;, add the following lines to your &lt;code&gt;~/.bashrc&lt;/code&gt; or &lt;code&gt;~/.bash_profile&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PYENV_ROOT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.pyenv"&lt;/span&gt;  
&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;$PYENV_ROOT&lt;/span&gt;/bin &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PYENV_ROOT&lt;/span&gt;&lt;span class="s2"&gt;/bin:&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;pyenv init - bash&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For &lt;code&gt;zsh&lt;/code&gt;, add these lines to your &lt;code&gt;~/.zshrc&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;Finally, reload your shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SHELL&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Verify Installation
&lt;/h4&gt;

&lt;p&gt;Check if pyenv is installed correctly by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see something like &lt;code&gt;pyenv 2.3.0&lt;/code&gt;, you’re good to go. If not, double-check the steps above and try not to yell at your computer (it’s sensitive, you know).&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Installing and Switching Python Versions
&lt;/h3&gt;

&lt;p&gt;Now comes the fun part: installing and switching between Python versions like a true Python wizard.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installing a Python Version
&lt;/h4&gt;

&lt;p&gt;Let’s say you need Python 3.8.10 for a project. Simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install &lt;/span&gt;3.8.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Want Python 3.10.9, the cool new kid on the block? No problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install &lt;/span&gt;3.10.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see a full list of available versions with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting a Global Python Version
&lt;/h4&gt;

&lt;p&gt;To set a global (default) Python version for your entire system, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv global 3.10.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, every time you open a terminal, Python 3.10.9 will be your default.&lt;/p&gt;

&lt;h4&gt;
  
  
  Setting a Local Python Version
&lt;/h4&gt;

&lt;p&gt;Want to use a specific Python version for a particular project? Navigate to your project directory and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;local &lt;/span&gt;3.8.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a &lt;code&gt;.python-version&lt;/code&gt; file in the directory, telling pyenv to use Python 3.8.10 whenever you’re working in this project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Temporarily Changing Python Version
&lt;/h4&gt;

&lt;p&gt;If you just want to switch Python versions temporarily (e.g., for a quick test), use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv shell 3.8.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets the Python version for your current shell session only. Once you close the terminal, it’s back to the default.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3: Living the Dream
&lt;/h3&gt;

&lt;p&gt;Congratulations! You’re now the proud owner of a flexible Python environment. No more arguing with your system Python installation or worrying about breaking dependencies. With pyenv, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Seamlessly switch between Python versions.&lt;/li&gt;
&lt;li&gt;Develop multiple projects with different Python requirements on the same machine.&lt;/li&gt;
&lt;li&gt;Impress your developer friends with your newfound Python wizardry.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Bonus: pyenv + Virtual Environments = True Happiness
&lt;/h2&gt;

&lt;p&gt;If you want to take things to the next level, combine pyenv with virtual environments using &lt;code&gt;pyenv-virtualenv&lt;/code&gt;. This allows you to create isolated environments for each project, each with its own Python version and dependencies.&lt;/p&gt;

&lt;p&gt;Install it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv &lt;span class="nb"&gt;install &lt;/span&gt;pyenv-virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then create a virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pyenv virtualenv 3.8.10 my-awesome-env
pyenv activate my-awesome-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you’re not just a Python wizard—you’re a Python &lt;em&gt;ninja&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;With pyenv, you’ve unlocked the power to switch Python versions as easily as you change your Spotify playlist. No more version conflicts, no more dependency nightmares—just smooth, efficient Python development.&lt;/p&gt;

&lt;p&gt;So go forth, Keeper of the Snakes, and wield your Python versions wisely. And remember: with great power comes great responsibility… and probably a lot of late-night coding.&lt;/p&gt;

&lt;p&gt;Happy coding, and may your &lt;code&gt;pip install&lt;/code&gt; commands always succeed on the first try!&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>linux</category>
    </item>
    <item>
      <title>Create package using Poetry, and deploy on private PyPi Server</title>
      <dc:creator>Oktapian Candra</dc:creator>
      <pubDate>Tue, 18 Feb 2025 05:46:47 +0000</pubDate>
      <link>https://dev.to/oktapiancaw/create-package-using-poetry-and-deploy-on-private-pypi-server-40g5</link>
      <guid>https://dev.to/oktapiancaw/create-package-using-poetry-and-deploy-on-private-pypi-server-40g5</guid>
      <description>&lt;p&gt;Ah, Python developers—masters of their craft, wielders of virtual environments, and occasional snackers of leftover pizza at 3 a.m. If you’ve ever wanted to create your own private Python package (because who doesn’t want to feel like a package-deploying secret agent?), this article will guide you through the process using &lt;strong&gt;&lt;a href="https://python-poetry.org/" rel="noopener noreferrer"&gt;Poetry&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://github.com/pypiserver/pypiserver" rel="noopener noreferrer"&gt;pypiserver&lt;/a&gt;&lt;/strong&gt;. By the end, you’ll not only have a private package but also a sense of accomplishment rivaled only by successfully debugging a &lt;code&gt;KeyError&lt;/code&gt; at first glance.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Poetry? (Not the Rhyming Kind)
&lt;/h2&gt;

&lt;p&gt;Before you start imagining yourself as a wordsmith crafting verses under the moonlight, let me clarify: &lt;strong&gt;Poetry&lt;/strong&gt; in this context is a tool for managing Python projects. It simplifies dependency management, package versioning, and publishing. Think of it as your Python project’s personal assistant—organizing everything neatly so you can focus on writing code (and googling stack traces).&lt;/p&gt;

&lt;p&gt;Key Features of Poetry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Management&lt;/strong&gt;: Specify, resolve, and manage your project dependencies in one place.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Environment Integration&lt;/strong&gt;: Automatically creates virtual environments for your project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Packaging Made Easy&lt;/strong&gt;: Build and publish Python packages with minimal effort—no need to wrestle with &lt;code&gt;setup.py&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, Poetry is like that one coworker who always keeps their desk tidy and remembers everyone’s birthday.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is pypiserver? (Hint: It’s Not a Fancy Dessert)
&lt;/h2&gt;

&lt;p&gt;Now, let’s talk about &lt;strong&gt;pypiserver&lt;/strong&gt;: a simple, lightweight PyPI (Python Package Index) server you can host yourself. Why would you want this? Well, maybe you’re building proprietary software, or maybe you just want to feel like a Python supervillain hoarding private packages. Either way, pypiserver lets you securely host and serve your own packages without relying on public repositories like PyPI.&lt;/p&gt;

&lt;p&gt;Key Features of pypiserver:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Private Package Hosting&lt;/strong&gt;: Store your own packages locally or on a private server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight&lt;/strong&gt;: Minimal setup and resource usage, perfect for small-scale hosting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compatibility&lt;/strong&gt;: Works seamlessly with pip and other Python tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Essentially, it’s like running your own private PyPI, but without needing a degree in server management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Would You Want a Private Package Anyway?
&lt;/h2&gt;

&lt;p&gt;Good question! Here are some common reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have proprietary code you don’t want to share with the world.&lt;/li&gt;
&lt;li&gt;You’re building reusable modules for internal use within your organization.&lt;/li&gt;
&lt;li&gt;You just want to flex on your teammates by saying, “Oh, I have my own PyPI server.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we’ve got the basics down, let’s jump into the fun part: creating a private package and deploying it on pypiserver.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: Install Poetry
&lt;/h3&gt;

&lt;p&gt;First, install Poetry. If you don’t already have it, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; https://install.python-poetry.org | python3 -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installation, make sure Poetry is accessible by checking its version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see something like &lt;code&gt;Poetry version 1.6.0&lt;/code&gt;, congratulations—you’re ready to roll. If not, double-check your installation steps, and try not to curse too loudly.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Create Your Python Package
&lt;/h3&gt;

&lt;p&gt;Let’s create that private package. For this example, we’re going to make a package called &lt;code&gt;my_private_package&lt;/code&gt; because creativity is overrated. Run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry new my_private_package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a new directory with the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_private_package/  
├── my_private_package/  
│   └── __init__.py  
├── tests/  
│   └── __init__.py  
├── pyproject.toml  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;pyproject.toml&lt;/code&gt; file is Poetry’s version of a project blueprint. It defines everything about your project, from its dependencies to its version number.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;tests/&lt;/code&gt; directory is where you can write tests… you know, once you stop procrastinating.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 3: Write Some Code
&lt;/h3&gt;

&lt;p&gt;Now, let’s add some code to your package. Open &lt;code&gt;my_private_package/__init__.py&lt;/code&gt; and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;! Welcome to your private package.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s simple, but hey, it gets the job done.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4: Build the Package
&lt;/h3&gt;

&lt;p&gt;To build your package, navigate to the root directory of your project and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a &lt;code&gt;dist/&lt;/code&gt; directory containing &lt;code&gt;.tar.gz&lt;/code&gt; and &lt;code&gt;.whl&lt;/code&gt; files for your package. These are the files you’ll upload to your private PyPI server (or, as I like to call it, your “Python treasure chest”).&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5: Set Up pypiserver
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Install pypiserver
&lt;/h4&gt;

&lt;p&gt;Now it’s time to set up your private PyPI server. First, install pypiserver:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;pypiserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a Directory for Your Packages
&lt;/h4&gt;

&lt;p&gt;Decide where you want to store your private packages. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/private_packages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add security using htpasswd
&lt;/h4&gt;

&lt;p&gt;Create a user and choose a beautiful password for your private PyPi Server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;htpasswd &lt;span class="nt"&gt;-sc&lt;/span&gt; ~/private_packages/htpasswd.txt admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Start the Server
&lt;/h4&gt;

&lt;p&gt;Run the following command to start pypiserver:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pypi-server run &lt;span class="nt"&gt;-p&lt;/span&gt; 8060 ~/private-packages &lt;span class="nt"&gt;-P&lt;/span&gt; ~/private-packages/htpasswd.txt &lt;span class="nt"&gt;--hash-algo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sha256
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start the server on &lt;code&gt;http://localhost:8060&lt;/code&gt;. You can now upload and serve packages from this directory.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 6: Deploy Your Package to pypiserver
&lt;/h3&gt;

&lt;p&gt;Let’s back to &lt;code&gt;my_private_package&lt;/code&gt;project directory, and add this on your private PyPi Server (let name it as “treasure_chest”) to the pyproject.toml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[[tool.poetry.source]]&lt;/span&gt;  
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"treasure_chest"&lt;/span&gt;  
&lt;span class="py"&gt;url&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"http://localhost:8060/simple/"&lt;/span&gt;  
&lt;span class="py"&gt;priority&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"supplemental"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To upload packages to a server with Poetry, you must first configure it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry config repositories.treasure_chest http://localhost:8060/  
poetry config http-basic.treasure_chest admin &lt;span class="s2"&gt;"&amp;lt;your_beautiful_password&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, yeah this time for upload your packages using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry publish &lt;span class="nt"&gt;--repository&lt;/span&gt; treasure_chest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will upload your package on &lt;code&gt;dist/&lt;/code&gt;to your private PyPi Server, and you will see your packages on &lt;code&gt;http://localhost:8060/simple/&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 7: Install Your Private Package
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using pip install
&lt;/h4&gt;

&lt;p&gt;To install your private package from pypiserver, use pip with the &lt;code&gt;--extra-index-url&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--extra-index-url&lt;/span&gt; http://localhost:8080 my_private_package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using poetry
&lt;/h4&gt;

&lt;p&gt;Or.. you can install it using poetry, with add your private PyPi server configuration on your &lt;code&gt;pyproject.toml&lt;/code&gt; like in the package directory earlier&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[[tool.poetry.source]]&lt;/span&gt;  
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"treasure_chest"&lt;/span&gt;  
&lt;span class="py"&gt;url&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"http://localhost:8060/simple/"&lt;/span&gt;  
&lt;span class="py"&gt;priority&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"supplemental"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then running this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry add &lt;span class="nt"&gt;--source&lt;/span&gt; treasure_chest my_private_package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see &lt;code&gt;Successfully installed my_private_package&lt;/code&gt;, congratulations—you’ve officially entered the realm of private package ninjas.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;And there you have it! You’ve created a private Python package using Poetry and deployed it on pypiserver. Whether you’re building an empire of proprietary modules or just trying to impress your developer friends, you now have the tools to do it.&lt;/p&gt;

&lt;p&gt;Remember, with great power comes great responsibility. Use your private PyPI server wisely, and don’t forget to share this tutorial with your favorite Python buddies. Or don’t—it’s your secret package lair, after all.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>development</category>
    </item>
  </channel>
</rss>
