Reputation: 21
Can anyone let me know how to set PYTHONPATH?
Do we need to set it in the environment variables (is it system specific) or we can independently set the PYTHONPATH and use it to run any independent python application?
i need to pick the module from a package available in directory which is different from the directory from which I am running my application . How to include these packages in my application
Upvotes: 0
Views: 452
Reputation: 25769
Instead of messing with system environment variables and paths set therein, if you only need to add a specific directory to the module lookup path of your application use:
import sys
sys.path.append("path/to/your/packages")
It's not recommended to mess with your paths in general - if you have to, you should probably rethink your application design - but if you still decide that you have to, this is more preferable than messing with system paths.
Upvotes: 0
Reputation: 161
I assume you are using Linux
Before executing your application u can metion pythonpath=path && execution script
Other elegant way is using virtualenv. Where u can have diff packages for each application. Before exection say workon env and then deactivate
Python3 has virtualenv by default
Upvotes: 1