-1

I am installing a python X module which is dependent on Y software.

There are two versions of Y software available, one that comes with operating system and another I installed it to a custom folder.

When I install "python X" module, I am asking it to take Y from my custom folder as a dependency.

The installation is successful, but while running that "python X" module as a application user then it is always taking Y ( it is making use of the libraries from Y) which is coming with operating system.

If we assume a.py is making use of "python X" module and

if I run

python a.py

then "python X" module is taking Y from my custom folder, but when I do

sudo -u user1 python a.py

then "python x" module is taking Y installed from operating system..

Could you let me know how to make "python x" module to always take from my custom folder for whichever user.

Kalyan Kumar
  • 399
  • 3
  • 14

1 Answers1

0

assume "from my custom folder", you may import "folder.module".

example :

#Test3.py
from Sub.Add2 import Add1 as SubAdd1
import Sub.Add2
import Add2

print( 'from Sub.Add2 import Add1 as SubAdd1, call SubAdd1 :' )
SubAdd1()

print( 'import Sub.Add2, call Sub.Add2.Add1(), Sub.Add2.Add2() :' )
Sub.Add2.Add1()
Sub.Add2.Add2()

print( "import Add2, call by 'object'.function name :" )
Add2.Add1()
Add2.Add2()
#Sub/Add2.py
def Add1():
    print( "Sub.Add2.py : Add1() ", 1 + 1 )

def Add2():
    print( "Sub.Add2.py : Add2() ", 2 + 2 )

Add2.py in current folder :

#Add2.py
def Add1():
    print( "Add2.py : Add1() ", 1 + 1 + 1 )

def Add2():
    print( "Add2.py : Add2() ", 2 + 2 + 2 )

> python Test3.py
from Sub.Add2 import Add1 as SubAdd1, call SubAdd1 :
Sub.Add2.py : Add1()  2
import Sub.Add2, call Sub.Add2.Add1(), Sub.Add2.Add2() :
Sub.Add2.py : Add1()  2
Sub.Add2.py : Add2()  4
import Add, call by 'object'.function name :
Add2.py : Add1()  3
Add2.py : Add2()  6
Flash Ang
  • 192
  • 2
  • 6
  • "python X" is a third party pure python package that has .py files but those .py files makes use of software Y which is not python – Kalyan Kumar Nov 12 '20 at 04:25
  • You may refer to these : [link]https://stackoverflow.com/questions/4383571/importing-files-from-different-folder[/link] Importing files from different folder [link]https://stackoverflow.com/questions/43476403/importerror-no-module-named-something[/link] ImportError: No module named – Flash Ang Nov 12 '20 at 07:21