I have my own package in python and I am using it very often. what is the most elegant or conventional directory where i should put my package so it is going to be imported without playing with PYTHONPATH or sys.path?
What about site-packages for example? /usr/lib/python2.7/site-packages
.
Is it common in python to copy and paste the package there ?
For the most part, modules are just Python scripts that are stored in your Lib or Lib/site-packages folder, or local to the script being run. That's it.
Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
Python looks for modules in “sys. It looks for a file called a_module.py in the directories listed in the variable sys.
I usually put the stuff i want to have ready to import in the user site directory:
~/.local/lib/pythonX.X/site-packages
To show the right directory for your platform, you can use python -m site --user-site
edit: it will show up in sys.path
once you create it:
mkdir -p "`python -m site --user-site`"
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