If I put a *.pth file in site-packages it's giving an ImportError
.
I'm not getting how to import by creating a *.pth file.
(Refers to importing in python)
append() Function. This is the easiest way to import a Python module by adding the module path to the path variable. The path variable contains the directories Python interpreter looks in for finding modules that were imported in the source files.
__file__ is a variable that contains the path to the module that is currently being imported. Python creates a __file__ variable for itself when it is about to import a module.
Setting path at Unix/LinuxIn the csh shell − type setenv PATH "$PATH:/usr/local/bin/python" and press Enter. In the bash shell (Linux) − type export PATH="$PATH:/usr/local/bin/python" and press Enter. In the sh or ksh shell − type PATH="$PATH:/usr/local/bin/python" and press Enter.
The easiest way to change it is to add a file /usr/local/lib/python2. 6/dist-packages/site-packages. pth containing ../site-packages . Alternatively, maybe you can teach the package to use site.
If you put a .pth
file in the site-packages
directory containing a path, python searches this path for imports. So I have a sth.pth
file there that simply contains:
K:\Source\Python\lib
In that directory there are some normal Python modules:
logger.py
fstools.py
...
This allows to directly import these modules from other scripts:
import logger
log = logger.Log()
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With