0

I am trying to run/debug my python project from IntelliJ Ultimate 2018.1. I have defined a python SDK, a Django local server (as the project uses Django as a template language), the PYTHONPATH is properly defined, etc. If I execute

python manage.py runserver

from my MacOS terminal, the server starts normally. When I am trying to run my IntelliJ configuration, it fails, with message:

 /usr/bin/python2.7 -d /Users/my_user/dev/github/my_project/manage.py runserver 8000
Traceback (most recent call last):
  File "/Users/my_user/dev/github/my_project/manage.py", line 19, in <module>
    paths = importlib.import_module('settings.' + server + '.paths')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/my_user/dev/github/my_project/settings/__init__.py", line 11, in <module>
    paths = importlib.import_module('my_project.settings.' + server + '.paths')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named my_project.settings.local.paths

The settings.local folder does contains the __init__.py file, and also settings folder and the root folder of my project. Doing a few hours of research over the internet I have realised that the main problem is to include local modules on the classpath, so they are available for server startup. For PyCharm, this is clearly explained here, and I was able to run the server from PyCharm. However, when trying to do the same thing in IntelliJ, this never works. Some people write about it here for example, but that didn't worked out for me.

I have tried using a system interpreter and also a virtual environment, created with PyCharm, with no luck. I am using python 2.7, Django 1.11 and MacOS High Sierra. Is this even possible with IntelliJ? I wonder why would people buy PyCharm if the same things can be accomplished (and so much more) with IntelliJ. Also, I have noticed that when I change a setting in IntelliJ run profile (the Django local server profile), this change is reflected back in PyCharm and viceversa. This seems to me like a bug from JetBrains, as two distinct apps somehow share the same config, probably due to the fact that the same project is loaded in both apps.

hypercube
  • 958
  • 2
  • 16
  • 34
  • Hi. Where exacty do you store ``my_project``? Could you please provide your project layout/structure and Django facet settings? – user996142 Apr 17 '18 at 14:54
  • The my_project folder is the root of the project. The settings.local.paths missing module is a folder from the project. Django facet is as follows: - Django project root: Users/my_user/dev/github/my_project - Settings: settings/local/settings.py - Do not use Django test runner: unchecked - Manage script: manage.py (located in the root of my_project) - Environment variables: none specified there - Folder path to track files: migrations Enable framework detection: checked. – hypercube Apr 18 '18 at 10:11

1 Answers1

1

The problem was in fact trivial, as clarified with JetBrains support: I needed to set the parent folder of my_project as content root (/Users/my_user/dev/github/), instead of using /Users/my_user/dev/github/my_project/ directly. This was needed because the source code contained imports from module my_project which could not be resolved, as there was no subfolder my_project inside of my main project folder. I implemented this change in Project settings -> Modules view, Project settings -> Facets view and also in the run configuration.

hypercube
  • 958
  • 2
  • 16
  • 34