#πŸ”’ How do you structure your own projects (considering installing mine as a module)

24 messages Β· Page 1 of 1 (latest)

slate isle
#

At the moment, I working in a small-medium project, and I am facing trouble with relative imports and file locations.

In general (and as far as I know) these are some of the most common ways to structure a private project:
A - Individual scripts and absolute/relative imports with a package structure
B - Adding your base path to PYTHONPATH
C - Installing your own module with the -e flag and import the module

Which one do you use (even if is not considered here) and why?

swift mountainBOT
#

@slate isle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

azure sandal
#

like most lib python does .. one separate directory in base path (venv\Lib\site-packages)

slate isle
#

Ohh I think I see it

#

You are saying that you create your project files inside the venv Lib

#

So it is considered as a module to it. Am I right?

#

So.. If my current file system is something like:

#
.
β”œβ”€β”€ .venv
β”œβ”€β”€ tests_files/
β”‚   β”œβ”€β”€ test1.in
β”‚   └── test2.in
β”œβ”€β”€ tests_loader.py
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ script1.py
β”‚   └── script2.py
└── __init__.py
#

You are saying to do something like:

slow solstice
#

hi debussy, love your reverie

slate isle
#

Hi Chuchumuru

#

I love it too

#

Now I am into coding, modern music pissed me off

slow solstice
#

haha

slate isle
#

But you do something like this instead?

.
.
└── .venv/
    └── Lib/
        └── site-packages/
            └── project_name /
                β”œβ”€β”€ tests_files/
                β”‚   β”œβ”€β”€ test1.in
                β”‚   └── test2.in
                β”œβ”€β”€ tests_loader.py
                β”œβ”€β”€ scripts/
                β”‚   β”œβ”€β”€ script1.py
                β”‚   └── script2.py
                └── __init__.py
limpid sierra
slate isle
#

I understand, something like an "entry point"

#

That way, you can use absolute imports

#

So, you dont install your project as a module?

azure sandal
#

my project i compile an exe ... and the user only see that ... all other is temporary in temp folder (like \AppData\Local\Temp)

slate isle
#

But before compiling your project into an exe, how do you structure it?

azure sandal
#

its more or less automated by pyintstaller similar to yours (venv/libs and venv/scripts) most other is on your own and how you call and define in your main code

swift mountainBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.