Perl DBD::CSV No such file or directory on Windows - windows

I must migrate my perlscripts to a new machine but DBD::CSV would not work as I expect.
I got ActiveState perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x86-multi-thread
DBD-CSV is Version 0.41 and everyting I try results in:
#################################################################
DBD::CSV::db do failed:
Execution ERROR: -d D:\TEST/D:\TEST: No such file or directory at D:/Programme/Perl/site/lib/DBI/DBD/SqlEngine.pm line 1503.
called from D:\TEST\CSVTest.pl at 7.
#################################################################
even at the simplest create TestTable
#################################################################
use DBI;
$dbh = DBI->connect ("dbi:CSV:");
my $table ="TestTable";
$dbh->do ("CREATE TABLE $table (id INTEGER, name CHAR (64))");
#################################################################
Any suggestion?
Update
Not the real answer, but too much for an comment the uncommented $DBDIR is the way i had excpeted to work. All the commented versions of $DBDIR I tried, but all created an foo.csv in same directory as the script (C:\Temp). I want to use some other Directory as the Script is located any sugestion?
use DBI;
my $DBDIR='C:\Temp\CSV-DB';
# my $DBDIR="C:\\Temp\\CSV-DB";
# my $DBDIR='C:\Temp\CSV-DB\\';
# my $DBDIR='..\CSV-DB';
# my $DBDIR="..\\CSV-DB";
# my $DBDIR='CSV-DB';
# my $DBDIR='\CSV-DB';
# my $DBDIR='\\CSV-DB';
# my $DBDIR='.\CSV-DB';
# my $DBDIR='/CSV-DB';
# my $DBDIR='./CSV-DB';
$dbh = DBI->connect ("dbi:CSV:", undef, undef, {
f_dir => [$DBDIR],
#f_dir_search => [$DBDIR],
f_ext => ".csv/r",
RaiseError => 1,
}) or die "Cannot connect: $DBI::errstr";
# Simple statements
$dbh->do ("CREATE TABLE foo (id INTEGER, name CHAR (10))");
##############################################################

I had this problem on my windows PC.
I found that it occurred when DBI was not the first module to be used.
By putting "use DBI;" as the first module the problem has disappeared.
I haven't tried to determine exactly which module caused the problem. I'm using CGI, Archive::Zip, POSIX, etc..

Related

How can I use the Win32::LongPath module in Perl to manipulate long path names?

My Perl scripts need to work with pathnames that are longer than 260 characters, and I can not turn on the feature in the registry to enable Windows Long Path support.
I included a small Perl test, using the Win32::LongPath module to do this, and found that only a few functions from that module work. No luck with:
chdirL
getcwdL
Environment:
Windows 10 version 10.0.19041 build 19041
Strawberry Perl 5.30.3
I can't really find evidence that Win32::LongPath will not work in that environment, except for CPAN saying that the module has only been tested on XP and Windows 8...
⚠ However all of the help for Perl/Windows Long Paths in Windows 10 seems to recommend this module?
Am I using it wrong? I have included the output of the last iteration of the loop in the MRE (Minimal Reproducible Example):
The chdirL command never changes directories.
The getcwdL command only has 249 characters (513 expected).
package main 1.0;
use strict;
use warnings;
use Carp;
use Readonly;
use File::Spec::Functions;
use Cwd;
use Win32::LongPath;
my $dir = 'd123456789';
my $file = 'test.txt';
my $long_path = 'C:\\Temp';
my $long_file;
my $long_root = catdir $long_path, $dir;
my $fh;
# Maximum path length on linux : 4096
# Maximum path length on Windows : 260
Readonly::Scalar my $MAX_PATH => 512;
chdirL $long_path;
while ( length $long_path < $MAX_PATH ) {
$long_path = catdir $long_path, $dir;
$long_file = catfile $long_path, $file;
printf "%-5d: %s\n", length $long_path, "Making $long_path...";
mkdirL $long_path;
# === Does not change directories ==>
chdirL $long_path;
system 'CD';
# === Truncates path name ==>
my $curdir = getcwdL;
printf "%-20s: %s (%d)\n", 'getcwpdL', $curdir, length $curdir;
printf "%-5d: %s\n", length $long_file, "Making $long_file...";
openL \$fh, '>', $long_file or die "unable to create file\n";
print {$fh} "$long_path\n" or die "unable to print to file\n";
close $fh or die "unable to close file\n";
last if ( !( testL 'e', $long_path ) );
last if ( !( testL 'e', $long_file ) );
}
unlinkL $long_file or warn "unable to delete file\n";
1;
Last loop iteration:
513 : Making C:\Temp\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789...
W:\home\_PERL\long_path
getcwpdL : C:\Temp\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789 (249)
522 : Making C:\Temp\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\d123456789\test.txt...
chdirL is failing with The filename or extension is too long. chdirL, like the others, converts the path to a long path (\\?\...), and calls the appropriate system call. This is SetCurrentDirectoryW for chdirL and GetCurrentDirectoryW for getcwdL.
Using paths of the form \\?\... extends the use length limit for some calls, but not for SetCurrentDirectoryW and GetCurrentDirectoryW. It also doesn't extend the limit for CreateDirectoryW, CreateDirectoryExW and RemoveDirectoryW. These five retain the classical length limit even when using "long paths", at least according to Maximum Path Length Limitation, which provides a registry setting PLUS a manifest entry you can use to remove the limit on long paths for those calls.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>
I don't remember if DLLs have their own manifest or not. If they do, the settings could be changed for just the module, and nothing would break. If they don't and perl's manifest needs to be changed, this would affect all uses of GetCurrentDirectoryW in the process, and that could cause problems. (GetCurrentDirectoryW could return an error because the buffer is too small, which could lead to a failure or crash depending on whether error checking is performed.)

