简体   繁体   中英

central path for python modules

I am starting to convert a lot of C stuff in python 3.

In CI defined a directory called "Toolbox", where i put all my functions i needed in different programs, so called libraries.

To use a specific library i had just to add the line

#include "/home/User/Toolbox/VectorFunctions.h"

into my source. So i was able to use the same library in different sources.

In python i tried to write some Toolbox functions and implement them into the source with import VectorFunctions, which works, as long as the file VectorFunctions.py is in the same directory as the source.

I there a way (I think there must be one...) telling python that VectorFunctions.py is located in a different directory, eg /home/User/Python_Toolbox?

Thanks for any comment!

What I would do is to organize these toolbox functions into one installable Python package bruno_toolbox , with its setup.py , and then install it into development mode to system site packages, using python setup.py develop , and then use the bruno_toolbox like any other package on the system, everywhere. Then if that package feels useful, I'd publish it to PyPI for the benefit of everyone.

You can use python path. Writing this code beginning of your program :

import sys
sys.path.append('/home/User/Python_Toolbox')

If you have VectorFunctions.py in this folder you can import it :

import VectorFunctions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM