Pycharm error Django is not importable in this environment

前端 未结 17 1038
情话喂你
情话喂你 2021-02-01 13:00

I\'m getting the following errors in Pycharm.

Error: Django is not importable in this environment

It used to work well but I moved t

相关标签:
17条回答
  • 2021-02-01 13:05

    I had the same problem and it was due to having more than one project interpreter defined in the project. In my case I had a python 2.7 and a python 3.7 interpreter. Fixed this issue by removing the python 2.7 interpreter.

    1. View the current interpreter by navigating to Preferences > Project > Project Interpreter

    2. Open the dropdown and select Show All...

    3. Remove any interpreters that aren't your primary
    0 讨论(0)
  • 2021-02-01 13:08

    In my case I had to go to Settings (Alt+F7, or the Spanner/Cog icon) and select a Python interpreter which has Django installed alongside it.

    If Django isn't already installed, you should be able to install it via the + (plus) icon (not shown below) once an interpreter has been selected.

    0 讨论(0)
  • 2021-02-01 13:08

    I had the same problem and I think the solution is not stated here yet. I had to go to Settings > Project Interpreter, click the gears icon on the right and chose the interpreter (which was already correct). Then click on the last icon to the right, the one with some folders structure icon. There I had to add the path to the site-packages of my venv (where Django is). Finally my tests run with no issues.

    0 讨论(0)
  • 2021-02-01 13:09

    For people having selected a virtualenv/interpreter that HAS Django installed (but it might have changed python version since first selection...), and even re-installed Django, and still get this message, and slowly getting crazy: Hit File > Invalidate Caches / Restart ....

    This solved it for me.

    Also, keeping the list of available interpreters clean and correct always helps (on my linux, old interpreters of previous linux installations kept popping up...whaat), as well as not using special characters in virtualenv names (as was the OPs problem...see his answer).

    0 讨论(0)
  • 2021-02-01 13:09

    It might seem obvious, but try quitting and then re-starting the PyCharm application. When I had this issue, I continued to get the "Django is not importable in this environment" error even though the project interpreter path was correct. Nothing worked until I closed and re-opened the application. Hope this saves someone some time.

    0 讨论(0)
  • 2021-02-01 13:11

    you have to edit your project configuration for that. Environemt->Environment variables set varable DJANGO_SETTINGS_MODULE=project_name.settings

    0 讨论(0)
提交回复
热议问题