Sublime Forum

Python environment problem

#1

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’.

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?

0 Likes

Build system: "The handle is invalid"
How to force SublimeText to use its own Python?
Windows 7 Needed to Rename Python27 to install
#2

Do you use virtualenv ?

0 Likes

#3

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

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).

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?

0 Likes

#4

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:

SET PYTHONPATH=""; sublime_text.exe

… and see if it works.

0 Likes

#5

I think I rather meant something this:

SET PYTHONPATH= && sublime_text.exe
0 Likes

#6

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.

[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.

{
  "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 (https://forum.sublimetext.com/t/build-system-traceback/1975/1). Have you any idea how I debug this new issue?

0 Likes

#7

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:

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.

0 Likes

#8

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

start sublime_text.exe %*
0 Likes

#9

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 :smile:. 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 :wink:.

Thanks a lot for all your help.

0 Likes

#10

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

Thanks.

0 Likes