Error while accessing sqlite3 shell from django application - django

When I run python manage.py dbshell command I get this error:
Error: You appear not to have the 'sqlite3' program installed or on your path. The solution is partly hinted at in the second post of this thread. But how it can be solved on ubuntu? The python I'm using is version 2.6.

Installing the sqlite program should solve the problem:
sudo apt-get install sqlite3
(or use synaptic if you prefer a GUI interface)

To download SQLite, you open the download page of the SQlite website.
First, go to the https://www.sqlite.org website.
Second, open the download page https://www.sqlite.org/download.html
SQLite provides various versions for various platforms e.g., Windows, Linux, Mac, etc. You should choose an appropriate version to download.
For example, to work with SQLite on Windows, you download the command-line shell program as shown in the screenshot below.
The downloaded file is ZIP format and its size is quite small.
Install SQLite
Installing SQLite is simple and straightforward.
First, create a new folder e.g., C:\sqlite.
Second, extract the content of the file that you downloaded in the previous section to the C:\sqlite folder. You should see the sqlite3.exe is in the C:\sqlite folder.
To verify the installation, you perform the following steps:
First, open the command line window and navigate to the C:\sqlite folder.
Second, enter sqlite3, you should see the following window
Third, you can type the .help command from the sqlite> prompt to see all available commands in sqlite3.
Fourth, to quit the sqlite>, you use .quit command as follows:
Append the directory where you installed the sqlite to the system path variable in windows environment variables and kaboom. Mine worked just fine.
Happy programming...!

Related

macOS Catalina: trying to install content to the system volume

I have apps that I distribute as .pkg files created using pkgbuild and productbuild. With macOS Catalina, this doesn't work any more. The installer complains that I'm trying to install content to the system volume.
I posted three weeks ago thinking the error had to do with bundling a Java runtime. It turns out it has nothing to do with Java.
To test it I have the smallest possible project called Hello with a main window and a button to click. In XCode, I do Product -> Archive, then Distribute App, and Copy App. This creates a directory Hello 2019-12-18 15-01-07 with contents Hello.app. The app works fine. I then
pkgbuild --root *7 Hello.pkg
which creates Hello.pkg.
When I double-click Hello.pkg in the finder the installer presents me with screens for Introduction, Destination Select (only one option is offered), and Installation type ("Standard Install on Macintosh HD"), then asks me for my password. It then says, "This package is incompatible with this version of macOS. The package is trying to install content to the system volume. Contact the software manufacturer for assistance."
It makes no difference if I codesign and notarize. Productbuild only adds one more layer to the failing process.
What am I missing?
We could fix the issue by using the option
--install-location
of the pkgbuild command.
If the
--install-location
option is not used, pkgbuild uses / as the default install location in many cases.
In macOS Catalina, only certain folders are writable. Refer this link for more details.
In our case, the package installation succeeded only when we specified one of the writable folders such as
/usr/local
/opt
/Applications
as the default install location.

Failing to install sqlite3 plugin for electron project on windows

I am trying to include sqlite3 in an electron project I am getting my hands dirty with. I have never used electron, nor Node before, excuse my ignorance. I understand that to do this on Windows, I need Python installed, I need to download sqlite3, and I need to install it.
As per the NPM sqlite3 page, I am trying to install it using npm install --build-from-source
It always fails with
unpack_sqlite_dep
'python' is not recognized as an internal or external command,
operable program or batch file.
I have Python 2.7 installed and the path has been added to environment variable PATH. I can verify that if I type 'python' in cmd, I get the same response. BUT, if I type 'py', it works....
So, my question is: how can I make node-gyp use the 'py' command instead of 'python' when trying to unpack sqlite3?
If this is not possible, how can I make 'python' an acceptable command to use?
I am using Windows 10 if this helps. Also, please let me know if I can do this whole procedure in a different way.
Thanks for any help!
This has been resolved....
Uninstalled Python 2.7.13. Reinstalled, added path to PATH variable again, now command 'python' works just fine...

