3

I'm trying to use pydiction to autocomplete Python/Django statements in VIM Editor.

When I try to add django modules to complete-dic using this:

python pydiction.py /usr/lib/pymodules/python2.6/django

or:

python pydiction.py /usr/lib/pymodules/python2.6/django/__init__.py

I receive this error:

Couldn't import: (...). Import by filename is not supported.

Thanks!

Pydiction: http://www.vim.org/scripts/script.php?script_id=850

3 Answers 3

6

It is quite some time since this question was raised. I faced similar problem. Following steps explain how to do it somewhat quickly.

Since pydiction.py doesn't parse packages recursively, I had to use find and vi to build a package list for Django. Suppose you have installed django in /usr/local/lib/python2.6/dist-packages/django. Then do the following:

cd /usr/local/lib/python2.6/dist-packages
find django -type d > /var/tmp/django_pkgs.sh

Open django_pkgs.sh in vim and delete all lines containing media, static, templates, gis, fixtures, tests, locale, localflavor etc. In vim, it is easy. Do the following from the vim console itself:

:g/media/d
:g/static/d
:g/templates/d
....
....
....

Once all unwanted files are removed from our listing, replace all / with . Do the following from within vim console:

:%s!/!.!g

This will convert the file path to fully qualified Python module names. Then replace all newlines with white space. Do the following from within the vim console:

%s/\n/ /

Note that there is a single white space character between last two forward slashes. Now you have all module names listed in a single line. Now add #!/bin/bash in the first line of the file. This way, we are converting our file into a bash script. Now add the following on second and third lines (as explained by oivvio in one of the earlier posts):

export DJANGO_SETTINGS_MODULE=settings
export PYTHONPATH=/path/to/parent/of/settings

Please replace path mentioned in the last line with the directory where your django settings.py is kept.

Then at the beginning of the line listing django modules, add the following

python ./pydiction.py

This line now should look like

python ./pydiction.py django django.contrib django.contrib.redirects ......

Now exit vim and run

chmod +x /var/tmp/django_pkgs.sh.

Then change to the directory where complete-dict and pydiction.py is kept and execute /var/tmp/django_pkgs.sh. You do need write access to the file complete-dict. If your package listing file is correct, everything will work fine. Otherwise you will see various errors on the console caused by importing of non-existing django modules. To fix them, identify such entries in your django_pkgs.sh file and remove them manually. Then again execute the same script.

I would have preferred pydiction.py doing a recursive search of modules rather than everyone preparing the module list manually. Probably a command line argument like -r could have been added to pydiction to do this automatically. :(

1
  • ok i ended up with 10gb file, which being scanned in VIm for like 5 hours.. =/
    – holms
    Apr 19, 2012 at 10:11
1

By glancing at the pydiction docs (I'm not a pydiction user) it appears that you are misusing the pydiction.py script.

You are not supposed to provide a filename for import. You are supposed to provide a module name on which to base the dictionary creation. The module must already be in your pythonpath.

So, with django in your pythonpath, you would do:

python pydiction.py django

0
0

For some reason doing

python pydiction.py django

will not add the submodules of django

What I had to do was:

export DJANGO_SETTINGS_MODULE=settings
export PYTHONPATH=/path/to/parent/of/settings

And then I had to add each submodule of django individually

python pydiction.py django.bin
python pydiction.py django.conf
python pydiction.py django.contrib

And so on. Tedious but it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.