Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 May 2014 12:15:43 -0700
From:      Alfred Perlstein <alfred@freebsd.org>
To:        python@freebsd.org
Subject:   Question on virtualenv (python) and FreeBSD
Message-ID:  <538A2A5F.2000601@freebsd.org>

next in thread | raw e-mail | index | archive | help
Hey folks,

First off, thank you all very much for all the work being put into the 
Python ports infrastructure.  We are using it extensively in our project 
and it's been a huge boon to us.

I do have a question about how Python is setup on FreeBSD by default and 
it has to do with "virtualenv".

http://docs.python-guide.org/en/latest/dev/virtualenvs/

Virtualenv allows you to make almost a python "chroot" to keep all your 
dependencies together so that tracking your deps is very easy. It's very 
much like Ruby's rvm.

 From the site:
 >  A Virtual Environment, put simply, is an isolated working copy of 
Python which allows you to work on a specific project without worry of 
affecting other projects.
 >
 >  For example, you can work on a project which requires Django 1.3 
while also maintaining a project which requires Django 1.0.

It's very cool and useful for allowing multiple apps to exist on a box 
with different deps.

The problem I came across is that it seems "broken" if you are coming 
from OS X or Linux.

Specifically it seems like FreeBSD is shipping a relatively stripped 
down version of Python that makes using virtualenv not work.

> ~/gitbridge/app % python db_repo/manage.py  version_control sqlite:///db.db  db_repo
> Traceback (most recent call last):
>   File "db_repo/manage.py", line 5, in <module>
>   main(debug='False')
>   File "/home/alfred/gitbridge/lib/python2.7/site-packages/migrate/versioning/shell.py", line 207, in main
>   ret = command_func(**kwargs)
>   File "<string>", line 2, in version_control
>   File "/home/alfred/gitbridge/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 155, in with_engine
>   engine = construct_engine(url, **kw)
>   File "/home/alfred/gitbridge/lib/python2.7/site-packages/migrate/versioning/util/__init__.py", line 140, in construct_engine
>   return create_engine(engine, **kwargs)
>   File "/home/alfred/gitbridge/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 344, in create_engine
>   return strategy.create(*args, **kwargs)
>   File "/home/alfred/gitbridge/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 73, in create
>   dbapi =dialect_cls.dbapi(**dbapi_args)
>   File "/home/alfred/gitbridge/lib/python2.7/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 297, in dbapi
>   raise e
> ImportError: No module named pysqlite2
>

I have details and a workaround on my blog here (less messy than pasting 
the entire 200+ lines of info into this message):
http://splbio.wordpress.com/2014/04/19/using-djangosqlalchemy-and-virtualenv-on-freebsd/

Basically it seems that because we don't by default ship sqlite with 
Python we wind up with this odd situation where the virtualenv'd Python 
can't be used for the apps that I tend to use.

I'm wondering can something be done to make virtualenv work better out 
of the box for people?

-Alfred



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?538A2A5F.2000601>