Global name 'col2im_6d_cython' is not defined, CS231n

I'm following CS231n and met a problem when doing assignment2: ConvolutionalNetworks: global name 'col2im_6d_cython' is not defined.
I think the problem was due to a failure in importing functions from im2col_cython.pyx, which used cython.
I've installed Xcode 7.3.1, as shown below, but the problem was still not solved.
I'm running the ipynb files in Jupyter from Anaconda. There is a related discussion on reddit, but unfortunately the solution here was for Windows, not Mac OS X.
Thank you for your time.
I wanted to add my input as a comment but didn't have enough reputation points to do so.
The issue was resolved for me when I closed the jupyter notebook and opened it again. I compiled the cython extension after I got the import error and probably have to relaunch it when the .so file is available.
I solved this with 2 easy steps:
In the terminal, run python setup.py build_ext --inplace in the cs231n directory.
Then reopen the notebook (if necessary, shutdown the notebook, the open it again);
Ps.: I tried this through the notebook using !python ./cs231n/setup.py build_ext --inplace as well. It does not work! You have to that outside the notebook, using the terminal.
I had this problem recently. I googled it a lot and also tried un-/-reinstall Anaconda. However it does work further. So I used "which python" to figure out which python's been using. And it turns out that the python included in Anakonda directory is used as default. I then tried the python2.7 in my macOS, which is located in /usr/bin/python2.7. Although I got a couple of warnings, but now it works likes charm. Perhaps it's kind of version problem. Solved in macOS Sierra 10.12.4.
I compared the two compiling results, as it shows that the include files are totally different. The one in Anaconda includes all header files in python3.6. Instead we need here corresponding header files in python2.7(I suppose). As the red circles point out.
enter image description here
Supported by python 3 onwards. Go to setup_googlecloud.sh and change the line
virtualenv .env
to
virtualenv -p python3 .env and run the setup again as explained in assignment1 setup..
Works well after that..
It occurred to me as well.
My problem:
I saw that the extention file that is created is named "im2col_cython.cp37-win_amd64.pyd" and the import is looking for im2col_cython alone, so I changed the file name to "im2col_cython.pyd" and ran the setup script again.
Now when I ran the code in the notebook it found the module but it said that the dll was compiled with a different python version. I use Anaconda envs and it turns out that since I ran the setup script from the cmd, it used a different python version than the one of the environment. I deleted the created files from the cs231n directory (im2col_cython.cp37-win_amd64.pyd and im2col_cython.c) and ran the setup script again, this time from the env Anaconda Prompt and it worked.
Solution:
remove already created files (the .c and .pyd files)
run the setup
script from the environment prompt (not plain cmd)
change the .pyd
file name into im2col_cython.pyd
Enjoy!

Installing Python 2.7 on Windows 8

