15👍
I finally found the error. The problem was that one folder name in the virtualenv path had an accent.
This is the old path:
/Users/plorenzo/../telefónica/gestorSchools/venv
This is the new one that works:
/Users/plorenzo/../telefonica/gestorSchools/venv
81👍
Yet another case, where my virtualenv did have Django installed, but Pycharm would still display this error.
I eventually found out that the same virtualenv path had been duplicated in the list of available interpreters. Removing all of them and re-adding fixed it.
The duplication happened after I copied the .idea from another machine, and re-created the virtualenv from Pycharm although it was already listed as a (broken) interpreter.
- [Django]-Best practices for adding .gitignore file for Python projects?
- [Django]-Django check for any exists for a query
- [Django]-Django return file over HttpResponse – file is not served correctly
57👍
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.
- [Django]-How to expire session due to inactivity in Django?
- [Django]-How to drop all tables from the database with manage.py CLI in Django?
- [Django]-NumPy array is not JSON serializable
35👍
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:
File > Invalidate Caches / Restart ...
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). Messing with the .idea
folder also is not recommended (dont copy it to your new computer ;-).
- [Django]-Explicitly set MySQL table storage engine using South and Django
- [Django]-Django admin: How to display the field marked as "editable=False" in the model?
- [Django]-How to find pg_config path
17👍
Project interpreter, which is being used in the pycharm
setting , doesn’t have the django
package installed. So go to
setting->Project->project interpreter
Then install django
package
it will work 🙂
- [Django]-Django: Reference to an outer query may only be used in a subquery
- [Django]-Django models: default value for column
- [Django]-How to run celery as a daemon in production?
11👍
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.
-
View the current interpreter by navigating to
Preferences > Project > Project Interpreter
-
Open the dropdown and select
Show All...
- Remove any interpreters that aren’t your primary
- [Django]-Django – Static file not found
- [Django]-How to use "get_or_create()" in Django?
- [Django]-How to spread django unit tests over multiple files?
9👍
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.
- [Django]-How to stop autopep8 not installed messages in Code
- [Django]-How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?
- [Django]-How to get the currently logged in user's id in Django?
3👍
I got the same issue on OS X, and to fix it, I had to use an absolute path for the project interpreter
/Users/myself/Projects/… is ok
~/Projects/… was not working
- [Django]-Disable a method in a ViewSet, django-rest-framework
- [Django]-Django create userprofile if does not exist
- [Django]-URL-parameters and logic in Django class-based views (TemplateView)
2👍
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.
- [Django]-Alowing 'fuzzy' translations in django pages?
- [Django]-How to specify an IP address with Django test client?
- [Django]-Referencing multiple submit buttons in django
2👍
I had the same problem in Pycharm
.
I fixed it by removing
the old Run/Debug Configurations and then create
another one.
Before that make sure to install Django if you haven’t already.
It is better to clear caches by going File > Invalidate Caches / Restart ...
to be more sure.
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
- [Django]-Django – Circular model import issue
- [Django]-Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:
1👍
I had similar problem…
I go PyCharm -> Preferences and tried to readd Django to project interpreter packages. PyCharm suddenly added everything in requirements.txt file. And now I can run project without any problem.
- [Django]-"Too many values to unpack" Exception
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-Manager isn't available; User has been swapped for 'pet.Person'
1👍
In my case, I was running the Cygwin version of Python when this error came up. Fixing it involved just adding some of cygwin’s bin paths to Window’s Path variable.
Run “control sysdm.cpl”
Go to the “Advanced” tab
Click the “Environmental Variables” button at the bottom of this tab
Find “Path” under “System Variables”
Add to it
;c:/cygwin/bin;c:/cygwin/sbin;c:/cygwin/usr/local/bin
I did not include /usr/bin, as for some reason, it is combined in to the /bin directory when viewing in windows.
- [Django]-How do I reuse HTML snippets in a django view
- [Django]-Retrieving a Foreign Key value with django-rest-framework serializers
- [Django]-Django Model() vs Model.objects.create()
1👍
Ok, in my case the solution was:
- Install django
- Use @cbueche suggestion to remove the ~
- Switch to a another project’s venv and switch back to my venv for this project
I exited and reloaded the project a few times in there so that might also be necessary. I love PyCharm but starting a new project is always painful.
- [Django]-ImportError: Couldn't import Django
- [Django]-Django – How to pass several arguments to the url template tag
- [Django]-STATIC_ROOT vs STATIC_URL in Django
1👍
As everybody said ,Check for your interpreter
Was it properly configured it or not.If you created your project in virtual environment ,make sure you configured the correct python interpreter or not .The python interpreter(whole) and python interpreter(for only single project using virtualenv) are different .
If you are using PyCharm
Go to Setting->Project->project interpreter and pick the right interpreter
Once you are done with that ,run the project if it runs,all set .if not check for the Edit configurations and check again for the interpreter
- [Django]-What’s the difference between a project and an app in Django world?
- [Django]-Django – Overriding the Model.create() method?
- [Django]-How to show processing animation / spinner during ajax request?
0👍
you have to edit your project configuration for that.
Environemt->Environment variables set varable DJANGO_SETTINGS_MODULE=project_name.settings
- [Django]-"<Message: title>" needs to have a value for field "id" before this many-to-many relationship can be used.
- [Django]-What's the idiomatic Python equivalent to Django's 'regroup' template tag?
- [Django]-Django DoesNotExist
0👍
I kept getting this error even after following suggestions made in other answers, like deleting .idea folder, reinstalling packages from settings->project interpreter.
Finally, I took the venv out of the project folder and created a venev beside the project folder and deleted .idea folder from project folder.
Then I opened the project and chose the interpreter as the newly created venv
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-How to get Django and ReactJS to work together?
- [Django]-Pylint "unresolved import" error in Visual Studio Code
0👍
steps :
1. Choose File Option
2. Setting
3. Scroll to Project -> Select Python Interpreter
4. Project Interpreter
5. Click on Setting icon and press Add environment
6. Create a Virtual Environment
- [Django]-How to limit the maximum value of a numeric field in a Django model?
- [Django]-Celery missed heartbeat (on_node_lost)
- [Django]-Django: Using F arguments in datetime.timedelta inside a query
0👍
I had the same error. Try to name path (and project) without "_":
../my_project/venv -> ../my-project/venv
- [Django]-Django: Multiple forms possible when using FormView?
- [Django]-Django's self.client.login(…) does not work in unit tests
- [Django]-Get object by field other than primary key
0👍
1 Everybody recommend you to check your Interpreter PATH to your venv-folder (virtual environment) in PyCharm:
Settings (Ctrl+Alt+S) –> Project: project_name –> Python Interpreter –> gear_icon (settings) –> Show All… –> press ‘+’ to add interpreter with correct path to venv –> Apply –> Ok
2 I also recommend you to try my kung-foo AFTER you done previous:
same steps… –> Show All… –> press ‘folder-tree icon’ (Show paths for the selected interpreter) –> press ‘+’ to add new path –> select path to this folder ‘../venv/Lib/site-packages’
Do that and you’ll be extra-happy!
- [Django]-Django: How to check if the user left all fields blank (or to initial values)?
- [Django]-Suddenly when running tests I get "TypeError: 'NoneType' object is not iterable
- [Django]-Printing Objects in Django