Loading ...
Sorry, an error occurred while loading the content.

vim plugins that embed python

Expand Messages
  • Senthil Kumaran
    1. I compiled python 2.7.3 from source. 2. Compiled vim against this custom python interpter Now there are certain plugins which embed Python like this: python
    Message 1 of 15 , Apr 16, 2012
    • 0 Attachment
      1. I compiled python 2.7.3 from source.
      2. Compiled vim against this custom python interpter

      Now there are certain plugins which embed Python like this:

      python <<EOF
      # -*- coding: utf-8 -*-
      import urllib , urllib2 , vim , xml.dom.minidom , xmlrpclib , sys , string , re

      When loading those plugins - this error is thrown.


      Error detected while processing /home/senthil/.vim/plugin/blog.vim:
      line 209:
      Traceback (most recent call last):
      File "<string>", line 2, in <module>
      File "/home/senthil/localpython/lib/python2.7/urllib2.py", line 94, in <module>
      import httplib
      File "/home/senthil/localpython/lib/python2.7/httplib.py", line 79, in <module>
      import mimetools
      File "/home/senthil/localpython/lib/python2.7/mimetools.py", line 6, in <module>
      import tempfile
      File "/home/senthil/localpython/lib/python2.7/tempfile.py", line 34, in <module>
      from random import Random as _Random
      File "/home/senthil/localpython/lib/python2.7/random.py", line 47, in <module>
      from os import urandom as _urandom
      ImportError: cannot import name urandom



      I searched the internet and it seems that this error is more for Python Virtual Environments was fixed in Python 2.6 and is not detected else where. So I am curious if something in vim needs fixing too.

      Thanks,
      Senthil

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Marcin Szamotulski
      ... I use vim 7.3.495 with python-2.7.2 and I cannot reproduce this. I use vim and python compiled by my system (Gentoo). Best, Marcin -- You received this
      Message 2 of 15 , Apr 16, 2012
      • 0 Attachment
        On 05:55 Mon 16 Apr , Senthil Kumaran wrote:
        > 1. I compiled python 2.7.3 from source.
        > 2. Compiled vim against this custom python interpter
        >
        > Now there are certain plugins which embed Python like this:
        >
        > python <<EOF
        > # -*- coding: utf-8 -*-
        > import urllib , urllib2 , vim , xml.dom.minidom , xmlrpclib , sys , string , re
        >
        > When loading those plugins - this error is thrown.
        >
        >
        > Error detected while processing /home/senthil/.vim/plugin/blog.vim:
        > line 209:
        > Traceback (most recent call last):
        > File "<string>", line 2, in <module>
        > File "/home/senthil/localpython/lib/python2.7/urllib2.py", line 94, in <module>
        > import httplib
        > File "/home/senthil/localpython/lib/python2.7/httplib.py", line 79, in <module>
        > import mimetools
        > File "/home/senthil/localpython/lib/python2.7/mimetools.py", line 6, in <module>
        > import tempfile
        > File "/home/senthil/localpython/lib/python2.7/tempfile.py", line 34, in <module>
        > from random import Random as _Random
        > File "/home/senthil/localpython/lib/python2.7/random.py", line 47, in <module>
        > from os import urandom as _urandom
        > ImportError: cannot import name urandom
        >
        >
        >
        > I searched the internet and it seems that this error is more for Python Virtual Environments was fixed in Python 2.6 and is not detected else where. So I am curious if something in vim needs fixing too.
        >
        > Thanks,
        > Senthil
        >
        > --
        > You received this message from the "vim_dev" maillist.
        > Do not top-post! Type your reply below the text you are replying to.
        > For more information, visit http://www.vim.org/maillist.php

        I use vim 7.3.495 with python-2.7.2 and I cannot reproduce this. I use vim and python
        compiled by my system (Gentoo).

        Best,
        Marcin

        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Marc Weber
        ... You re not accurately describing what might be causing the problem. In python you call it loading modules rather than plugins . Thus try ... (and
        Message 3 of 15 , Apr 16, 2012
        • 0 Attachment
          Excerpts from Senthil Kumaran's message of Mon Apr 16 14:55:40 +0200 2012:
          > 1. I compiled python 2.7.3 from source.
          > 2. Compiled vim against this custom python interpter
          >
          > Now there are certain plugins which embed Python like this:
          >
          > python <<EOF
          > # -*- coding: utf-8 -*-
          > import urllib , urllib2 , vim , xml.dom.minidom , xmlrpclib , sys , string , re
          > When loading those plugins - this error is thrown.
          You're not accurately describing what might be causing the problem.
          In python you call it "loading modules" rather than "plugins".
          Thus try
          :py import urllib2
          (and repeat) to find out which python module is causing trouble.
          urandom could be a unix specific random generator module using kernels
          /dev/urandom special device.

          Thus there are two possible fixes:
          a) try to compile python with a different python version (or try to
          compile that python with urandom support if possible, watch
          configuration output)
          b) replace urandom by another library / implementation to gather random
          data.

          Maybe a python guru knows more details ?

          My python 2.7.2, and 2.6.7 succeed on "from os import urandom".

          Because you compiled python from source I think you have to reconfigure
          *and* read the configure output carefully.

          Marc Weber

          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Senthil Kumaran
          ... I meant,those vim plugins which were internally using python. ... Yeah, just ... Was enough to experience this error. Traceback (most recent call last):
          Message 4 of 15 , Apr 16, 2012
          • 0 Attachment
            On Monday, 16 April 2012 21:14:50 UTC+8, MarcWeber wrote:

            > You're not accurately describing what might be causing the problem.
            > In python you call it "loading modules" rather than "plugins".

            I meant,those vim plugins which were internally using python.


            > :py import urllib2

            Yeah, just

            :py import random

            Was enough to experience this error.

            Traceback (most recent call last):
            File "<string>", line 1, in <module>
            File "/home/senthil/localpython/lib/python2.7/random.py", line 47, in <module>
            from os import urandom as _urandom
            ImportError: cannot import name urandom

            > Thus there are two possible fixes:
            > a) try to compile python with a different python version (or try to
            > compile that python with urandom support if possible, watch
            > configuration output)

            hmm. Perhaps, this could work, but that would prove something is wrong with vim, correct? Because the python 2.7.3 works out of box. (I can do import random and my os module has urandom()) just that from vim it does not work.

            > Because you compiled python from source I think you have to reconfigure
            > *and* read the configure output carefully.

            Let me try to get more details from vim + python configure output. Standalone that python version is fine. I can do from os import urandom but from within vim it fails.

            Thanks,
            Senthil

            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Marc Weber
            ... I m not entirely sure but I vaguely remember than python on linux uses statically linked python whereas python on windows uses python dlls.. This in turns
            Message 5 of 15 , Apr 16, 2012
            • 0 Attachment
              > Let me try to get more details from vim + python configure output.
              > Standalone that python version is fine. I can do from os import
              > urandom but from within vim it fails.

              I'm not entirely sure but I vaguely remember than python on linux uses
              statically linked python whereas python on windows uses python dlls..

              This in turns means that vim uses that python version which vim's
              makefiles finds first (which may not be your local python at all, but
              the traces hint that it does).

              you can try that import random (or whatever fails) within vim and python
              and compare traces (which .py files are read by vim) and or compare
              sys.path to get an idea what might be happening.

              Marc Weber

              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • ZyX
              ... Depends entirely on compilation options, but it I never saw it linked *statically*: I mean, when no external python library is required. Main difference:
              Message 6 of 15 , Apr 16, 2012
              • 0 Attachment
                понедельник, 16 апреля 2012 г., 18:27:00 UTC+4 пользователь MarcWeber написал:
                > > Let me try to get more details from vim + python configure output.
                > > Standalone that python version is fine. I can do from os import
                > > urandom but from within vim it fails.
                >
                > I'm not entirely sure but I vaguely remember than python on linux uses
                > statically linked python whereas python on windows uses python dlls..

                Depends entirely on compilation options, but it I never saw it linked *statically*: I mean, when no external python library is required. Main difference: in linux you are likely to have python library linked by system linker (like ld-linux.so), on windows you are likely to use vimLoadLib which uses LoadLibrary which is probably defined in some windows header files: I see
                ifdef PYTHON
                ifndef DYNAMIC_PYTHON
                DYNAMIC_PYTHON=yes
                endif
                <...>
                in src/Make_ming.mak, so this is the default. Besides, it is convenient for package maintainers: without package manager which will install dependencies for you requiring to install all interpreters is a pain for users and having all possible combinations of interpreters support is a pain for maintainers. I can compile dynamically linked python-enabled vim executable that uses system linker if you wish.

                If you saw my python-extended branch, I can say that in order to make both pythons work (thus test all modifications without recompilation) at the same time I have no options other then using dlopen (--with-python*interp=dynamic).

                >
                > This in turns means that vim uses that python version which vim's
                > makefiles finds first (which may not be your local python at all, but
                > the traces hint that it does).

                It will do so in any case unless you saw an executable when vim is linked really statically.

                >
                > you can try that import random (or whatever fails) within vim and python
                > and compare traces (which .py files are read by vim) and or compare
                > sys.path to get an idea what might be happening.
                >
                > Marc Weber

                By the way, latest vim compiled with python (2.7.3) support succeeds at

                from os import urandom
                on win32 (wine), but python was installed from msi package to default location. In order to do so I have the following variables:

                PYTHON={C}/Python27
                PYTHONINC=-I$PYTHON/include
                . If you compile using mingw with Make_ming.mak be sure they are set to proper values ({C} in my case is ~/.wine/dosdevices/c:, but Make_ming.mak is not only for cross-compiling). Also be sure that your custom python is in your $PATH (in my case it is C:\Python27) and it goes before any other python (at least when launching vim), python msi package is not adding it, make or whatever you used to compile python definitely won't add it also. If there are still differences, follow Marc Weber's advice.

                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • char101
                ... Hi, Just add this line in your .vimrc before using any python commands let $PYTHONHOME= -- You received this message from the
                Message 7 of 15 , Apr 16, 2012
                • 0 Attachment
                  On Monday, April 16, 2012 7:55:40 PM UTC+7, Senthil Kumaran wrote:
                  > 1. I compiled python 2.7.3 from source.
                  > 2. Compiled vim against this custom python interpter
                  >
                  > Now there are certain plugins which embed Python like this:
                  >
                  > python <<EOF
                  > # -*- coding: utf-8 -*-
                  > import urllib , urllib2 , vim , xml.dom.minidom , xmlrpclib , sys , string , re
                  >
                  > When loading those plugins - this error is thrown.

                  Hi,

                  Just add this line in your .vimrc before using any python commands

                  let $PYTHONHOME='<your python install dir>'

                  --
                  You received this message from the "vim_dev" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Senthil Kumaran
                  ... I tried this, but it did not help. The error message has something to do with virtual environments and I am not sure what is happening with a vim plugin is
                  Message 8 of 15 , Apr 17, 2012
                  • 0 Attachment
                    On Tuesday, 17 April 2012 09:59:25 UTC+8, char101 wrote:

                    > Just add this line in your .vimrc before using any python commands
                    >
                    > let $PYTHONHOME='<your python install dir>'

                    I tried this, but it did not help.

                    The error message has something to do with virtual environments and I am not sure what is happening with a vim plugin is calling python <<<EOF followed-by-python-code within it.

                    Thanks,
                    Senthil

                    --
                    You received this message from the "vim_dev" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • Charles
                    ... Hi, Sorry I didn t read the error messages thoroughly If you run this command python import os; print os.__file__ does it show the right file (probably
                    Message 9 of 15 , Apr 17, 2012
                    • 0 Attachment
                      On 4/17/12, Senthil Kumaran <orsenthil@...> wrote:
                      > On Tuesday, 17 April 2012 09:59:25 UTC+8, char101 wrote:
                      >
                      >> Just add this line in your .vimrc before using any python commands
                      >>
                      >> let $PYTHONHOME='<your python install dir>'
                      >
                      > I tried this, but it did not help.
                      >
                      > The error message has something to do with virtual environments and I am not
                      > sure what is happening with a vim plugin is calling python <<<EOF
                      > followed-by-python-code within it.

                      Hi,

                      Sorry I didn't read the error messages thoroughly

                      If you run this command

                      python import os; print os.__file__

                      does it show the right file (probably there is another os.py in the
                      python sys.path).

                      --
                      You received this message from the "vim_dev" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • Senthil Kumaran
                      ... Yes, it does, it properly shows the path to os module /home/senthil/localpython/lib/python2.7/os.pyc I see some software throwing the same error message.
                      Message 10 of 15 , Apr 17, 2012
                      • 0 Attachment
                        On Tuesday, 17 April 2012 21:12:11 UTC+8, char101 wrote:
                        > If you run this command
                        >
                        > python import os; print os.__file__
                        >
                        > does it show the right file (probably there is another os.py in the
                        > python sys.path).

                        Yes, it does, it properly shows the path to os module

                        /home/senthil/localpython/lib/python2.7/os.pyc

                        I see some software throwing the same error message.

                        https://bugs.launchpad.net/summit/+bug/963312

                        https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/954595

                        Thanks,
                        Senthil

                        --
                        You received this message from the "vim_dev" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      • Senthil Kumaran
                        On Tuesday, 17 April 2012 21:23:43 UTC+8, Senthil Kumaran wrote: Another related discussion -
                        Message 11 of 15 , Apr 17, 2012
                        • 0 Attachment
                          On Tuesday, 17 April 2012 21:23:43 UTC+8, Senthil Kumaran wrote:

                          Another related discussion -

                          http://www.gossamer-threads.com/lists/python/bugs/959768?page=last

                          --
                          You received this message from the "vim_dev" maillist.
                          Do not top-post! Type your reply below the text you are replying to.
                          For more information, visit http://www.vim.org/maillist.php
                        • Xavier de Gaye
                          ... This thread of the python-devel mailing list describes the issues raised by the change in 2.7.3 that removed urandom from the stdlib module os.py:
                          Message 12 of 15 , Apr 17, 2012
                          • 0 Attachment
                            On Tue, Apr 17, 2012 at 2:22 PM, Senthil Kumaran wrote:
                            > On Tuesday, 17 April 2012 09:59:25 UTC+8, char101  wrote:
                            >
                            >> Just add this line in your .vimrc before using any python commands
                            >>
                            >> let $PYTHONHOME='<your python install dir>'
                            >
                            > I tried this, but it did not help.
                            >
                            > The error message has something to do with virtual environments and
                            > I am not sure what is happening with a vim plugin is calling python
                            > <<<EOF followed-by-python-code within it.
                            >


                            This thread of the python-devel mailing list describes the issues
                            raised by the change in 2.7.3 that removed urandom from the stdlib
                            module os.py:

                            http://thread.gmane.org/gmane.comp.python.devel/131382

                            One of the participants in this thread wrote a page explaining the
                            issue:

                            http://piratepad.net/PAZ3CEq9CZ


                            If you do not see 2.7.3 when you run:

                            :python import sys; print sys.version

                            then it is because you are running in Vim an "older Python executable
                            (which does not have an implementation of urandom), but then
                            references the newer standard library (in which the os module also
                            does not have an implementation of urandom)."


                            --
                            Xavier

                            Les Chemins de Lokoti: http://lokoti.alwaysdata.net

                            --
                            You received this message from the "vim_dev" maillist.
                            Do not top-post! Type your reply below the text you are replying to.
                            For more information, visit http://www.vim.org/maillist.php
                          • Senthil Kumaran
                            ... 2.7.2+ (2.7:0c10061df711, Jan 4 2012, 00:27:06) [GCC 4.5.2] Press ENTER or type command That s indeed the case, but I wonder how vim is referencing this
                            Message 13 of 15 , Apr 17, 2012
                            • 0 Attachment
                              On Tuesday, 17 April 2012 22:11:07 UTC+8, Xavier de Gaye wrote:
                              > This thread of the python-devel mailing list describes the issues
                              > raised by the change in 2.7.3 that removed urandom from the stdlib
                              > module os.py:
                              >
                              > http://thread.gmane.org/gmane.comp.python.devel/131382
                              >
                              > One of the participants in this thread wrote a page explaining the
                              > issue:
                              >
                              > http://piratepad.net/PAZ3CEq9CZ
                              >
                              >
                              > If you do not see 2.7.3 when you run:
                              >
                              > :python import sys; print sys.version
                              >
                              > then it is because you are running in Vim an "older Python executable
                              > (which does not have an implementation of urandom), but then
                              > references the newer standard library (in which the os module also
                              > does not have an implementation of urandom)."


                              2.7.2+ (2.7:0c10061df711, Jan 4 2012, 00:27:06)
                              [GCC 4.5.2]
                              Press ENTER or type command

                              That's indeed the case, but I wonder how vim is referencing this older python executable.

                              I set the PATH=/home/senthil/localpython/bin:$PATH

                              And then do

                              ./configure --enable-pythoninterp --with-python-config-dir=/home/senthil/localpython/lib/python2.7/config --with-features=huge --prefix=/home/senthil/local


                              It is still taking up 2.7.2+ ( I am not not sure where it is taking from.
                              config.log details are here:
                              http://paste.pocoo.org/show/583031/

                              I suspect at at one line it take -Ipython2.7 and I guess, it going to other python interpreter.

                              Thanks,
                              Senthil

                              --
                              You received this message from the "vim_dev" maillist.
                              Do not top-post! Type your reply below the text you are replying to.
                              For more information, visit http://www.vim.org/maillist.php
                            • Charles
                              ... How about adding export LD_LIBRARY_PATH=/home/senthil/localpython/lib -- You received this message from the vim_dev maillist. Do not top-post! Type your
                              Message 14 of 15 , Apr 17, 2012
                              • 0 Attachment
                                On 4/17/12, Senthil Kumaran <orsenthil@...> wrote:
                                > That's indeed the case, but I wonder how vim is referencing this older
                                > python executable.
                                >
                                > I set the PATH=/home/senthil/localpython/bin:$PATH

                                How about adding

                                export LD_LIBRARY_PATH=/home/senthil/localpython/lib

                                --
                                You received this message from the "vim_dev" maillist.
                                Do not top-post! Type your reply below the text you are replying to.
                                For more information, visit http://www.vim.org/maillist.php
                              • Xavier de Gaye
                                ... The following line in your config.log explains the problem: configure:5427: gcc -o conftest -g -O2 -I/home/senthil/localpython/include/python2.7
                                Message 15 of 15 , Apr 18, 2012
                                • 0 Attachment
                                  On Tue, Apr 17, 2012 at 5:00 PM, Senthil Kumaran wrote:
                                  > On Tuesday, 17 April 2012 22:11:07 UTC+8, Xavier de Gaye  wrote:
                                  >> If you do not see 2.7.3 when you run:
                                  >>
                                  >>     :python import sys; print sys.version
                                  >>
                                  >> then it is because you are running in Vim an "older Python executable
                                  >> (which does not have an implementation of urandom), but then
                                  >> references the newer standard library (in which the os module also
                                  >> does not have an implementation of urandom)."
                                  >
                                  >
                                  > 2.7.2+ (2.7:0c10061df711, Jan  4 2012, 00:27:06)
                                  > [GCC 4.5.2]
                                  > Press ENTER or type command
                                  >
                                  > That's indeed the case, but I wonder how vim is referencing this older python executable.
                                  >
                                  > I set the PATH=/home/senthil/localpython/bin:$PATH
                                  >
                                  > And then do
                                  >
                                  > ./configure  --enable-pythoninterp  --with-python-config-dir=/home/senthil/localpython/lib/python2.7/config --with-features=huge --prefix=/home/senthil/local


                                  The following line in your config.log explains the problem:

                                  configure:5427: gcc -o conftest -g -O2
                                  -I/home/senthil/localpython/include/python2.7
                                  -DPYTHON_HOME=\"/home/senthil/localpython\" -pthread -I/usr/local/include
                                  -L/usr/local/lib conftest.c -lselinux
                                  -L/home/senthil/localpython/lib/python2.7/config
                                  -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic >&5


                                  The link is done against python 2.7.2 with -lpython2.7,
                                  but it is done while referencing python 2.7.3 standard library with
                                  -DPYTHON_HOME=\"/home/senthil/localpython\"

                                  I believe it is best to avoid having two different python minor
                                  versions on the same system.

                                  --
                                  Xavier

                                  Les Chemins de Lokoti: http://lokoti.alwaysdata.net

                                  --
                                  You received this message from the "vim_dev" maillist.
                                  Do not top-post! Type your reply below the text you are replying to.
                                  For more information, visit http://www.vim.org/maillist.php
                                Your message has been successfully submitted and would be delivered to recipients shortly.