How can I call python module inside version package folder?
I need to write python codes that run inside a host application. The python codes need to be deployed under a specific folder of the host application. I have to put my python input module under the root of a specific folder. And I want to put all my other python and c / c ++ dll codes under a sub folder, I prefer to name the sub folder like XXX-1.0, the number is the version of my python codes. The python login module is just simple to call the python module in a sub folder.
In this way, different python codebases can be deployed together without collision. May I know if this is possible or not? Thanks.
a source to share
I'm not sure if I understand your question correctly, but here is an easy way to have multiple versions of a package without collisions.
Directory structure:
C:\tmp\eggs>dir /B /S
C:\tmp\eggs\libs
C:\tmp\eggs\test.py
C:\tmp\eggs\libs\foo-1.0.egg
C:\tmp\eggs\libs\foo-2.0.egg
C:\tmp\eggs\libs\foo-1.0.egg\foo.py
C:\tmp\eggs\libs\foo-2.0.egg\foo.py
Now the contents of the files:
# contents of C:\tmp\eggs\libs\foo-1.0.egg\foo.py
version=(1,0)
# contents of C:\tmp\eggs\libs\foo-2.0.egg\foo.py
version=(2,0)
#contents of C:\tmp\eggs\test.py:
import sys
sys.path.insert(1, 'libs')
from pkg_resources import require
require('foo<1.5')
import foo
print foo.version
# will output (1,0)
If you change 'foo<1.5'
to 'foo>1.5'
, or the 'foo'
output changes to(2,0)
You will find details in the setuptools documentation.
a source to share
If you created a file .pth
eg. X.pth
And put XXX-1.0
inside as content
XXX-1.0\
- xxx.py
X.pth
Then you could import xxx
Note : only checked in the site-packages folder, I'm not sure if you could put your subfolder anywhere.
Edit : For example wxPython does this as it can have multiple versions on the same machine.
wx-2.8-msw-unicode \
wx
\
more stuff
wx.pth (wx-2.8-msw-unicode)
a source to share