So I'm trying python 2.7 on my Windows. It is running Windows 8. I cannot add it to my path. I've done the usual: using the advanced system settings, environment variables, adding C:\Python27 in system variables.
However, when I type Python in command prompt it says 'python is not recognized ..'
I think that the essence of this question is how to install Python and be able to use it from the command line. The steps below show how to get all that working. Check that you didn't miss anything:
From https://www.python.org/download/releases/2.7.6 download appropriate Python 2.7.6 Windows Installer. (If that link doesn't work, check https://www.python.org/downloads/)
Run the file
Select install for all users or install just for me, click Next
You'll see it installs under the C:\Python27 folder, click Next
Click Next again for the 'Customize Python' step
Click Finish
Open Control Panel, then System
Click 'Advanced system settings' on the left
Click the 'Environment Variables' button
Under 'System variables' click the variable called 'Path' then the 'Edit...' button. (This will set it for all users, you could instead choose to edit the User variables to just set python as a command prompt command for the current user)
Without deleting any other text, add C:\Python27; (include the semi-colon) to the beginning of the 'Variable value' and click OK.
Click OK on the 'Environment Variables' window.
Open a new command prompt window type python, you will have python running in the command prompt. Note: command prompt windows open prior to setting the Environment Variable will not have the python command available.
Easiest way is to open CMD or powershell as administrator and type
set PATH=%PATH%;C:\Python27
System variables usually require a restart to become effective. Does it still not work after a restart?
Make sure you don't put a space between the semi-colon and the new folder location that you are adding to the path.
For example it should look like...
{last path entry};C:\Python27;C:\Python27\Scripts;
...not...
{last path entry}; C:\Python27; C:\Python27\Scripts;
How to install Python / Pip on Windows Steps
Visit the official Python download page and grab the Windows installer for the latest version of Python 3.
python.org/downloads/
Run the installer. Be sure to check the option to add Python to your PATH while installing.
Open PowerShell as admin by right clicking on the PowerShell icon and selecting ‘Run as Admin’
To solve permission issues, run the following command:
Set-ExecutionPolicy Unrestricted
Next, set the system’s PATH variable to include directories that include Python components and packages we’ll add later. To do this:
C:\Python35-32;C:\Python35-32\Lib\site-packages\;C:\Python35-32\Scripts\
download the bootstrap scripts for easy_install and pip from https://bootstrap.pypa.io/
ez_setup.py
get-pip.py
Save both the files in Python Installed folder
Go to Python folder and run following:
Python ez_setup.py
Python get-pip.py
To create a Virtual Environment, use the following commands:
cd c:\python
pip install virtualenv
virtualenv test
.\test\Scripts\activate.ps1
pip install IPython
ipython3
Now You can install any Python package with pip
That’s it !!
happy coding
Visit This link for Easy steps of Installation python and pip in windows http://rajendralora.com/?p=183
Type this in Windows PowerShell or CMD:
"[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")"
After running the command, please restart PowerShell or CMD. If it still doesn't work, restart your PC.
there is a simple procedure to do it go to controlpanel->system and security ->system->advanced system settings->advanced->environment variables
then add new path enter this in your variable path and values
i'm using python 2.7 in win 8 too but no problem with that. maybe you need to reastart your computer like wclear said, or you can run python command line program that included in python installation folder, i think below IDLE program. hope it help.
GUI Option:
Open System Properties
a. Type it in the Start Menu
b. Use the keyboard shortcut Win+Pause)
c. From Windows Explorer address bar go to
%windir%\System32\SystemPropertiesProtection.exe
d. Write SystemPropertiesProtection in run window and press Enter
Switch to the Advanced tab
Click Environment Variables
Select PATH in the System variables section
Click Edit
Add python's path to the end of the list (the paths are separated by semicolons).
For example:
C:\Windows;C:\Windows\System32;C:\Python27
Command Line Option:
Run Command Prompt as administrator
Check existing paths under PATH variable (the paths are separated by semicolons). If your python folder already listed then no need to add again. Default python folder is C:\Python27
C:\Windows\system32>path or C:\Windows\system32>echo %PATH%
Append python path using setx command. The /M option sets the variable at SYSTEM scope.
The default behavior is to set it for the USER.
C:\Windows\system32>setx /M PATH "%PATH%;C:\Python27"

Install Spatialite for python (GeoDjango) on OS X

