Home Download Buy Blog Forum Support

Python environment problem

Python environment problem

Postby schmiidt on Mon Jul 18, 2011 1:12 pm

I'm using a custom build tool at work that is written in python. It's a command-line tool that is put under version control together with the rest of our source code.

I can have several different versions of this build tool running simultaneously, when I'm working on more than one project, release or feature. I don't know exactly how it works, but I activate (a python term I guess) a different python environment for each version of the software that I'm working on. Apparently, Sublime tries to use this environment when I start it from a command-line there I have activated the build tool. This results in a lot of tracebacks like the following when I run 'sublime_text.exe'.

Code: Select all
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 1, in <module>
    import os
  File ".\os.py", line 398, in <module>
  File ".\UserDict.py", line 83, in <module>
  File "C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib\abc.py", line 109, in register
  File "C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib\abc.py", line 151, in __subclasscheck__
  File "C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib\_weakrefset.py", line 69, in __contains__
TypeError: cannot create weak reference to 'classobj' object


The path 'C:\views\jsc_FwMainlinePrj' is one of the branches of our software that I'm working on and 'C:\views\jsc_FwMainlinePrj\pooma' is the path to the build tool. I know very little about python, but to me it looks like Sublime is trying to use the python environment that comes with the build tool. Is there a way I can make Sublime use its own python environment while the python environment for our custom build tool is still activated?
schmiidt
 
Posts: 20
Joined: Wed Oct 07, 2009 12:50 pm

Re: Python environment problem

Postby bizoo on Tue Jul 19, 2011 5:52 am

Do you use virtualenv ?
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Python environment problem

Postby schmiidt on Tue Jul 19, 2011 8:32 am

I'm not sure what I use :|, but I run a script called 'activate.bat' to activate the build tool and it adds the following to my environment.

Code: Select all
VIEWPATH=C:\views\jsc_FwMainlinePrj
VIRTUAL_ENV=C:\views\jsc_FwMainlinePrj\pooma
PYTHONHOME=C:\views\jsc_FwMainlinePrj\pooma
PYTHONPATH=C:\views\jsc_FwMainlinePrj\pooma\DLLs;C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib;C:\views\jsc_FwMainlinePrj
\pooma\Lib.zip\Lib\site-packages;C:\views\jsc_FwMainlinePrj\pooma\source;C:\views\jsc_FwMainlinePrj\pooma\unite


Now the build tool is working, but if I start Sublime (both 1.4 and 2) from this environment it doesn't work. I get the following traceback from Sublime 1.4 (the traceback in my previous post was from Sublime 2).

Code: Select all
Traceback (most recent call last):
File ".\PackageSetup.py", line 4, in <module>
  import glob
File ".\glob.py", line 4, in <module>
File ".\os.py", line 398, in <module>
File ".\UserDict.py", line 83, in <module>
File "C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib\abc.py", line 109, in register
File "C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib\abc.py", line 151, in __subclasscheck__
File "C:\views\jsc_FwMainlinePrj\pooma\Lib.zip\Lib\_weakrefset.py", line 69, in __contains__
TypeError: cannot create weak reference to 'classobj' object


I could have sworn that I had our build tool working in Sublime 1.x at some point, but something has changed since then. Has there been any changes in Sublime with respect to the environment variables above?
schmiidt
 
Posts: 20
Joined: Wed Oct 07, 2009 12:50 pm

Re: Python environment problem

Postby guillermooo on Tue Jul 19, 2011 8:39 am

It seems that Sublime Text is reading the PYTHONPATH environment variable and maybe scanning the standard library of your system's Python for *Command classes.

Try this from the command line:

Code: Select all
SET PYTHONPATH=""; sublime_text.exe


... and see if it works.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Python environment problem

Postby guillermooo on Tue Jul 19, 2011 8:56 am

I think I rather meant something this:

Code: Select all
SET PYTHONPATH= && sublime_text.exe
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Python environment problem

Postby schmiidt on Tue Jul 19, 2011 11:45 am

Yes, it changed things. Now I'm able to launch the build tool without any tracebacks, but I get the following error in the output panel.

Code: Select all
[Error 6] The handle is invalid
[Finished]


Apparently, this happens for all build tools. Even the simplest of all build tool finishes with this error message.

Code: Select all
{
  "cmd": [""]
}


It doesn't seem to be connected with the use of virtualenv, because it happens even without activating our build tool here at work. I simply cannot build anything on my machine at work no matter how I start Sublime 2, but at home it is working fine after you guys solved the Unicode problem for me (http://www.sublimetext.com/forum/viewtopic.php?f=3&t=2441). Have you any idea how I debug this new issue?
schmiidt
 
Posts: 20
Joined: Wed Oct 07, 2009 12:50 pm

Re: Python environment problem

Postby guillermooo on Tue Jul 19, 2011 11:57 am

Are you on Windows XP by any chance? For me, the invalid handle error occurs only if I launch Sublime Text from the command line. It works fine if I start if first from the Windows shell (but then the current directory in Sublime Text is wrong.). I've never found this issue on Windows 7.

Also, if you're on Windows XP, I would suggest trying to start Sublime Text from PowerShell if you have it installed (I don't) and see if that way it works fine.

Lastly, you should be able to work around this with a .bat file along these lines:

Code: Select all
REM This goes in sublime.bat
SET PYTHONPATH=
start cmd.exe /c sublime_text.exe %*


My cmd.exe knowledge is rusty, so you might need to adjust that (SETLOCAL, args, etc.). Especially the unsetting of PYTHONPATH, as your external build system might stop working from the command line.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Python environment problem

Postby guillermooo on Tue Jul 19, 2011 12:07 pm

This works for me on Windows XP Pro 32 bit from the command line:

Code: Select all
start sublime_text.exe %*
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Python environment problem

Postby schmiidt on Tue Jul 19, 2011 1:20 pm

I'm on Windows Vista at work and you are right, the invalid handle issue only occurs when I launch Sublime Text from the command line, which I do all the time at work in order to get the current directory and environment right for our build system. If I launch Sublime Text from the Windows shell then the Build System seems to work.

I have tried the bat-script you suggested and it seems to work :). I'm also going to try the PowerShell approach at some time, but for now I'll continue with the bat-script and see how far I make it this time ;).

Thanks a lot for all your help.
schmiidt
 
Posts: 20
Joined: Wed Oct 07, 2009 12:50 pm

Re: Python environment problem

Postby cek on Sat Mar 10, 2012 9:10 pm

anyone know the root cause of this problem? Is this a bug in Sublime Text 2? It is super annoying.

Thanks.
cek
 
Posts: 1
Joined: Sat Mar 10, 2012 8:37 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 21 guests