How do I get Python virtuelenv and pysqlite to work?

C, C++, Python, Perl, Shell, etc.

How do I get Python virtuelenv and pysqlite to work?

Postby olav » 21 Jul 2010, 10:52

I'm currently playing a bit with the Pylons Python Web Framework and is trying to get it to work with Sqlalchemy and Sqlite.

I have installed py-pysqlite23, py-sqlite3 and python2.6 from ports.

When I'm not in a virtuelenv mode the command
[CMD=""]python -c 'import pysqlite2'[/CMD]
works fine.

But if I create a virtualenv with --no-site-packages
I get this
Code: Select all
(zbadminenv)[olav@olbsd ~/zbadmin]$ python -c 'import pysqlite2'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pysqlite2


If I try to install it with easy_install I get this error message
Code: Select all
(zbadminenv)[olav@olbsd ~/zbadmin]$ easy_install pysqlite                                                                             
Searching for pysqlite                                                                                                               
Reading http://www.pylonshq.com/download/                                                                                             
Best match: pysqlite 2.5.6                                                                                                           
Downloading http://cdn.pylonshq.com/download/1.0/pysqlite-2.5.6.tar.gz                                                               
Processing pysqlite-2.5.6.tar.gz                                                                                                     
Running pysqlite-2.5.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mrRfW0/pysqlite-2.5.6/egg-dist-tmp-E2BzUt                   
In file included from src/module.c:24:                                                                                               
src/connection.h:33:21: error: sqlite3.h: No such file or directory                                                                   
In file included from src/module.c:24:                                                                                               
src/connection.h:38: error: expected specifier-qualifier-list before 'sqlite3'                                                       
In file included from src/module.c:25:                                                                                               
src/statement.h:37: error: expected specifier-qualifier-list before 'sqlite3'                                                         
src/module.c:265: error: 'SQLITE_OK' undeclared here (not in a function)                                                             
src/module.c:266: error: 'SQLITE_DENY' undeclared here (not in a function)
src/module.c:267: error: 'SQLITE_IGNORE' undeclared here (not in a function)
src/module.c:268: error: 'SQLITE_CREATE_INDEX' undeclared here (not in a function)
src/module.c:269: error: 'SQLITE_CREATE_TABLE' undeclared here (not in a function)
src/module.c:270: error: 'SQLITE_CREATE_TEMP_INDEX' undeclared here (not in a function)
src/module.c:271: error: 'SQLITE_CREATE_TEMP_TABLE' undeclared here (not in a function)
src/module.c:272: error: 'SQLITE_CREATE_TEMP_TRIGGER' undeclared here (not in a function)
src/module.c:273: error: 'SQLITE_CREATE_TEMP_VIEW' undeclared here (not in a function)
src/module.c:274: error: 'SQLITE_CREATE_TRIGGER' undeclared here (not in a function)
src/module.c:275: error: 'SQLITE_CREATE_VIEW' undeclared here (not in a function)
src/module.c:276: error: 'SQLITE_DELETE' undeclared here (not in a function)
src/module.c:277: error: 'SQLITE_DROP_INDEX' undeclared here (not in a function)
src/module.c:278: error: 'SQLITE_DROP_TABLE' undeclared here (not in a function)
src/module.c:279: error: 'SQLITE_DROP_TEMP_INDEX' undeclared here (not in a function)
src/module.c:280: error: 'SQLITE_DROP_TEMP_TABLE' undeclared here (not in a function)
src/module.c:281: error: 'SQLITE_DROP_TEMP_TRIGGER' undeclared here (not in a function)
src/module.c:282: error: 'SQLITE_DROP_TEMP_VIEW' undeclared here (not in a function)
src/module.c:283: error: 'SQLITE_DROP_TRIGGER' undeclared here (not in a function)
src/module.c:284: error: 'SQLITE_DROP_VIEW' undeclared here (not in a function)
src/module.c:285: error: 'SQLITE_INSERT' undeclared here (not in a function)
src/module.c:286: error: 'SQLITE_PRAGMA' undeclared here (not in a function)
src/module.c:287: error: 'SQLITE_READ' undeclared here (not in a function)
src/module.c:288: error: 'SQLITE_SELECT' undeclared here (not in a function)
src/module.c:289: error: 'SQLITE_TRANSACTION' undeclared here (not in a function)
src/module.c:290: error: 'SQLITE_UPDATE' undeclared here (not in a function)
src/module.c:291: error: 'SQLITE_ATTACH' undeclared here (not in a function)
src/module.c:292: error: 'SQLITE_DETACH' undeclared here (not in a function)
src/module.c: In function 'init_sqlite':
src/module.c:419: warning: passing argument 1 of 'PyString_FromString' makes pointer from integer without a cast
error: Setup script exited with error: command 'cc' failed with exit status 1

Is it possible to fix this?
User avatar
olav
Member
 
Posts: 349
Joined: 23 Apr 2010, 19:39
Location: Norway, Stavanger

Postby fairy » 21 Jul 2010, 11:04

You didn't state why you need --no-site-packages that effectively disables py-sqlite*. Pretty much any python port installs into PYTHON_SITELIBDIR (i.e. [file]/usr/local/lib/python2.6/site-packages[/file]).
fairy
Junior Member
 
Posts: 34
Joined: 15 Jun 2010, 17:44

Postby olav » 21 Jul 2010, 11:21

I want to isolate the project as much as possible, I want to make it as easy as possible to move to another system, upgrade a system and so on. I've been involved with enough of Python projects with library conflicts :)
User avatar
olav
Member
 
Posts: 349
Joined: 23 Apr 2010, 19:39
Location: Norway, Stavanger

Postby roddierod » 21 Jul 2010, 11:35

site-packages is a pretty standard place to put packages, if the packages are in there then you'll start running into library conflicts.

I've written python apps that run on windows, freebsd & linux and always use site-packages without problem.
User avatar
roddierod
Member
 
Posts: 697
Joined: 17 Nov 2008, 12:36
Location: On my Slingerlands!

Same problem on FreeBSD 8.2

Postby puria » 09 Jul 2011, 09:07

Almost a year after, same problem here. Seems that since the sqlite3 is in a seperated module, the pythonists freebsd guys just made e little mistake. the [FILE]_sqlite3.so[/FILE] lib is under "site-packages" system wide that is sad ;)

So first of all you need to install [FILE]/usr/ports/databases/py-sqlite3[/FILE] . Then you can fix your virtualenv --no-site-packages by link in you freshly create virtualenv as this:

Code: Select all
$ virtualenv --no-site-packages your_virtualenv_name
$ ln -s /usr/local/lib/python2.x/site-packages/_sqlite3.so !$/lib/python2.x/


for me is python2.6 but be aware to change your right python version =)
puria
Junior Member
 
Posts: 1
Joined: 07 Jul 2011, 21:42


Return to Userland Programming & Scripting

Who is online

Users browsing this forum: No registered users and 1 guest