[Tutor] Problem compiling code from GitHub

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Aug 29 09:04:49 EDT 2018


On Mon, 27 Aug 2018 at 13:18, Dave Hill <dave at the-hills.org.uk> wrote:
>
> I have found 'odswriter' on GitHub
> https://github.com/mmulqueen/odswriter which appears to provide what I
> want. However, I have come to a halt, due to the limitation of my knowledge.
>
> I admit that I am confounded as to where/how to access this code.

There are two ways. The code is there in github because that's where
the author(s) are saving their work on it and where people could
contribute to it.

Normally as a "user" of the odswriter code you wouldn't access it from
there. If you did want to access it from github in order to use the
code you would normally use the git program to download it:

    $ git clone https://github.com/mmulqueen/odswriter

Alternatively you can download the .zip file from github using your
browser and extract it. Either way you then need to *install* the
package to use it:

    $ cd odswriter
    $ python setup.py install

However as I said before someone who simply wants to use the odswriter
code (and not contribute to writing it) would not normally access the
code from github since Python has a better place for this which is
PyPI. You can see the PyPI page for odswriter here:
https://pypi.org/project/odswriter/

Again though you wouldn't normally download the code from PyPI using
the web browser. Python comes with a program called pip which can
download and install it for you. So the command is:

    $ pip install odswriter

I don't know why Steve has difficulty with that but this is the
easiest, fastest, officially-recommended etc. way to install Python
packages.

> I am using Python 3.6.4, in IDLE on a PC running windows.
>
> I am using the following code as a starting point , Test_ODS#1.py
>
>     import datetime
>     import decimal
>     ##import odswriter as ods
>     try:
>          from OdsWriter import odswriter as ods
>     except RuntimeError:
>          print("Error importing OdsWriter!")

I have just installed odswriter in Python 3.6, on Linux, using pip and
I get this:

    >>> from OdsWriter import odswriter as ods
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'OdsWriter'

However if I instead write

    >>> from odswriter import ODSWriter

then it works fine. The package name odswriter should be all
lower-case. This may not show an error on Windows because you may be
using a case-insensitive filesystem but you should fix it anyway. The
class-name ODSWriter needs to exactly match each upper and lower-case
letter because Python is much fussier than Windows file systems.

I think that misspelling the capitals in a package name can lead to
import problems although I don't know if that explains the problem
you're having. Most likely that is because you haven't "installed" the
code correctly.

--
Oscar


More information about the Tutor mailing list