pycharm unable to load django apps












0















In The PyCharm I have Django configured in virtual environment, what I did is:




  1. Previously I had python 3.6 on my windows 10 so I uninstalled it and

  2. Installed Python 3.7

  3. pip install virtualenv


  4. vertualenv venv and then activated it

  5. pip install django

  6. also installed djangorestframework, coreapi and requests via pip

  7. django-admin startproject hasslefreeaccounts

  8. opened project in PyCharm, then: Files > settings > Language &
    Framework
    and Configured my project as:

  9. entered project root, settings.py and manage.py path (see image below)


enter image description here



and then created 2 apps named customer and master

and then configured the run configurations as:



enter image description here



after this (am using pycharm professional) everything works fine except while importing apps PyCharm Gives me error when I import my django apps in other as:



from masters.models import some_class


pycharm says cant find module, thought when I run project it works fine with no error.

so I tried doing:



from ..master.models import some_class


This makes PyCharm import apps (see image below)



enter image description here



this in pycharm doesn't shows any error but on run gives error as:



ValueError: attempted relative import beyond top-level package


Other Details:



and here is the project interpreter settings:



enter image description here



and Settings.py as:



import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'KEY_HERE'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'customers',
'masters',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'hasslefreeaccounts.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)

}

WSGI_APPLICATION = 'hasslefreeaccounts.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC' # 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'


UPDATED:



Basically PyCharm is reading my apps one directory above

I have tried updating my project source root to one directory above as well, but that doesn't help, in project interpreter settings