I am tearing my hair out trying to install Spatialite for GeoDjango!
I am already using Homebrew, it's generally easy and convenient so I initially tried to follow the Homebrew instructions for GeoDjango.
But this stops short of installing any database, i.e. Spatialite. The next step is to try and install Spatialite itself, but there are no Homebrew-specific instructions provided by Django docs.
I found this tutorial which looks perfect - a Homebrew and virtualenv-friendly install of Spatialite for GeoDjango.
But it doesn't work... it appears that my pysqlite is linked against the non-spatial-enabled version of SQLite that comes with OS X, rather than the Spatial-ised one I installed from Homebrew, I get this error when Django tried to connect to the db:
"The pysqlite library does not support C extension loading. Both SQLite and pysqlite must be configured to allow the loading of extensions to use SpatiaLite."
The author of pysqlite hasn't responded to my pleas for help on Github and I haven't found anything via Google.
So I went back to the drawing board and decided to follow the "Mac OS X-specific instructions" in the GeoDjango docs... by installing the various geo libs from the KyngChaos binary packages.
The docs say "Install the packages in the order they are listed above" but I found I couldn't install UnixImageIO without installing PROJ first. The link in the docs to download Spatialite binaries (http://www.gaia-gis.it/spatialite-2.3.1/binaries.html) is broken so I used the "Spatialite Tools v4.1" from KyngChaos instead.
Proceeding to the next step I get this error:
$ spatialite geodjango.db "SELECT InitSpatialMetaData();"
SQLite header and source version mismatch
2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a
2013-09-03 17:11:13 7dd4968f235d6e1ca9547cda9cf3bd570e1609ef
Not really sure what's wrong at this point.
There is someone else here on SO who has gone the KyngChaos route and just ends up with the same "Both SQLite and pysqlite must be configured to allow the loading of extensions" error I got from the Homebrew route anyway.
I found this ticket #17756 for adding pyspatialite support to Django - pyspatialite is supposed to be an easier way to pip install everything but unfortunately it doesn't work either (see comments towards bottom of ticket).
I'm a bit reluctant to start trying to build everything from source by hand as it seems likely I'll just run into the same problems again, but spending hours Googling for info about cryptic compiler errors, magic flags and paths etc along the way.
I'm about ready to give up and just use Postgres/PostGIS.
I was able to get this working now, using the tip here:
https://github.com/ghaering/pysqlite/issues/60#issuecomment-50345210
I'm not sure if it was using the real paths that fixed it, or just the Homebrew kegs or underlying packages have been updated and now install cleanly. Still, it works now.
I reproduce below the steps I took:
brew update
brew install sqlite # 3.8.5
brew install libspatialite # 4.2.0
brew install spatialite-tools # 4.1.1
git clone https://github.com/ghaering/pysqlite.git
cd pysqlite
(where brew reported I had existing versions I unlinked them and installed the latest as commented above)
then edited setup.cfg to comment out #define=SQLITE_OMIT_LOAD_EXTENSION and specify the paths:
include_dirs=/usr/local/opt/sqlite/include
library_dirs=/usr/local/opt/sqlite/lib
activated the virtualenv where I want it installed, then
python setup.py build
python setup.py install
(build_static still fails with clang: error: no such file or directory: 'sqlite3.c')
(maybe I should have done pip install . as suggested in the github issue)
now the spatialite geodjango.db "SELECT InitSpatialMetaData();" succeeds, albeit with an ignorable error:
InitSpatiaMetaData() error:"table spatial_ref_sys already exists"
i.e. it's probably not even necessary to run that command
When I was istalling this i follow this instructions https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/spatialite/#pysqlite2
pysqlite2
If you’ve decided to use a newer version of pysqlite2 instead of the sqlite3 Python stdlib module, then you need to make sure it can load external extensions (i.e. the required enable_load_extension method is available so SpatiaLite can be loaded).
This might involve building it yourself. For this, download pysqlite2 2.6, and untar:
$ wget https://pypi.python.org/packages/source/p/pysqlite/pysqlite-2.6.3.tar.gz
$ tar xzf pysqlite-2.6.3.tar.gz
$ cd pysqlite-2.6.3
Next, use a text editor (e.g., emacs or vi) to edit the setup.cfg file to look like the following:
[build_ext]
#define=
include_dirs=/usr/local/include
library_dirs=/usr/local/lib
libraries=sqlite3
#define=SQLITE_OMIT_LOAD_EXTENSION
I had the same error: SQLite header and source version mismatch.
For me it was enough to update libsqlite3-dev.
After that invoking $ spatialite geo.db "SELECT InitSpatialMetaData();" creates proper database.