I installed python 2.6 and MySQL-python-1.2.2.win32-py2.6 and created a new project using the command django-admin.py startproject mysite and it successfully created the project and I could run it.But when I edit mysite/settings.py file to use MySQLdb and run it again,it says
Validating models...
Unhandled exception in thread started by bound method Command.inner_run of dja
ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x02BFCB
raise ImproperlyConfigured(Error loading MySQLdb module:)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: DLL l
oad failed: The specified module could not be found.
I tried searching all net and couldn't identify the problem.Is it to do with setting some environment variables? Can anyone please help me about this?
If you fire up regular python and try
>>> import MySQLdb
and then fire up the django shell
> python manage.py shell
>>> import MySQLdb
and get the same error, I would presume that you have the wrong SQL package for your system - this is often a 32bit vs 64bit issue.
Dig out the actual SQL dll (called _mysql.pyd and see if you can import that directly into pyton (go to the directory containing the dll, fire up python and import _mysql). This should help speed up the diagnosis.
Alternatively, I've always found Bitnami's django stack to be the least painful way to install and manage my Windows django stack. It will set up and manage Apache HTTP Server, MySQL, Python, SQLite, PostgreSQL, Django all in one go.
Related
django works well on my local machine. But, when I deploy it to heroku, I see "ModuleNotFoundError" "No module named '_tkinter'". Though, I never imported "_tkinter" or "tkinter" in my code. Your help will be appreciated. Thank you.
ModuleNotFoundError at /
No module named '_tkinter'
Request Method: GET
Request URL: https://howididit.herokuapp.com/
Django Version: 4.0.6
Exception Type: ModuleNotFoundError
Exception Value:
No module named '_tkinter'
Exception Location: /app/.heroku/python/lib/python3.10/tkinter/init.py, line 37, in
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.10.5
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python310.zip',
'/app/.heroku/python/lib/python3.10',
'/app/.heroku/python/lib/python3.10/lib-dynload',
'/app/.heroku/python/lib/python3.10/site-packages']
If you don't use Tkinter, just remove it from /forms.py. otherwise it'll be imported.
If you want to use tkinter,then consider the below process
please try adding tkinter to your requirements.txt. If it fails, even after that, check if you have added Python buildpack. If both the cases pass, try shelling into your Heroku instances and run the following command:
sudo apt install python3-tk
This will install Tkinter library in your instance of Heroku. That will resolve your error.
I found out these from pyexpat import model from turtle import title from attr import fields where imported in my forms.py. After deleting them, The problem was solved. Again, thank you all guys for your time, I really appreciate it.
Okay so for anyone looking at this in the future and banging their head against the desk...this is what worked for me:
I started with a new Hello World app and started adding bits of my original code until i got to the error
found out that one of the modules I was using : icu, was using tkinter and i needed to install the Pyicu module instead
pip installed directly into heroku bash console instead of through my app
None of the answers i found online had worked for me, and I think its because this error isnt from having tkinter directly in your app, but from another module thats calling it.
When in doubt do what I did and start a new project from scratch and add chunks of code until you get the error to see which module is creating it
Dont forget to change DEBUG to False in your settings file
I'm using boost::python in my Visual C++ application and I have a script that wants to connect to an SQLite database and read some data from it.
In my script, I imported sqlite3 and it works fine when I run it with Python IDLE but, when it runs inside my Visual C++ application, I get an exception:
No module named _sqlite3
Can anyone tell me why it happens? What did I miss here?
Even this line in my code returns the same exception:
boost::python::object objSQLite3 = boost::python::import("sqlite3");
I finally found the problem!!!
I install the python via inno setup in silent mode. For first time since there is no python on system all libraries copy successfully But if u do it again since it try to install python again (/i), It some how mess with some library like sqlite3.
So u need change your inno setup script to reinstall the python if it exists (/a).
PS : If you have this problem and you don't use inno setup just reinstall your python to fix this problem.
Best Regards
I am trying to create an app using GeoDjango and I am completely new to this. After some (failing) attempts at making SpatiaLite work, I decided to try out PostgreSQL. I am following the GeoDjango tutorial, and I am stuck at the python manage.py sqlall world line. When I ran that command (or python manage.py syncdb), I got ImportError: No module named psycopg2.extensions. I looked online and realized I needed to install psycopg2, which I did via MacPorts with sudo port install py27-psycopg2. I reran the program and got the same error. I restarted my computer and ran the program again, and still got the same error. Does anyone know anything else that might have caused this?
Thanks!
PS. If anyone cared to know, I was stuck at the same command while testing out SpatiaLite. I consistently received the 'DatabaseOperations' object has no attribute 'geo_db_type'error. I looked around the internet, didn't find any answer and decided to move on for the time being and maybe try again later.
PSS. I am working on Mac OS X 10.7.5
Previously I have been trying to host multiple DEMO django projects using a virtual host on apache, and have been successfully with the help of stackoverflow.
Now I have been trying to host my new project using the same technique like the previous ones. My new project is connected to the sql_server database. My project runs perfectly when using djangos in-built server.
When i try running using apache i get an 500 Internal Server Error and my apache error logs shows -
Exception occurred processing WSGI script
ImproperlyConfigured: Error loading pyodbc module: DLL load failed: A dynamic link library (DLL) initialization routine failed.
My wsgi file looks like this -
import os
import sys
path = 'C:/path/project1'
if path not in sys.path:
sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
And i do have "C:\Windows\SysWOW64\python27.dll" in my machine
My system -
Windows 7, Apache 2.2, python 2.7, django 1.4.2
Another info i found out on my machine -
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Any solution towards this??
Thanks alot guys...
I managed to solve this problem, after spending severl hours googling for answers, finally found an answer here, and it says :
It appears that this dependency is being satisfied by running inside of python.exe (which is linked against the same). When the dll version of the python interpreter is instead hosted by another process, the windows sxs configuration applies the msvcr90 dependency only to the python dll.
This means that, in general, pyodbc.pyd (and likely pyodbcconf.pyd) will be unusable in embedded python on windows unless
the host application is linked against the appropriate version of the
msvc runtimes.
Use mt.exe (a freely available tool in the windows sdk) and try the commands on the command line.
Where do I get mt.exe?
mt.exe -inputresource:c:\windows\syswow64\python27.dll;#2 -outputresource:pyodbc.pyd;#2
mt.exe -inputresource:c:\windows\syswow64\python27.dll;#2 -outputresource:pyodbcconf.pyd;#2
Hopefully this wil be usefull for someone.
Cheers
I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Django or PySQL, I generally fail when installing them on my computer so maybe it's good I can't install on the host.
I found bpgsql really good because it does not require an install, it's a single file that I can look at, read and then call the functions of. Does anybody know of something like this for MySQL?
MySQLdb is what I have used before.
If you host is using Python version 2.5 or higher, support for sqlite3 databases is built in (sqlite allows you to have a relational database that is simply a file in your filesystem). But buyer beware, sqlite is not suited for production, so it may depend what you are trying to do with it.
Another option may be to call your host and complain, or change hosts. Honestly these days, any self respecting web host that supports python and mysql ought to have MySQLdb pre installed.
I don't have any experience with http://www.SiteGround.com as a web host personally.
This is just a guess, but it's common for a shared host to support Python and MySQL with the MySQLdb module (e.g., GoDaddy does this). Try the following CGI script to see if MySQLdb is installed.
#!/usr/bin/python
module_name = 'MySQLdb'
head = '''Content-Type: text/html
%s is ''' % module_name
try:
__import__(module_name)
print head + 'installed'
except ImportError:
print head + 'not installed'
I uploaded it and got an internal error
Premature end of script headers
After much playing around, I found that if I had
import cgi
import cgitb; cgitb.enable()
import MySQLdb
It would give me a much more useful answer and say that it was not installed, you can see it yourself -> http://woarl.com/db.py
Oddly enough, this would produce an error
import MySQLdb
import cgi
import cgitb; cgitb.enable()
I looked at some of the other files I had up there and it seems that library was one of the ones I had already tried.
You could try setting up your own python installation using Virtual Python. Check out how to setup Django using it here. That was written a long time ago, but it shows how I got MySQLdb setup without having root access or anything like it. Once you've got the basics going, you can install any python library you want.
You really want MySQLdb for any MySQL + Python code. However, you shouldn't need root access or anything to use it. You can build/install it in a user directory (~/lib/python2.x/site-packages), and just add that to your PYTHON_PATH env variable. This should work for just about any python library.
Give it a shot, there really isn't a good alternative.
Take a pick at
https://docs.djangoproject.com/en/1.8/ref/databases/
MySQLdb is mostly used driver, but if you are using python3 and django 1.8.x that will not work, then you should use mysqlclient that is a folk of MySQLdb on the following link
https://pypi.python.org/pypi/mysqlclient