Posted by & filed under GeoDjango.

We do a lot of django work here at Linfiniti and always use a python virtual environment with each project so that the runtime requirements are isolated to that project. Our typical project looks like this:

 

projectfolder
+-- django_project
   +-- django_app
+-- python
   +-- bin
   +-- include
   +-- lib
   +-- local

 

…with an outer folder containing a python virtual environment and a django project with one or more django apps in it.

This works out great…until you need to change the name of your project. You can simply rename everything like this:

 

newfolder
+-- new_django_project
   +-- django_app
+-- python
   +-- bin
   +-- include
   +-- lib
   +-- local

 

Using mv and git mv. But the problem is that virtualenvs are not portable – they have the filesytem paths hard coded into them. Usually I just destroy the virtualenv and then recreate it, but in our low bandwidth office that takes quite a while. So today I came up with a formula to rename everything without rebuilding. There are four steps:

1) rename the outer project folder e.g.

 

 
mv projectfolder newfolder

 

2) rename the django project e.g.

 

git mv django_project new_django_project

 

3) use the linux ‘rpl’ command to replace all references to the old folder names (run from the root of the newfolder directory:

 

 rpl -R "projectfolder" "newfolder" *
 rpl -R "django_project" "new_django_project" *

 

4) remove all old pyc files:

find . -name "*.pyc" -exec rm -rf {} \;
This last step is the important one – if you don’t do it python binary files will contain stale references to the old directory structure and you will see something like this if you try to do a runserver:
ValueError: bad marshal data (unknown type code)
Needless to say you should create a backup before attempting the above.
  • Ben

    I know this old, but it still applies. Ran into the error you mention in the last paragraph and I was brought right to this post. Thanks a ton.

    • http://kartoza.com/ Tim Sutton

      Glad it helped you Ben!