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

2

There are 2 answers

0
adamJLev On

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

0
Julian A. On

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