Program to send mail won't compile

use strict;
use warnings;
use Net::SMTP;
# to install Net::SMTP moudle package, run cpan command in command line
# in the shell type install Net::SMTP
sub send_mail
####################################################################################################
#
# SUBROUTINE : send_mail
#
# PURPOSE : Send an email.
#
# INPUT(S) : smtp_server - Simple Mail Transfer Protocol server
# to - Recipient address
# from - Sender address
# subject - Subject
# body - Reference to an array containing the message body
#
# OUTPUT(S) : 0 - success
# 1 - failure
#
####################################################################################################
{
my $from = 'home.yosef#gmail.com';
my $to = 'home.yosef#gmail.com';
my $data = "A simple test message from Perl script\n";
my $subject = "Hello World from Perl script";
smtp_server => "smtp.gmail.com";
# Connect to the SMTP server
my $smtp = Net::SMTP->new($smtp_server);
# If connection is successful, send mail
if ($smtp) {
# Establish to/from
$smtp->mail($from);
$smtp->to($to);
# Start data transfer
$smtp->data();
# Send the header
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
# Send the body
$smtp->datasend(#body);
# End data transfer
$smtp->dataend();
# Close the SMTP connection
$smtp->quit();
# If connection fails return with error
}
else {
# Print warning
warn "WARNING: Failed to connect to $smtp_server: $!";
return 1;
}
return 0;
}
# Define the message body
my #message_body = "Hello World! from Perl script\n";
push #message_body, "Add another line!\n";
# Send the email!
send_mail(
smtp_server => <smtp_server_name>,
to => <to_address>,
from => <from_address>,
subject => 'This is a mail from Perl script',
body => \#message_body,
);
I have Windows installed with Strawberry Perl. When I run this script from the command line I get errors and I donn't know what is wrong.
These are the errors:
Global symbol "$smtp_server" requires explicit package name (did you forget to declare "my $smtp_server"?) at windows_send_mail_with_SMTP.pl line 40.
Global symbol "#body" requires explicit package name (did you forget to declare "my #body"?) at windows_send_mail_with_SMTP.pl line 59.
Global symbol "$smtp_server" requires explicit package name (did you forget to declare "my $smtp_server"?) at windows_send_mail_with_SMTP.pl line 71.
Execution of windows_send_mail_with_SMTP.pl aborted due to compilation errors.
Well I think it's pretty clear from the messages. You haven't declared (or defined) either $smtp_server or #body
This line doesn't do anything useful
smtp_server => "smtp.gmail.com"
The => operator is just a comma that happens to put quotes around its first parameter, so it's the same as
"smtp_server", "smtp.gmail.com"
which just evaluates two strings and discards them
Since you have already successfully defined four other variables on the lines before, I don't understand why you chose to do something different here
As for #body, you never declare it or put anything into it. As the error message says,
did you forget to declare "my #body"?

How to export variables from multiple files using module manifests in PowerShell?

I am trying to package multiple modules in one manifest module with PowerShell 4.0. Basically, I have 3 Setup Modules that do some stuff. I package these three using my manifest module. I then export only some functions and variables from all three modules. However, only my functions are callable from outside, my variables are nowhere to be seen. Can anyone help me out here? I basically followed this guide.
Here is my code:
Setup.ps1 (Startup-Script):
$currentDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
$setupScriptPath = $currentDirectory + "\Setup.psd1"
Import-module $setupScriptPath
# This has to be set for every environment
$firstVariable # Not defined?
# $secondVariable= "http://url/"
# $thirdVariable= "http://url/"
Start-FirstSetup
Remove-Module -Name Setup
Setup.psd1 (Manifest module):
#
# Module manifest for module 'Setup'
#
# Generated by: Name
#
# Generated on: 1/7/2017
#
#{
# Script module or binary module file associated with this manifest.
# RootModule = ''
# Version number of this module.
ModuleVersion = '1.0'
# ID used to uniquely identify this module
GUID = 'guid'
# Author of this module
Author = 'Author name'
# Company or vendor of this module
CompanyName = 'Company'
# Copyright statement for this module
Copyright = '(c) 2017 Company'
# Description of the functionality provided by this module
Description = 'Starts three setups.'
# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''
# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = #()
# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = #()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = #()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = #()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = #()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = #('FirstSetup.psm1', 'SecondSetup.psm1', 'ThirdSetup.psm1')
# Functions to export from this module
FunctionsToExport = #('Start-FirstSetup', 'Start-SecondSetup', 'Start-ThirdSetup')
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = #('firstVariable', 'secondVariable', 'thirdVariable')
# Aliases to export from this module
AliasesToExport = '*'
# List of all modules packaged with this module
ModuleList = #('FirstSetup.psm1', 'SecondSetup.psm1', 'ThirdSetup.psm1')
# List of all files packaged with this module
# FileList = #()
# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}
FirstSetup.psm1 (First Module):
$firstVariable # This is not getting exported. Why?
function Start-FirstSetup{
Register-FirstVariables
echo "First setup started..."
}
Second and third setups: Same as first, only varables and functions are named firstVariable, thirdVariable, Start-SecondSetup, etc.
So my specific problem is, when I try to access $firstVariable from Setup.psm1, I get an error that it's not defined. But I marked it for export in my manifest module. So what did I miss here? When Start-FirstSetup is called, it goes through without any problem and I can even debug my module, but even then my $firstVariable is undefined.
You need to do 3 things to get a variable exported from a module:
Define the variable explicitly:
New-Variable -Name firstvariable
An implicit definition ($firstvariable) does not suffice.
Export the variable in the module (the .psm1 file):
Export-ModuleMember -Variable firstvariable
Define the exported variables in the manifest (the .psd1 file). A wildcard should normally suffice here:
VariablesToExport = '*'
but you can also provide a list:
VariablesToExport = #('firstvariable', 'secondvariable', 'thirdvariable')
This setting is basically a filter for defining which of the exported variables will actually be exposed. If a variable does not have a match here it will not be exported from the module, even if it's exported in a .psm1 file.

Perl Image::OCR::Tesseract module on Windows

Anyone out there know of a graceful way to install the "Image::OCR::Tesseract" module on Windows? The module fails to install on Windows via CPAN due to a *NIX only module dependency called "LEOCHARRE::CLI". This module does not seem to be required to run "Image::OCR::Tesseract" itself.
I've managed to get the module working by first manually installing the dependency modules listed in the makefile.pl (except for "LEOCHARRE::CLI") and then by moving the module file to the correct directory structure under "C:\Perl\site\lib\Image\OCR". The final part of getting it to work was to alter the section of code that calls the ImageMagick and Tesseract executables from the command line to put quotes around the program names when the executables are called by module.
This works, but I'd really feel better about doing a PPM or CPAN install on a production system from a repo that works on Windows.
Never mind, I got it, though I can't decide what is the better solution.
To get the installer to work on Windows via the traditional "perl makefile.pl, make, make test, make install" routine requires an edit to the Makefile.pl script, including the missing Windows install module (Devel::AssertOS::MSWin32), and patch to AssertEXE.pm to use "File::Which" rather than the built in shell "which" command that Windows lacks. All this still requires that The "Image::OCR::Tesseract" be patched to put quotes around program names when executing "convert" and "tesseract" from the command line.
Given the number of steps involved to make the installer work on Windows, and the fact the module does not create a binary component for the module to link to, I'd say the best option for installing and getting the Tesseract module working on windows would be to first install the following binary packages:
ImageMagick
Link
Tesseract
http://code.google.com/p/tesseract-ocr/downloads/list
Next, locate your Perl module directory - on my system it is "C:\Perl\site\lib". Create a folder "Image", if you don't have one. Next, open the Image folder and create a folder called "OCR". Open the OCR folder. At this point, your path should be something along the lines of "C:\Perl\site\lib\Image\OCR". Create a new text file called "Tesseract.pm", and copy in the following content...
package Image::OCR::Tesseract;
use strict;
use Carp;
use Cwd;
use String::ShellQuote 'shell_quote';
use Exporter;
use vars qw(#EXPORT_OK #ISA $VERSION $DEBUG $WHICH_TESSERACT $WHICH_CONVERT %EXPORT_TAGS #TRASH);
#ISA = qw(Exporter);
#EXPORT_OK = qw(get_ocr get_hocr _tesseract convert_8bpp_tif tesseract);
$VERSION = sprintf "%d.%02d", q$Revision: 1.24 $ =~ /(\d+)/g;
%EXPORT_TAGS = ( all => \#EXPORT_OK );
BEGIN {
use File::Which 'which';
$WHICH_TESSERACT = which('tesseract');
$WHICH_CONVERT = which('convert');
if($^O=~m/MSWin/) {
$WHICH_TESSERACT='"'.$WHICH_TESSERACT.'"';
$WHICH_CONVERT='"'.$WHICH_CONVERT.'"';
}
$WHICH_TESSERACT or die("Is tesseract installed? Cannot find bin path to tesseract.");
$WHICH_CONVERT or die("Is convert installed? Cannot find bin path to convert.");
}
END {
scalar #TRASH or return;
if ( $DEBUG ){
print STDERR "Debug on, these are trash files:\n".join("\n",#TRASH) ;
}
else {
unlink #TRASH;
}
}
sub DEBUG { Carp::cluck("Image::OCR::Tesseract::DEBUG() deprecated") }
sub get_hocr {
my ($abs_image,$abs_tmp_dir,$lang)= #_;
-f $abs_image or croak("$abs_image is not a file on disk");
my $hocr="hocr";
if(defined $abs_tmp_dir){
-d $abs_tmp_dir or die("tmp dir arg $abs_tmp_dir not a dir on disk.");
$abs_image=~/([^\/]+)$/ or die("cant match filename in path arg '$abs_image'");
my $abs_copy = "$abs_tmp_dir/$1";
# TODO, what if source and dest are same, i want it to die
require File::Copy;
File::Copy::copy($abs_image, $abs_copy)
or die("cant make copy of $abs_image to $abs_copy, $!");
# change the image to get ocr from to be the copy
$abs_image = $abs_copy;
# since it's a copy. erase that on exit
push #TRASH, $abs_image;
}
my $tmp_tif = convert_8bpp_tif($abs_image);
push #TRASH, $tmp_tif; # for later delete
_tesseract($tmp_tif,$lang,$hocr) || '';
}
sub get_ocr {
my ($abs_image,$abs_tmp_dir,$lang)= #_;
-f $abs_image or croak("$abs_image is not a file on disk");
if(defined $abs_tmp_dir){
-d $abs_tmp_dir or die("tmp dir arg $abs_tmp_dir not a dir on disk.");
$abs_image=~/([^\/]+)$/ or die("cant match filename in path arg '$abs_image'");
my $abs_copy = "$abs_tmp_dir/$1";
# TODO, what if source and dest are same, i want it to die
require File::Copy;
File::Copy::copy($abs_image, $abs_copy)
or die("cant make copy of $abs_image to $abs_copy, $!");
# change the image to get ocr from to be the copy
$abs_image = $abs_copy;
# since it's a copy. erase that on exit
push #TRASH, $abs_image;
}
my $tmp_tif = convert_8bpp_tif($abs_image);
push #TRASH, $tmp_tif; # for later delete
_tesseract($tmp_tif,$lang) || '';
}
sub convert_8bpp_tif {
my ($abs_img,$abs_out) = (shift,shift);
defined $abs_img or die('missing image arg');
$abs_out ||= $abs_img.'.tmp.'.time().(int rand(9000)).'.tif';
my #arg = ( $WHICH_CONVERT, $abs_img, '-compress','none','+matte', $abs_out );
#die (join(" ", #arg));
system(#arg) == 0 or die("convert $abs_img error.. $?");
$DEBUG and warn("made $abs_out 8bpp tiff.");
$abs_out;
}
# people expect tesseract to automatically convert
*tesseract = \&_tesseract;
sub _tesseract {
my ($abs_image,$lang,$hocr) = #_;
defined $abs_image or croak('missing image path arg');
$abs_image=~/\.tif+$/i or warn("Are you sure '$abs_image' is a tif image? This operation may fail.");
#my #arg = (
# $WHICH_TESSERACT, shell_quote($abs_image), shell_quote($abs_image),
# (defined $lang and ('-l', $lang) ), '2>/dev/null'
#);
my $cmd =
( sprintf '%s %s %s',
$WHICH_TESSERACT,
shell_quote($abs_image),
shell_quote($abs_image)
) .
( defined $lang ? " -l $lang" : '' ) .
( defined $hocr ? " hocr" : '' ) .
" 2>/dev/null";
$DEBUG and warn "command: $cmd";
system($cmd); # hard to check ==0
my $txt = $abs_image.($hocr?".html":".txt");
unless( -f $txt ){
Carp::cluck("no text output for image '$abs_image'. (No text file '$txt' found on disk)");
return;
}
$DEBUG and warn "Found text file '$txt'";
my $content = (_slurp($txt) || '');
$DEBUG and warn("content length of text in '$txt' from image '$abs_image' is ". length $content );
push #TRASH, $txt;
$content;
}
sub _slurp {
my $abs = shift;
open(FILE,'<', $abs) or die("can't open file for reading '$abs', $!");
local $/;
my $txt = <FILE>;
close FILE;
$txt;
}
1;
__END__
#sub _force_imgtype {
# my $img = shift;
# my $type = shift;
# my $delete_original = shift;
# $delete_original ||=0;
#
#
# if($img=~/\.$type$/i){
# return $img;
# }
#
# my $img_out= $img;
# $img_out=~s/\.\w{1,5}$/\.$type/ or die("cant get file ext for $img");
#
#
#
#}
Save and close. Close the command line session and open a new one if you've had one open from before you did the ImageMagick and Tesseract binary installs. Test the module with the following script:
use Image::OCR::Tesseract;
my $image = 'SomeImageFileThatContainsText.jpg';
my $text = Image::OCR::Tesseract::get_ocr($image);
print "Text...\n";
print $text."\n";
print "Normal Exit\n";
exit;
That's it. Messy, I know, but there's no good way around the fact that the module installer really needs to be updated to support Windows (and other) systems even though the actual module code almost runs without modification. Really, if Tesseract and ImageMagick were installed to paths without spaces then the "Image::OCR::Tesseract" module code would not need any changes, but this minor tweak lets the supporting executables be installed anywhere, including the default locations.

windows django AttributeError: 'tuple' object has no attribute 'split

I am using the following command on WinXP and getting an error, but works fine on MacOS and Linux, thank you very very much for any help.
C:\Documents and Settings\Administrator\Sites\team_track>manage.py syncdb --settings=local_settings
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table app_player
Creating table app_team_players
Creating table app_team
Creating table app_game
Creating table app_gameparticipant
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'administrator'):
E-mail address: kam#kam.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\Sites\team_track\manage.py", line 19, in <module>
execute_manager(team_tracker.settings)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 438, in execute_mana
ger
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 220, in execute
output = self.handle(*args, **options)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 351, in handle
return self.handle_noargs(**options)
File "c:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 121, in handl
e_noargs
custom_sql = custom_sql_for_model(model, self.style, connection)
File "c:\Python27\lib\site-packages\django\core\management\sql.py", line 166, in custom_sql_for_mo
del
backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
AttributeError: 'tuple' object has no attribute 'split'
Here is what my manage.py looks like:
#!/usr/bin/env python
import sys
import os.path
from django.core.management import execute_manager
try:
import team_tracker.settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(team_tracker.settings)
And my local_settings.py resides in root dir:
from team_tracker.settings import *
DEBUG = True
#DATABASE_ENGINE = 'sqlite3'
#DATABASE_NAME = 'caktus_website.db'
DATABASE_ENGINE = 'sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'team_track.db' # Or path to database file if using sqlite3.
And finally my team_tracker/settings.py is here:
# Django settings for team_tracker project.
import os.path
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
MANAGERS = ADMINS
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
# 'NAME': 'team_track.db', # Or path to database file if using sqlite3.
# 'USER': '', # Not used with sqlite3.
# 'PASSWORD': '', # Not used with sqlite3.
# 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
# 'PORT': '', # Set to empty string for default. Not used with sqlite3.
# }
#}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/Users/kamilski81/Sites/team_tracker/media/'#os.path.join(SITE_ROOT, 'appmedia')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/Users/kamilski81/Sites/team_tracker/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'v8#s)7gw-^#zp&6**g7rz$uj!#3v4a36so_uw!_#0pa$h4)b-s'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# #kamtodo: find out how to truly use this and the best way if we have many forms
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(SITE_ROOT, 'templates').replace('\\','/'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'app',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
In local_settings.py:
DATABASE_ENGINE = 'sqlite3',
The comma here makes DATABASE_ENGINE a tuple with one element instead of a string. Remove it and it should work.

Resources