How can I import the sqlite3 module into Python 2.4? - python

The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sqlite3/__init__.py", line 23, in ?
from dbapi2 import *
File "sqlite3/dbapi2.py", line 26, in ?
from _sqlite3 import *
ImportError: No module named _sqlite3
The file '_sqlite3' is in lib-dynload, but if I include this in the sqlite3 directory, I get additional errors.
Any suggestions? I am working in a limited environment; I don't have access to GCC, among other things.

I had same problem with CentOS and python 2.4
My solution:
yum install python-sqlite2
and try following python code
try:
import sqlite3
except:
from pysqlite2 import dbapi2 as sqlite3

Did you install it? That often works better than messing with sys.path.
python setup.py install
If so, you should then find it.
If, for some reason, you can't install it, set the PYTHONPATH environment variable. Do not make a habit of messing with sys.path.

You will need to install pysqlite. Notice, however, that this absolutely does require a compiler, unless you can find binaries for it (and Python 2.4) on the net. Using the 2.5 binaries will not be possible.

You must ensure your sqlite, sqlite-devel, python-sqlite are installed correctly first and then recompile Python.

Related

How to get packages to import in code within anaconda virtualenv?

Currently I cannot import package installed in virtual environment:
Traceback (most recent call last):
File "/Users/glada/GIT_REPOS/autoflux/main.py", line 5, in
import cx_oracle
ModuleNotFoundError: No module named 'cx_oracle'
Imports in python are sometimes a bit tricky because it depends on how you call a line of code. Do you call the import from the python REPL input?
>>> import cx_oracle
Do you call the line of code from inside a script?
$ python myscript.py
Do you run the script as a module?
$ python -m myscript
Also a folder structure would be helpful. Do you use virtualenv? Maybe you have installed the package to the wrong location (installed in main python installation site-packages and now you are trying to import inside an activated virtualenv)?
There is a brilliant answer on a similar question, which is really descriptive and once I also found very useful to understand imports in python. Maybe this helps you.

audiolab for python 2.7

I have python 2.7 installed in my system and I need to use the audiolab module.
I downloaded from the following site: http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikits.audiolab
When I import scikits.audiolab I get the following error:
Traceback (most recent call last):
File "C:/Python27/trystuff", line 1, in <module>
from scikits.audiolab import formatinfo as format
File "C:\Python27\lib\site-packages\scikits\__init__.py", line 1, in <module>
__import__('pkg_resources').declare_namespace(__name__)
ImportError: No module named pkg_resources
What should I do?
There is a Windows binary build of scikits.audiolab (and a whole lot of other stuff) for python 2.7 here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikits.audiolab
audiolab will also require libsndfile. The link is right there on that page, but I'll put it here too since libsndfile is great:
http://www.mega-nerd.com/libsndfile/#Download
PS: You will need to put the libsndfile-1.dll someplace python can find it. If you don't mind wasting at tiny bit of disk space, you can drop a copy of it in the Python27\Lib\site-packages\scikits\audiolab\pysndfile directory.
You need pkg_resources module which is a part of setup_tools or the newer fork distribute. The site you linked also has Windows binaries for you to install. I'd recommend the distribute module. They also provide you easy install/uninstall capabilities for third-party modules.

Python - problem in importing new module - libgmail

I downloaded Python module libgmail from sourceforge and extracted all the files in the archive. The archive had setup.py, so I went to that directory in command prompt and did
setup.py install
I am getting the following error message
I:\libgmail-0.1.11>setup.py install
Traceback (most recent call last):
File "I:\libgmail-0.1.11\setup.py", line 7, in ?
import libgmail
File "I:\libgmail-0.1.11\libgmail.py", line 36, in ?
import mechanize as ClientCookie
ImportError: No module named mechanize
This may be trivial, but I am new to python. So plz guide what to do.
please note, I am using python 2.4 and using Windows-XP.
Thank you
MicroKernel
I think this lib depends on this one:
http://wwwsearch.sourceforge.net/mechanize/
Try installing it first.
You need to download and install the module called mechanize. Depending on your operating system (ie. Linux), your package manager probably has something for this, otherwise you will need to google it, and follow it's installation instructions.
easy_install mechanize
If this doesn't work, you need to fix your PATH environment variable to include path to your python installation directory\scripts. easy_install will save you a lot of time in future.
P.S.: Python 2.4 is 6 years old, you should really consider at least 2.6.

How to get _sqlite3.so file?

