#๐Ÿ”’ how to work with making multiple modules

41 messages ยท Page 1 of 1 (latest)

dull temple
#

I have two modules and the second one imports the first one, it should say import firstmodule
but then I need to somehow make the first module importable, and I am confused how to do that. Do I need to "install" it somehow?

glossy stagBOT
#

@dull temple

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.

opal goblet
#

If firstmodule is the name of your module, inside a python file

#

Say, for example, the python file is named first_module_file.py

#

from your other file, you would do

from first_module_file import firstmodule
#

You can then use firstmodule normally

#

bare in mind, when importing from a file using import and/or from you leave out the file extension. Hope that helps

dull temple
#

I do know how to import from a folder nearby that has a __init__.py file

opal goblet
ancient sluice
#

They probably have 2 folders as modules

dull temple
#

like 2 separate libraries

opal goblet
#

You can add it to your python PATH variable

#
import sys

sys.path.insert(1, '/path/to/application/app/folder')
ancient sluice
#

I'm pretty sure you can pip install path/to/local/module, or pip install -e path/to/local/module to install it in editable/development mode, the latter is probably what you want if you're still devving it on your system

opal goblet
#

Basically this adds /path/to/application/app/folder to the list of folders for the python interpreter to search from when using the import module

opal goblet
ancient sluice
dull temple
grand oyster
#

I need to somehow make the first module importable

what do you mean by that

dull temple
#

If I want to share it with other people I can't use sys.path.insert because they will have different paths

grand oyster
#

everywhere? or for one specific project

dull temple
#

everywhere

grand oyster
#

oh yes if you specifically want to share your code you want to look up how to distribute a python package

dull temple
#

pip install -e does that

#

well I want to share it but the question is more about how do I develop 2 packages when one depends on another

grand oyster
#

you want to share both of them? what do they dfo

dull temple
#

the code in the other package needs to work as if the first package was installed

grand oyster
#

packages can have requirements for others

#

python packaging can be slightly in the weeds, i know arjancodes usually does excellent videos

https://www.youtube.com/watch?v=0f3moPe_bhk

https://www.youtube.com/watch?v=5KEObONUkik

It can be tricky when different packages in Python don't play nice. The solution to this problem is to create an isolated, virtual environment. In this video, Iโ€™ll show you how to set up a virtual environment with poetry, a package manager for Python that simplifies dependency management and project packaging.

๐Ÿš€ Next-Level Python Skillshare Cla...

โ–ถ Play video

Do you want to know how to build a complete Python package? Well, look no further! This video will take you step-by-step through the entire process, from creating your project to publishing it on PyPI.

The most popular software licenses available: https://tldrlegal.com/ or https://choosealicense.com/

Check the available classifiers here https...

โ–ถ Play video
dull temple
#

first one is a bunch of tensor transforms that arent in torchvision transforms or anywhere else, and second one is for quickly making datasets or merging datasets but basically it needs the first one to compose transforms

grand oyster
#

yes eventually you'd want to do pip install -e in the second one while you are developing it

#

i suggest check out both of those videos, and come back and ask more questions if there's new things you are still confused about

dull temple
#

ok, thanks!

#

I've just realized that to pip install my package I probably need to do something with it to make it being able to install using pip, but I am sure that one is googleable

grand oyster
#

yes the second video will explain that ๐Ÿ‘

dull temple
#

!close

glossy stagBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.