When I run the tests (in the pycharm environment) I get an error ModuleNotFoundError: No module named 'django'. Django installed (2.2.5)
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
File "/home/m0nte-cr1st0/projects/slack_bot/tests.py", line 4, in <module>
from app.models import *
File "/home/m0nte-cr1st0/projects/slack_bot/app/models.py", line 1, in <module>
from django.db import models
ModuleNotFoundError: No module named 'django'
You probably have not configured your PyCharm Project to use your virtualenv for tests.
In your Run/Debug configurations (the dropdown next to the run button), select "Edit Configurations".
Find your test configuration and check the value for "Python Interpreter". If should be something like /home/m0nte-cr1st0/.virtualenvs/slack_bot/bin/python, but probably it is something like /usr/bin/python3.6
If it is in the list, select /home/m0nte-cr1st0/.virtualenvs/slack_bot/bin/python. Otherwise, you have to add a new interpreter.
To add an interpreter, look at the status bar on the bottom right. It should say "Python 3.6". If you click on it, there should be an option to add an interpreter.
Related
Hello fellow programmers, I´m following the steps to install django-fluent-contents
from the link
https://django-fluent-contents.readthedocs.io/en/latest/ quickstart.html
1- pip install django-fluent-contents
2- Basic setup
Next, create a project which uses the module. The basic module can be installed and optional plugins can be added:
INSTALLED_APPS += (
'fluent_contents',
'django_wysiwyg',
# And optionally add the desired plugins:
'fluent_contents.plugins.text', # requires django-wysiwyg
'fluent_contents.plugins.code', # requires pygments
'fluent_contents.plugins.gist',
'fluent_contents.plugins.googledocsviewer',
'fluent_contents.plugins.iframe',
'fluent_contents.plugins.markup',
'fluent_contents.plugins.rawhtml',
)
3- pip install django-fluent-contents[text,code]
4- then running python manage.py migrate
and then, error message:
D:\projetos\fluent\fluentdemo>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 381, in RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
I´ve tried with and without virtual enviroment activated, same error message!!
.......then I followed the advice of #solarissmoke, adding the django.contrib.site to INSTALLED_APPS .... but now the error message is like this:
"D:\projetos\fluent\fluentdemo\fluentdemo\veenv\lib\site-packages\fluent_contents\plugins\markup\models.py", line 10, in <module>
from fluent_contents.plugins.markup import appsettings, backend
File "D:\projetos\fluent\fluentdemo\fluentdemo\veenv\lib\site-packages\fluent_contents\plugins\markup\appsettings.py", line 34, in <module>
raise ImproperlyConfigured("The '{0}' package is required to use the '{1}' language for the '{2}' plugin.".format(backendapp, language, 'markup'))
django.core.exceptions.ImproperlyConfigured: The 'docutils' package is required to use the 'restructuredtext' language for the 'markup' plugin.
It doesn't seem to be mentioned in the documentation, but this app requires django.contrib.sites to be installed, and you're getting an error because it isn't.
Try adding django.contrib.sites to your INSTALLED_APPS.
I am getting following error
D:\pythongui>C:\Python27\python.exe D:/pythongui/controller/MainController.py
Traceback (most recent call last):
File "D:/pythongui/controller/MainController.py", line 5, in <module>
from view.MainView import Launcher
ImportError: No module named view.MainView
when I am executing the following command in terminal
C:\Python27\python.exe D:/pythongui/controller/MainController.py
But the same code is working in pycharm without any error.
My Directory structure is as follows :
I have tried following code
import GetMyIp as getMyIP
import sys
sys.path.append("view/MainView")
import Server as server
import view.MainView
I am working through the PYcharm tutorial, which sets up a polling site, as my first Python/Django project. I am new to this so if I am asking silly questions I apologize in advance. In the admin.py file the following import is not working:
from MyDjangoApp.polls.models import Poll, Choice
I have specified the environment variable as I found in other posts to
DJANGO_SETTINGS_MODULE MyDjangoApp.settings
with MyDjangoApp being my project name and MyDjangoApp.settings as the value in the Edit Configurations tab.
I also tried to follow the lightbulb suggestion to install package models but when I do that I get the following error:
Error occurred when installing packages.
The following command was executed:
packaging_tool.py install --build-dir /tmp/pycharm packaging1986982253689628475.tmp
models
The error output of the command:
Downloading/unpacking models
Downloading models-0.9.3.tar.gz
Running setup.py egg_info for package models
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/tmp/pycharm-packaging1986982253689628475.tmp/models/setup.py", line 25, in
<module>
import models
File "models/__init__.py", line 24, in <module>
from props import *
File "models/props.py", line 23, in <module>
import yaml
ImportError: No module named yaml
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/tmp/pycharm-packaging1986982253689628475.tmp/models/setup.py", line 25, in
<module>
import models
File "models/__init__.py", line 24, in <module>
from props import *
File "models/props.py", line 23, in <module>
import yaml
ImportError: No module named yaml
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pycharm
-packaging1986982253689628475.tmp/models
Storing complete log in /home/andrew/.pip/pip.log
I am not sure how to proceed. I have seen a decent amount of suggestions but they either don't work or I'm not doing it correctly. If anyone has any suggestions I would greatly appreciate it. I have been banging my head against this wall most of the day today and I would really like to be able to move forward. Thanks is advance for anyone willing to help out a newbie.
In polls/admin.py do from models import Poll, Choice - this is presuming you have a models.py file next to admin.py.
I receive the following error when trying to run a shell command using Python Tool for Visual Studio. I have added the database to the settings file, and have been able to run the django app without errors, but when I try to add data using the shell, it throws this error:
>>> from ProjectTrackerServer.projects.models import Project
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\djangoapps\ProjectTrackerServer\ProjectTrackerServer\projects\models.py", line 1, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in inner
self._setup()
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
The error states the issue. It occurred because you forgot to supply the project setting DJANGO_SETTINGS_MODULE. You can fix it by supplying it. You need to set the DJANGO_SETTINGS_MODULE environment variable.
When you use Django, you have to tell it which settings
you're using. Do this by using an environment variable,
DJANGO_SETTINGS_MODULE.
The value of DJANGO_SETTINGS_MODULE should be in
Python path syntax, e.g. mysite.settings. Note
that the settings module should be on the
Python import search path.
https://docs.djangoproject.com/en/dev/topics/settings/
I have the DJANGO_SETTINGS_MODULE problem. I am using Pycharm and under Project Settings -> Django Support everything is set and enabled. Nevertheless I get following error while trying do an import in models.py:
from django.db import models
C:\Python27\python.exe C:/Users/Grimbo/PycharmProjects/Muspy/poll/models.py
Traceback (most recent call last):
File "C:/Users/Grimbo/PycharmProjects/Mus/poll/models.py", line 1, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in inner
self._setup()
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
print(sys.path):
['C:\\Program Files (x86)\\JetBrains\\PyCharm 2.6.3\\helpers\\pydev', 'C:\\WINDOWS\\SYSTEM32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Users\\Grimbo\\PycharmProjects\\Mus']
Does someone has an idea what's wrong?
Check out this link. Specifically, you want to set the Environmental Variable in the configuration. By default, you will see PYTHONBUFFERED = 1, and you will want to add DJANGO_SETTINGS_MODULE = project.settings - obviously replacing project with the actual name of your project.
Another good thing to do is to go to File-> Settings -> Django Support -> and be sure that your Django Root, Settings.py, and Manage.py fields are correct.
Following Dan Hoerst's answer worked for me, but it wasn't clear where to set the environment variable. You can find the setting under the menu option:
Run -> Edit Configurations...
Expand the Django Server option on the left hand side and then select your project. There you will find the Environment Variables: setting. Remember to use the dotted path like Muspy.settings and not the file path.
Dan, I'd reply to your answer, but don't have the rep.