I have installed Python 2.6.2.. I did it "locally" since I do not have root permissions. With this version of Python I wanted to use module called "sqlite3" (it is called "pysqlite" in earlier versions). In theory I had to be able to use this module without any problems since it is supposed to be included by default in the considered version of Python. However, I have some troubles. When I type:
from sqlite3 import *
I get:
Traceback (most recent call last):
File "", line 1, in File "/home/verrtex/opt/lib/python2.6/sqlite3/init.py", line 24, in
from dbapi2 import *
File "/home/verrtex/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: No module named _sqlite3
As I have already told to, the possible reason of this problem is that the module in tries to import _sqlite3 and fails, so it's not finding _sqlite3.so. This explanations is supported by the fact that I do not have _sqlite3.so file in my "/home/verrtex/opt/lib/python2.6/lib-dynload" directory. So, this is the problem I have to solve (I have to get this file to this directory).
I found out that to solve this problem I have to "install sqlite3 and recompile Python". I also found out that the problem can be solved by "building from source and moving the library to /usr/lib/python2.5/lib-dynload/".
However, it is not clear to me what exactly should I do. Should I install python module called "sqlite3" or I should install sqlite-database? By the way, I have already sqlite-database installed globally by the administrator. Can I use it or I still have to install my own database? By the way, I do not have root permissions. Can it be a problem? Or I need to install a python module? Is absence of root permissions a problem, in this case?
I also has been told to, to take source files from SQLite Download Page, extract archive, move to expanded directory and execute:
./configure
make
make install
Then I have to copy newly compiled files to my Python directory. Should I copy all newly compiled files? And to which exactly directory should I copy (my Python directory have some subdirectories)?
Would very appreciate any help, because I stack with this problem for a wile.
P.S. My OS is CentOS release 5.3 (Final).
Your sys.path is likely not pointing to your locally installed copy, or you're not running the Python 2.6.2 you think you are.
If none of that is the case, you need the SQLite development headers (sqlite-dev or whatever), and then recompile Python. You need to pay attention at the end of the compile, because it complains about what it didn't build due to missing dependencies.
EDIT: Reread question.
EDIT 2: Also, please don't do this:
from module import *
Do this:
from module import what_i_need
import module2
Although you might have found your solution, I just wrote mine down for someone who are stuck in the same problem.
My OS is CentOS 6.3(Final) with python2.6.
I install python2.7.3 in my system, but the problem's still there. (_sqlite3.so should be in /path/to/python2.7.3/lib/python2.7/lib-dynload after python2.7.3 has been installed. Because before python2.7 was installed, sqlite-autoconf-3071502.tar.gz was installed.)
I then copy the /path/to/python2.6/lib/python2.6/lib-dynload/_sqlite3.so to the python2.7's path. And type in the python-shell:
>>> import sqlite3
or
>>> import _sqlite3
No error reports.
Unfortunately, the damn error appeared as before when I run my python script.
I install sqlite-devel(sudo yum install sqlite-devel or download here), and then reinstall python2.7.3 again. Run my python script again. Thank goodness! The damn error finally solved.

How to find out if I have installed a Python module in Linux?

I tried to install a Python module by typing: sudo python setup.py install
After I typed this command I got a lot of output to the screen.
The lest few lines are bellow:
writing manifest file 'scikits.audiolab.egg-info/SOURCES.txt'
removing '/usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info' (and everything under it)
Copying scikits.audiolab.egg-info to /usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5.egg-info
Installing /usr/lib/python2.5/site-packages/scikits.audiolab-0.10.2-py2.5-nspkg.pth
running install_scripts
So, there were nothing suspicious. But when I tried to use the module from the Python:
import pyaudiolab
I see that Python does not find the module:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import pyaudiolab ImportError: No module named pyaudiolab
How can I found out what went wrong? As a result of the installation I get a new directory:
/usr/lib/python2.5/site-packages (so something happened) but I still cannot use the module. Can anybody help me with that?
Have you tried import scikits.audiolab or import audiolab?
From the OP's comment to an answer, it's clear that scikits.audiolab is indeed where this module's been installed, but it also needs you to install numpy. Assuming the module's configuration files are correct, by using easy_install instead of the usual python setup.py run, you might have automatically gotten and installed such extra dependencies -- that's one of the main points of easy_install after all. But you can also do it "manually" (for better control of where you get dependencies from and exactly how you install them), of course -- however, in that case, you do need to check and manually install the dependencies, too.
Your library depends upon numoy. Try installing numpy:
sudo apt-get install python-numpy
You need a more recent version of numpy (>= 1.2.0), as indicated on the audiolab installation informations.
check if you have the module somewhere inside:
/usr/lib/python2.5/site-packages/
(search for a file named |modulename|.py so in your example - try: pyaudiolab.py or audiolab.py)
if it exists - check if the directory in which it exists is found in the sys.path variable:
import sys
sys.path

Categories