Package directory question

Ben Finney ben.finney at 1
Mon Jun 25 10:19:20 EDT 2018


From: Ben Finney <ben+python at benfinney.id.au>

Robert Latest via Python-list <python-list at python.org> writes:

> Because the main.py script needs to import the tables.py module from
> backend, I put this at the top if main.py:
>
>    sys.path.append('../..')
>    import jobwatch.backend.tables as tables
>
> My question is: Is this the way it should be done? It looks fishy. The
> only alternative I could come up with is to put a symlink to tables.py
> into the frontend directory, which also seems fishy.

Your fish-sense is working correctly. Both of those are hard-coding the path,
when the Python import mechanism is designed so you don't do that.

Instead, to run the package, first install the package.

To install the package, use the Pip tool. This comes standard when you install
Python 3.

By installing your code, you make it available to be discovered by Python's
normal import mechanism.

So, choose how you want to install the package:

* To install for normal use, Γ  python3 -m pip install Γ |Γ ╓.

* To install for use only by the current user, add the Γ  --userΓ ╓ option.

* To install for use while also developing, add the Γ  --editableΓ ╓ option.

See the Γ  python3 -m pip --helpΓ ╓ document for details about what all that
does.

--
 \        Γ úTelling pious lies to trusting children is a form of abuse, |
  `\                    plain and simple.Γ ╪ Γ ÷Daniel Dennett, 2010-01-12 |
_o__)                                                                  |
Ben Finney

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)



More information about the Python-list mailing list