sys.path

Add a directory to Python sys.path so that it's included each time I use Python

核能气质少年 提交于 2019-11-26 20:16:14
问题 Currently, when trying to reference some library code, I'm doing this at the top of my python file: import sys sys.path.append('''C:\code\my-library''') from my-library import my-library Then, my-library will be part of sys.path for as long as the session is active. If I start a new file, I have to remember to include sys.path.append again. I feel like there must be a much better way of doing this. How can I make my-library available to every python script on my windows machine without having

PYTHONPATH vs. sys.path

我怕爱的太早我们不能终老 提交于 2019-11-26 17:09:26
Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory. We have a Python project with a typical directory structure: Project setup.py package __init__.py lib.py script.py In script.py, we need to do import package.lib . When the package is installed in site-packages, script.py can find package.lib . When working from a user directory, however, something else needs to be done. My solution is to set my PYTHONPATH to include "~/Project". Another developer wants to put this line of code

PYTHONPATH vs. sys.path

泄露秘密 提交于 2019-11-26 06:04:49
问题 Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory. We have a Python project with a typical directory structure: Project setup.py package __init__.py lib.py script.py In script.py, we need to do import package.lib . When the package is installed in site-packages, script.py can find package.lib . When working from a user directory, however, something else needs to be done. My