guys. I'm trying to develop a program to create excel file with using xlwt.
I have used
pip install xlwt
to install it. In Terminal, it can be imported with no error. And the Django project could be run correctly.
But in pycharm, it shows import error when running the Django project. The error code shows below:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/checks/urls.py", line 10, in check_url_config
return check_resolver(resolver)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/checks/urls.py", line 19, in check_resolver
for pattern in resolver.url_patterns:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/motion/Documents/GitHub/motion-op/motion/urls.py", line 4, in <module>
from product.views import home
File "/Users/motion/Documents/GitHub/motion-op/product/views.py", line 22, in <module>
from .ProductService import ProductService
File "/Users/motion/Documents/GitHub/motion-op/product/ProductService.py", line 13, in <module>
from method import ProductServicePO,send_email, SaveImg, create_excel_file
File "/Users/motion/Documents/GitHub/motion-op/product/method/create_excel_file.py", line 2, in <module>
import xlwt
ImportError: No module named xlwt
I have already set project interpreter. The project interpreter image shows here.
Does anyone know how to solve it, thanks guys.
Hit the pip list command on pycharm's terminal and see whether xlwt available there or not. If not install it again.You are using python 2.7 so, see the version of xlwt you are using is compatible with this python or not.
Edited:
If you want to run your project with start button then go to `edit configuration by clicking on drop-down button beside the start and set the python interpreter there.
Apart from that, you need to see from .ProductService import ProductService (try writing full path instead of just typing .productService) and from method import ProductServicePO,send_email, SaveImg, create_excel_file import line in views.py and ProductService.py respectively.
Set project intepretator for current project. You probably set for common project
Just faced same problem and fixed it.
Configure your current interpreter in pycharm. (ctrl+alt+s)
Click '+' icon on the right side and install xlwt.
Install successfully with a pop-ups from pycharm and import problem is fixed.
I had to install through the Pycharm's GUI directly. Look in the following:
File|Settings|Project:|Python Interpreter| add
then search for xlwt and install.
Went to Python Packages at the bottom of PyCharm, found xlwt and installed from there.
Related
The ipython console is constantly throwing this error and I tried :
updating spyder
Uninstalling and reinstalling anaconda
Reading people's response on how they tried to fix it
But still I could not fix this.
Traceback (most recent call last):
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\console\__main__.py", line 11, in
start.main()
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 287, in main
import_spydercustomize()
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 39, in import_spydercustomize
import spydercustomize
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\customize\spydercustomize.py", line 27, in
from IPython.core.getipython import get_ipython
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\IPython\__init__.py", line 54, in
from .core.application import Application
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\IPython\core\application.py", line 23, in
from traitlets.config.application import Application, catch_config_error
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\traitlets\config\__init__.py", line 6, in
from .application import *
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\traitlets\config\application.py", line 10, in
import json
File "C:\Users\bbachegowda\json.py", line 12
source = response.read()
^
IndentationError: expected an indented block
The module name resolution is described in https://docs.python.org/3/tutorial/modules.html#the-module-search-path:
When a module named spam is imported, the interpreter first searches
for a built-in module with that name. If not found, it then searches
for a file named spam.py in a list of directories given by the
variable sys.path.
It looks like for some reason, the built-in module json is not found and that python looks into the path where C:\Users\bbachegowda\json.py is. So you should reinstall python to fix the built-in module json.
Had the same problem with Spyder when installing WinPython, version: WPy64-3.7.4.1.
However previous version: WPy64-3.7.4.0 works fine.
I am trying to create an installer for a django website that uses the django-omnibus module.
My Pyinstaller command:
pyinstaller --name djangosite manage.py
The Pyinstaller command runs to completion.
Trying to run the web server using
djangosite.exe runserver localhost:8000
I get the following error:
Traceback (most recent call last):
File "<string>", line 10, in <module>
File "django\core\management\__init__.py", line 338, in execute_from_command_line
File "django\core\management\__init__.py", line 312, in execute
File "django\__init__.py", line 18, in setup
File "django\apps\registry.py", line 85, in populate
File "django\apps\config.py", line 86, in create
File "importlib\__init__.py", line 37, in import_module
File "c:\users\USERNAME\appdata\local\temp\pip-build-vxcefe\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
File "omnibus\__init__.py", line 3, in <module>
File "pkg_resources\__init__.py", line 561, in get_distribution
File "pkg_resources\__init__.py", line 441, in get_provider
File "pkg_resources\__init__.py", line 962, in require
File "pkg_resources\__init__.py", line 849, in resolve
pkg_resources.DistributionNotFound: The 'django-omnibus' distribution was not found and is required by the application manage returned -1
If I remove all django-omnibus code, the site works fine (except for the my websocket functionality obviously). Any ideas? Thanks.
I needed to add a hook.py file for django-omnibus and add the --additional-hooks-dir=. flag to the pyinstaller command.
hook-omnibus.py
from PyInstaller.utils.hooks import copy_metadata, collect_data_files
datas = copy_metadata('django-omnibus')
datas += collect_data_files('omnibus')
Similar answer here:
https://github.com/pyinstaller/pyinstaller/issues/1713
I know this is a late reply, but I had a similar issue with django-user-accounts - pkg_resources.DistributionNotFound: The 'django-user-accounts' distribution was not found
I was directed here when searching for a fix. I solved the issue with the following addition to settings.py - hopefully helps someone else.
INSTALLED_APPS = [
...
'django.contrib.sites',
...
]
I need to ask because I'm starting in Django and it was impossible for me to continue with the tutorial that I'm following. I've just completed a Python course, I know the basics of python. The case is that I've installed Django in my mac and it's OK because when I do in the IDLE the
import django
print django.VERSION
It makes a good answer without errors in IDLE (is the software that I use to write python code). But when I execute in the Terminal the command:
python manage.py runserver
It raises this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/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.
I also want to ask you some questions:
Can I use XAMPP instead of Django? How?
What is Django used for exactly?
I've installed PyDev in Eclipse. How can I set Django to execute code properly?
call command django-admin startproject xxx under the target directory. You can get three .py files: setting.py, urls.py and manage.py. And you can execute python manage.py runserver command
I think it's slightly outdated now, but I'd seriously recommend going through the Djangobook examples. It'll explain how to set up Django properly, and give a pretty good foundation in how to use it.
Since today morning I'm having some weird problem with Python's unit-testing tool Nose + NoseGAE. I want to run unit-tests for my GAE project in terminal and it ends with this error:
Traceback (most recent call last):
File "/usr/local/bin/nosetests", line 8, in <module>
load_entry_point('nose==1.2.1', 'console_scripts', 'nosetests')()
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/core.py", line 118, in __init__
**extra_args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/core.py", line 135, in parseArgs
self.config.configure(argv, doc=self.usage())
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/config.py", line 338, in configure
self.plugins.configure(options, self)
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/plugins/manager.py", line 284, in configure
cfg(options, config)
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/plugins/manager.py", line 99, in __call__
return self.call(*arg, **kw)
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/plugins/manager.py", line 167, in simple
result = meth(*arg, **kw)
File "build/bdist.macosx-10.7-intel/egg/nosegae.py", line 84, in configure
File "/usr/local/google_appengine/google/appengine/tools/dev_appserver.py", line 61, in <module>
import simplejson
ImportError: No module named simplejson
It's weird because I'm not even using simplejson anywhere. I know it's part of Django, but I'm not using it either.
OS X 10.7.4
Python 2.7.1
Nose 1.2.1
NoseGAE 0.2.0
Do you have any idea what might be wrong?
This was probably just temporary problem in older GAE on OS X. Newer versions run without any problem.
So I just updated django to 1.2.3 and now when I try to run 'python manage.py shell' to work in the django environment, I'm getting the following error.
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/shell.py", line 18, in handle_noargs
loaded_models = get_models()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/loading.py", line 167, in get_models
self._populate()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/opt/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/opt/local/lib/python2.5/site-packages/django_celery-2.0.3-py2.5.egg/djcelery/models.py", line 7, in <module>
from celery import conf
File "/opt/local/lib/python2.5/site-packages/celery-2.0.3-py2.5.egg/celery/conf.py", line 6, in <module>
from celery import routes
File "/opt/local/lib/python2.5/site-packages/celery-2.0.3-py2.5.egg/celery/routes.py", line 2, in <module>
from celery.utils import instantiate, firstmethod, mpromise
File "/opt/local/lib/python2.5/site-packages/celery-2.0.3-py2.5.egg/celery/utils/__init__.py", line 9, in <module>
import importlib
ImportError: No module named importlib
Any ideas. I can't seem to find what's going on here and for all I can tell I'm running the same versions on my web server and I don't have the same error showing up.
importlib which was added in Python 2.7/3.1, I believe. You can download a port for pyton 2.5 here:
importlib 1.0.1 - Backport of importlib.import_module() from Python 2.7
Also check the setup.cfg for celery near the bottom and make sure all the other requirements are met (toward the bottom of the script).
importlib was added to Python in version 3.1, and then backported to Python 2.7. Third party backports are available on PyPI.
Also note that 'backported to 2.7' doesn't imply that all versions after 2.7 will have importlib. Python 3.0, I believe, does not have importlib.