开发者

WIth PyCharm, why is the PYTHONPATH when running a Django project different from when running the manage.py syncdb task?

Shouldn't it be the same by default? If not,开发者_StackOverflow is there some way to fix this so that the same PYTHONPATH is used?


This may not be the ideal solution, but it works, and comes courtesy of my boss.

Modify pycharm's django_manage.py, inserting the following code at the top, before all existing code. django_manage.py can be found at [PyCharm install directory]/helpers/pycharm/django_manage.py.

import site
import sys

# Add the locations missing from PYTHONPATH when running a manage.py task here.
ALLDIRS = [
    r'C:\git_repos\src\dev\common\py',
    r'C:\git_repos\src\dev\main_website',
]

# Remember original sys.path.

prev_sys_path = list(sys.path)

# Add each new site-packages directory.

for directory in ALLDIRS:
    site.addsitedir(directory)

# Reorder sys.path so new directories at the front.

new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path


Did you select the right python install for your project in Settings > Python Interpreter?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