简体   繁体   中英

how to use PYTHONPATH for independent python application

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM