Author Topic: No site packages allowed when debugging Python?  (Read 312 times)

texasaggie97

  • Community Member
  • Posts: 16
  • Hero Points: 1
No site packages allowed when debugging Python?
« on: August 06, 2017, 09:39:12 pm »
I am trying to debug a Python script and it isn't working.

It fails trying to import a module that is installed into site-packages.

There is an option on the "Python Options" page for Interpreter arguments. There are menu items for that entry including "Don't imply 'import site' on initialization" and "Unbuffered binary stdout and stderr".

I have explicitly not selected anything, including those two, yet my command line starts like this:
"C:\Program Files\Python36\python.exe" -S -u "C:\Program Files\SlickEdit Pro 21.0.2\resource\tools\pydbgp-1.2.0/bin/pydbgp_bootstrapper.py" -d 127.0.0.1:8826 -k slickedit <script to debug>

The -S corresponds to "Don't imply 'import site' on initialization" and -u corresponds to "Unbuffered binary stdout and stderr".

I am less concerned about the -u parameter but it is the -S parameter that is breaking my script.

After much searching, I find that those two parameters are hardcoded into pythonopts.e on line 696 and there is nothing I can do to remove them, without editing a builtin file:
Code: [Select]
         _str pydbgp_exe = maybe_quote_filename(pydbgp_dir'/bin/pydbgp_bootstrapper.py');
         // -S : Do not 'import site' on initialization because it can mess with pydbgp.pl
         // -u : Unbuffered binary stdout/stderr allows Build window to print output as-it-comes
         _str pydbgp_cmdline = '-S -u 'pydbgp_exe' -d 'host':'port' -k slickedit';

If I run the same command without the -S, it does seem to work.

So my question is: How am I supposed to run a Python script that needs a additional packages installed? Do I hand edit the builtin pythonopts.e? And why do you have those as optional Interpreter arguments when you add them all the time?

I am using SlickEdit 21.0.3 with hotfix 6.

Rodney

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 706
  • Hero Points: 45
Re: No site packages allowed when debugging Python?
« Reply #1 on: August 06, 2017, 11:22:10 pm »
When we first implemented Python debugging, implied site packages was obviously enough of a problem for our beta testers that we decided to hard code the -S. Leaving it as an optional interpreter arg was an oversight. It has been a while since all of this was done, so I will have to research the best course of action (default to -S and have an option to override it, or leave -S out and leave the current Interpreter args option).

In the meantime, your only course is to edit out the '-S' from pythonopts.e and reload (Macro>Load Module).

++rodney

texasaggie97

  • Community Member
  • Posts: 16
  • Hero Points: 1
Re: No site packages allowed when debugging Python?
« Reply #2 on: August 07, 2017, 01:27:17 am »
Okay, thank you. At least for the script I am running, this works.

-Mark

ebbe

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: No site packages allowed when debugging Python?
« Reply #3 on: August 07, 2017, 08:20:24 am »
so I will have to research the best course of action (default to -S and have an option to override it, or leave -S out and leave the current Interpreter args option).

I have had this problem too for quite some time now and I have reported it to SlickEdit Support as a defect (See PM).

I have not had any serious problems running python scripts without the -S option. Could you please enlighten us a bit on what the problems encountered by the beta-testers were?

Anyway, not being able to load site packages is a showstopper when developing anything serious, at least on Windows. I have several scripts that go absolutely nowhere unless win32con is available. With the -S option on it isn't...

texasaggie97

  • Community Member
  • Posts: 16
  • Hero Points: 1
Re: No site packages allowed when debugging Python?
« Reply #4 on: August 07, 2017, 05:23:06 pm »
Could you please enlighten us a bit on what the problems encountered by the beta-testers were?

I'd also be interested in knowing what the issue was. That way if it happens to me, I'll know what a potential solution would be. Though I don't know if any of my Python scripts would work without the site-packages available.

Rodney

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 706
  • Hero Points: 45
Re: No site packages allowed when debugging Python?
« Reply #5 on: August 07, 2017, 11:15:21 pm »
I've removed the hard coded -S switch from pythonopts.e. You can still add it via Python Options as before. This will be in the next hotfix for 21.0.3 (TBA).

++rodney

ebbe

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: No site packages allowed when debugging Python?
« Reply #6 on: August 08, 2017, 06:47:28 am »
I've removed the hard coded -S switch from pythonopts.e. You can still add it via Python Options as before.
Thanks :)

This will be in the next hotfix for 21.0.3 (TBA).
There are at least two of us that are very much looking forward to that.