0

I created a custom library in python and I published it using jenkins, my problem is that to call my new library I would use `

import lib.my_lib

but I want to change so I use

import my_lib 

directly. I want to find a solution where I can change this in my code and from my research I think it should be in the init file but I don't know how to do it.

I tried to initialize the library by using from lib.my_lib import my_lib hoping that would make my_lib recognizable but it didn't work.

This is my project structure:

lib
|__docs
|_my_lib
|___
    |_model
    |_my_lib.py
    |___init__.py
|_tests
|_setup.py
|_requirements.txt
|_jenkinsfile
  • 1
    Is there a place where we can see your code (e.g. github) or can you give us some more information about the structure of your project? – Cuartero Jun 13 '23 at 13:21
  • 1
    Perhaps see [this answer](https://stackoverflow.com/a/4383597/9731347). – SanguineL Jun 13 '23 at 13:27
  • That answer doesn't fix my problem because I want users to call directly my custom library but its name my_lib without having to deal with paths – elyes massoussi Jun 13 '23 at 13:42
  • 1
    Well, either you use `sys` to add the `lib` folder to the `PATH` or you use `import lib.my_lib` (which is the best way). Those are the only ways to import a file that is in a subfolder. I also am confused about what kind of benefit you're trying to achieve. Saving you from typing four characters? – SanguineL Jun 13 '23 at 13:59

0 Answers0