share|improve this question





























    0















    In The PyCharm I have Django configured in virtual environment, what I did is:




    1. Previously I had python 3.6 on my windows 10 so I uninstalled it and

    2. Installed Python 3.7

    3. pip install virtualenv


    4. vertualenv venv and then activated it

    5. pip install django

    6. also installed djangorestframework, coreapi and requests via pip

    7. django-admin startproject hasslefreeaccounts

    8. opened project in PyCharm, then: Files > settings > Language &
      Framework
      and Configured my project as:

    9. entered project root, settings.py and manage.py path (see image below)


    enter image description here



    and then created 2 apps named customer and master

    and then configured the run configurations as:



    enter image description here



    after this (am using pycharm professional) everything works fine except while importing apps PyCharm Gives me error when I import my django apps in other as:



    from masters.models import some_class


    pycharm says cant find module, thought when I run project it works fine with no error.

    so I tried doing:



    from ..master.models import some_class


    This makes PyCharm import apps (see image below)



    enter image description here



    this in pycharm doesn't shows any error but on run gives error as:



    ValueError: attempted relative import beyond top-level package


    Other Details:



    and here is the project interpreter settings:



    enter image description here



    and Settings.py as:



    import os

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = 'KEY_HERE'

    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = True

    ALLOWED_HOSTS = ['*']


    # Application definition

    INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'customers',
    'masters',
    ]

    MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]

    ROOT_URLCONF = 'hasslefreeaccounts.urls'

    TEMPLATES = [
    {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
    'context_processors': [
    'django.template.context_processors.debug',
    'django.template.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
    ],
    },
    },
    ]

    REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
    'rest_framework.permissions.IsAuthenticated',
    )

    }

    WSGI_APPLICATION = 'hasslefreeaccounts.wsgi.application'


    # Database
    # https://docs.djangoproject.com/en/2.1/ref/settings/#databases

    DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
    }


    # Password validation
    # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

    AUTH_PASSWORD_VALIDATORS = [
    {
    'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
    'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
    'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
    'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
    ]


    # Internationalization
    # https://docs.djangoproject.com/en/2.1/topics/i18n/

    LANGUAGE_CODE = 'en-us'

    TIME_ZONE = 'UTC' # 'Asia/Kolkata'

    USE_I18N = True

    USE_L10N = True

    USE_TZ = True


    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/2.1/howto/static-files/

    STATIC_URL = '/static/'

    STATIC_ROOT = os.path.join(BASE_DIR, "static/")

    MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
    MEDIA_URL = '/media/'


    UPDATED:



    Basically PyCharm is reading my apps one directory above

    I have tried updating my project source root to one directory above as well, but that doesn't help, in project interpreter settings










    share|improve this question



























      0












      0








      0








      In The PyCharm I have Django configured in virtual environment, what I did is:




      1. Previously I had python 3.6 on my windows 10 so I uninstalled it and

      2. Installed Python 3.7

      3. pip install virtualenv


      4. vertualenv venv and then activated it

      5. pip install django

      6. also installed djangorestframework, coreapi and requests via pip

      7. django-admin startproject hasslefreeaccounts

      8. opened project in PyCharm, then: Files > settings > Language &
        Framework
        and Configured my project as:

      9. entered project root, settings.py and manage.py path (see image below)


      enter image description here



      and then created 2 apps named customer and master

      and then configured the run configurations as:



      enter image description here



      after this (am using pycharm professional) everything works fine except while importing apps PyCharm Gives me error when I import my django apps in other as:



      from masters.models import some_class


      pycharm says cant find module, thought when I run project it works fine with no error.

      so I tried doing:



      from ..master.models import some_class


      This makes PyCharm import apps (see image below)



      enter image description here



      this in pycharm doesn't shows any error but on run gives error as:



      ValueError: attempted relative import beyond top-level package


      Other Details:



      and here is the project interpreter settings:



      enter image description here



      and Settings.py as:



      import os

      # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
      BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

      # SECURITY WARNING: keep the secret key used in production secret!
      SECRET_KEY = 'KEY_HERE'

      # SECURITY WARNING: don't run with debug turned on in production!
      DEBUG = True

      ALLOWED_HOSTS = ['*']


      # Application definition

      INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'rest_framework',
      'rest_framework.authtoken',
      'customers',
      'masters',
      ]

      MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
      ]

      ROOT_URLCONF = 'hasslefreeaccounts.urls'

      TEMPLATES = [
      {
      'BACKEND': 'django.template.backends.django.DjangoTemplates',
      'DIRS': [os.path.join(BASE_DIR, 'templates')],
      'APP_DIRS': True,
      'OPTIONS': {
      'context_processors': [
      'django.template.context_processors.debug',
      'django.template.context_processors.request',
      'django.contrib.auth.context_processors.auth',
      'django.contrib.messages.context_processors.messages',
      ],
      },
      },
      ]

      REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': (
      'rest_framework.authentication.TokenAuthentication',
      ),
      'DEFAULT_PERMISSION_CLASSES': (
      'rest_framework.permissions.IsAuthenticated',
      )

      }

      WSGI_APPLICATION = 'hasslefreeaccounts.wsgi.application'


      # Database
      # https://docs.djangoproject.com/en/2.1/ref/settings/#databases

      DATABASES = {
      'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
      }


      # Password validation
      # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

      AUTH_PASSWORD_VALIDATORS = [
      {
      'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
      'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
      'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
      'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
      ]


      # Internationalization
      # https://docs.djangoproject.com/en/2.1/topics/i18n/

      LANGUAGE_CODE = 'en-us'

      TIME_ZONE = 'UTC' # 'Asia/Kolkata'

      USE_I18N = True

      USE_L10N = True

      USE_TZ = True


      # Static files (CSS, JavaScript, Images)
      # https://docs.djangoproject.com/en/2.1/howto/static-files/

      STATIC_URL = '/static/'

      STATIC_ROOT = os.path.join(BASE_DIR, "static/")

      MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
      MEDIA_URL = '/media/'


      UPDATED:



      Basically PyCharm is reading my apps one directory above

      I have tried updating my project source root to one directory above as well, but that doesn't help, in project interpreter settings










      share|improve this question
















      In The PyCharm I have Django configured in virtual environment, what I did is:




      1. Previously I had python 3.6 on my windows 10 so I uninstalled it and

      2. Installed Python 3.7

      3. pip install virtualenv


      4. vertualenv venv and then activated it

      5. pip install django

      6. also installed djangorestframework, coreapi and requests via pip

      7. django-admin startproject hasslefreeaccounts

      8. opened project in PyCharm, then: Files > settings > Language &
        Framework
        and Configured my project as:

      9. entered project root, settings.py and manage.py path (see image below)


      enter image description here



      and then created 2 apps named customer and master

      and then configured the run configurations as:



      enter image description here



      after this (am using pycharm professional) everything works fine except while importing apps PyCharm Gives me error when I import my django apps in other as:



      from masters.models import some_class


      pycharm says cant find module, thought when I run project it works fine with no error.

      so I tried doing:



      from ..master.models import some_class


      This makes PyCharm import apps (see image below)



      enter image description here



      this in pycharm doesn't shows any error but on run gives error as:



      ValueError: attempted relative import beyond top-level package


      Other Details:



      and here is the project interpreter settings:



      enter image description here



      and Settings.py as:



      import os

      # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
      BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

      # SECURITY WARNING: keep the secret key used in production secret!
      SECRET_KEY = 'KEY_HERE'

      # SECURITY WARNING: don't run with debug turned on in production!
      DEBUG = True

      ALLOWED_HOSTS = ['*']


      # Application definition

      INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'rest_framework',
      'rest_framework.authtoken',
      'customers',
      'masters',
      ]

      MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
      ]

      ROOT_URLCONF = 'hasslefreeaccounts.urls'

      TEMPLATES = [
      {
      'BACKEND': 'django.template.backends.django.DjangoTemplates',
      'DIRS': [os.path.join(BASE_DIR, 'templates')],
      'APP_DIRS': True,
      'OPTIONS': {
      'context_processors': [
      'django.template.context_processors.debug',
      'django.template.context_processors.request',
      'django.contrib.auth.context_processors.auth',
      'django.contrib.messages.context_processors.messages',
      ],
      },
      },
      ]

      REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': (
      'rest_framework.authentication.TokenAuthentication',
      ),
      'DEFAULT_PERMISSION_CLASSES': (
      'rest_framework.permissions.IsAuthenticated',
      )

      }

      WSGI_APPLICATION = 'hasslefreeaccounts.wsgi.application'


      # Database
      # https://docs.djangoproject.com/en/2.1/ref/settings/#databases

      DATABASES = {
      'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
      }


      # Password validation
      # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

      AUTH_PASSWORD_VALIDATORS = [
      {
      'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
      'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
      'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
      'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
      ]


      # Internationalization
      # https://docs.djangoproject.com/en/2.1/topics/i18n/

      LANGUAGE_CODE = 'en-us'

      TIME_ZONE = 'UTC' # 'Asia/Kolkata'

      USE_I18N = True

      USE_L10N = True

      USE_TZ = True


      # Static files (CSS, JavaScript, Images)
      # https://docs.djangoproject.com/en/2.1/howto/static-files/

      STATIC_URL = '/static/'

      STATIC_ROOT = os.path.join(BASE_DIR, "static/")

      MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
      MEDIA_URL = '/media/'


      UPDATED:



      Basically PyCharm is reading my apps one directory above

      I have tried updating my project source root to one directory above as well, but that doesn't help, in project interpreter settings







      python django pycharm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 5:10







      Aashish Gahlawat

















      asked Nov 22 '18 at 4:50









      Aashish GahlawatAashish Gahlawat

      991112




      991112
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Not sure of but this helped me!



          enter image description here



          As in the image shown, the virtualenv shall be within the project directory and not outside, this helpe me!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424078%2fpycharm-unable-to-load-django-apps%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Not sure of but this helped me!



            enter image description here



            As in the image shown, the virtualenv shall be within the project directory and not outside, this helpe me!






            share|improve this answer




























              0














              Not sure of but this helped me!



              enter image description here



              As in the image shown, the virtualenv shall be within the project directory and not outside, this helpe me!






              share|improve this answer


























                0












                0








                0







                Not sure of but this helped me!



                enter image description here



                As in the image shown, the virtualenv shall be within the project directory and not outside, this helpe me!






                share|improve this answer













                Not sure of but this helped me!



                enter image description here



                As in the image shown, the virtualenv shall be within the project directory and not outside, this helpe me!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 5:35









                Aashish GahlawatAashish Gahlawat

                991112




                991112
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424078%2fpycharm-unable-to-load-django-apps%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    Npm cannot find a required file even through it is in the searched directory