title: How can a Python module single file be installed using pip and PyPI?
body: <p>I am trying to learn how to make a Python module available via pip on PyPI. In order to do this, I am testing using the PyPI test site (<a href="https://testpypi.python.org/pypi" rel="noreferrer">https://testpypi.python.org/pypi</a>) and have attempted to create a <code>setup.py</code> for the module. My module is a file at the root directory and I cannot get it to be installed successfully. I want to find out how to do this.</p>
  
  <p>Below, I detail the steps I am taking. I suspect that the problem lies in how I have written <code>setup.py</code>.</p>
  
  <p>The anatomy of the repository is as follows:</p>
  
  <pre><code>.
  ├── examples_1.py
  ├── LICENSE
  ├── MANIFEST.in
  ├── README.rst
  ├── setup.py
  └── supermodule.py
  </code></pre>
  
  <p>Note that the module is simply the file <code>supermodule.py</code> at the root of the directory. Note also that the file <code>examples_1.py</code> is <em>not</em> to be included in an installation of the module package.</p>
  
  <p>The contents of <code>setup.py</code> are as follows:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  import os
  import setuptools
  
  def read(*paths):
  
      with open(os.path.join(*paths), "r") as filename:
          return filename.read()
  
  def main():
  
      setuptools.setup(
          name             = "supermodule",
          version          = "2015.10.30.0820",
          description      = "super utilities",
          long_description = (read("README.rst")),
          url              = "https://github.com/johndrake1/junk",
          author           = "John Drake",
          author_email     = "j.drake@sern.ch",
          license          = "GPLv3",
          package_data     = {
              "": [
                  "*.txt",
                  "*.md",
                  "*.rst",
                  "*.py"
              ]
          }
      )
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I go through the following procedures to register, upload and install the package:</p>
  
  <pre><code>python setup.py register -r https://testpypi.python.org/pypi
  python setup.py sdist upload -r https://testpypi.python.org/pypi
  sudo pip install -i https://testpypi.python.org/pypi supermodule
  </code></pre>
  
  <p>In the source distribution, <code>supermodule-2015.10.30.0820.tar.gz</code>, I can see the following directory structure:</p>
  
  <pre><code>.
  └── supermodule-2015.10.30.0820
      ├── LICENSE
      ├── MANIFEST.in
      ├── PKG-INFO
      ├── README.rst
      ├── setup.cfg
      ├── setup.py
      ├── supermodule.egg-info
      │   ├── dependency_links.txt
      │   ├── PKG-INFO
      │   ├── SOURCES.txt
      │   └── top_level.txt
      └── supermodule.py
  </code></pre>
  
  <p>So, it appears that the packaging and uploading works fine and contains the module file <code>supermodule.py</code> that is at the root directory. However, when I install the package, I get the following files installed locally:</p>
  
  <pre><code>/usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info/DESCRIPTION.rst
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info/METADATA
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info/RECORD
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info/WHEEL
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info/metadata.json
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0820.dist-info/top_level.txt
  </code></pre>
  
  <p>You can see that the file <code>supermodule.py</code> is not there and it cannot be imported in a Python instance. What should I do to include this file in the installation such that it is importable in Python?</p>
  
  <hr>
  
  <p>EDIT: Following a suggestion by @DeanFenster, I moved the file <code>supermodule.py</code> to <code>supermodule/__init__.py</code> and changed <code>setup.py</code> to the following:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  import os
  import setuptools
  
  def read(*paths):
      with open(os.path.join(*paths), "r") as filename:
          return filename.read()
  
  def main():
  
      setuptools.setup(
          name             = "supermodule",
          version          = "2015.10.30.0902",
          description      = "super utilities",
          long_description = (read("README.rst")),
          url              = "https://github.com/johndrake1/junk",
          author           = "John Drake",
          author_email     = "j.drake@sern.ch",
          license          = "GPLv3",
          packages         = ["supermodule"]
      )
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Following registration, upload and installation, this resulted in an installation that made the module importable, with the following files installed locally:</p>
  
  <pre><code>/usr/local/lib/python2.7/dist-packages/supermodule
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info
  /usr/local/lib/python2.7/dist-packages/supermodule/__init__.py
  /usr/local/lib/python2.7/dist-packages/supermodule/__init__.pyc
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info/DESCRIPTION.rst
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info/METADATA
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info/RECORD
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info/WHEEL
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info/metadata.json
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.0902.dist-info/top_level.txt
  </code></pre>
  
  <p>It's good that this approach works, but I would still like to know how to install the module when it is in the form of a single file.</p>
  
  <hr>
  
  <p>EDIT: Following a suggestion by @Xk0nSid, I changed <code>setup.py</code> to the following:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  import os
  import setuptools
  
  def read(*paths):
      with open(os.path.join(*paths), "r") as filename:
          return filename.read()
  
  def main():
  
      setuptools.setup(
          name             = "supermodule",
          version          = "2015.10.30.1001",
          description      = "super utilities",
          long_description = (read("README.rst")),
          url              = "https://github.com/johndrake1/junk",
          author           = "John Drake",
          author_email     = "j.drake@sern.ch",
          license          = "GPLv3",
          py_modules       = ["supermodule"],
          entry_points     = """
              [console_scripts]
              supermodule = supermodule:supermodule
          """
      )
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Following registration, upload and installation, this resulted in an installation that made the module importable, with the following files installed locally:</p>
  
  <pre><code>/usr/local/bin/supermodule
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info
  /usr/local/lib/python2.7/dist-packages/supermodule.py
  /usr/local/lib/python2.7/dist-packages/supermodule.pyc
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/DESCRIPTION.rst
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/METADATA
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/RECORD
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/WHEEL
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/entry_points.txt
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/metadata.json
  /usr/local/lib/python2.7/dist-packages/supermodule-2015.10.30.1001.dist-info/top_level.txt
  </code></pre>
  
  <p>This approach was successful at handling the single file form of the module.</p>