Inkscape overwrites PYTHONPATH and PATH environment variables

Bug #1518278 reported by me-kell
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
In Progress
Wishlist
jazzynico

Bug Description

Inkscape (only in Windows!) overwrites PYTHONPATH and PATH environment variables prepending inkscape's own subdirectories. AFIK there is no trivial possibility to use another Python interpreter in windows.

In Windows systems (#ifdef WIN32) Inkscape (since rev 5073) sets PYTHONPATH environment variable hard coded and points (from rev 5073) to inkscape's python subdirectory ignoring the system PYTHONPATH variable,
later (from rev 5106) inkscape's python subdirectory is prepended to a system PYTHONPATH variable (if existing).

(For windows) the PATH variable is also (from rev 5073) hard coded prepending the existing system PATH variable.

http://bazaar.launchpad.net/~inkscape.dev/inkscape/RELEASE_0_91_BRANCH/revision/5073
http://bazaar.launchpad.net/~inkscape.dev/inkscape/RELEASE_0_91_BRANCH/revision/5106

Suggested solutions:

A. do not change the PYTHONPATH and PATH environment variables if existing. This solution has some problems if the system is using a PYTHONPATH pointing to a Python environment not compatible with inkscape's extensions (e.g. inkex.py).

B. let the user configure two environment variables, e.g. INKSCAPE_EXTENSIONS_PYTHONPATH. If this variable exists then use it, otherwise set PYTHONPATH as expected by inkscape. Do the same with INKSCAPE_EXTENSIONS_PATH. This is my preferred solution.

here is a patch for my proposed solution B. Based on RELEASE_0_91_BRANCH rev #13849 of file <inkscape>/src/main.cpp:

542a543,544
> gchar const *inkscape_extensions_pythonpath = g_getenv("INKSCAPE_EXTENSIONS_PATH");
> gchar const *inkscape_extensions_pythonpath = g_getenv("INKSCAPE_EXTENSIONS_PYTHONPATH");
560,563c562,569
< if (path) {
< new_path = g_strdup_printf("%s;%s;%s;%s;%s", exe, python, scripts, perl, path);
< } else {
< new_path = g_strdup_printf("%s;%s;%s;%s", exe, python, scripts, perl);
---
> if (inkscape_extensions_path) {
> new_path = inkscape_extensions_path;
> } else {
> if (path) {
> new_path = g_strdup_printf("%s;%s;%s;%s;%s", exe, python, scripts, perl, path);
> } else {
> new_path = g_strdup_printf("%s;%s;%s;%s", exe, python, scripts, perl);
> }
565,570c571,580
< if (pythonpath) {
< new_pythonpath = g_strdup_printf("%s;%s;%s;%s",
< python_s, pythonlib_s, pythondll_s, pythonpath);
< } else {
< new_pythonpath = g_strdup_printf("%s;%s;%s",
< python_s, pythonlib_s, pythondll_s);
---
> if (inkscape_extensions_pythonpath) {
> new_pythonpath = inkscape_extensions_pythonpath;
> } else {
> if (pythonpath) {
> new_pythonpath = g_strdup_printf("%s;%s;%s;%s",
> python_s, pythonlib_s, pythondll_s, pythonpath);
> } else {
> new_pythonpath = g_strdup_printf("%s;%s;%s",
> python_s, pythonlib_s, pythondll_s);
> }

Revision history for this message
su_v (suv-lp) wrote :

Attaching in-line diff as separate diff file (against lp:inkscape/0.91.x r13849) to ease testing on other systems.

tags: added: win32
removed: environment
Changed in inkscape:
importance: Undecided → Wishlist
jazzynico (jazzynico)
Changed in inkscape:
status: New → In Progress
assignee: nobody → jazzynico (jazzynico)
Revision history for this message
jazzynico (jazzynico) wrote :

New version attached (some compilation fixes and debug messages).
Tested successfully on Windows 7, Inkscape trunk rev. 14761 (32-bit).

I'm not found of B, and A is indeed not perfect, so I'd suggest a solution C: add a new preference checkbox for Windows (in Edit>Preferences, System section) to let users decide if they wish to use an external Python environment or not. Then if the option is set and a external Python environment exists, use it. Else (if the option is not set or if there's no external Python environment) revert to the internal Python environment.

Revision history for this message
me-kell (me-kell) wrote :

I agree with jazzynico's solution C: adding two new preferences: EXTENSIONS_PATH and EXTENSIONS_PYTHONPATH.

Revision history for this message
jazzynico (jazzynico) wrote :

@me-kell - C is not about adding two paths in the preferences, but about a checkbox to choose if existing PATH (with python.exe dir in it) and PYTHONPATH envs should be used instead of the default Inkscape environment.

Revision history for this message
me-kell (me-kell) wrote :

@jazzynico: IMHO using the global PATH and PYTHONPATH is not the optimal solution. For "normal" users this would be ok. But for developers who probably use different python environments this is not the best solution.

What are the arguments against setting a python environment for inkscape in the preferences?

If the only argument against is not to mess with the preferences, one solution (I call it solution D) could be a python environment file, e.g. "python.env" (or whatever name). This file would store PATH and PYTHONPATH and (if wished) other environment settings needed for the python environment. One could also think about a minimalistic algorithm: if a file "python.env" is present in one the preferences directories, then set this environment for python, else revert to the internal python environment.

Revision history for this message
Patrick Storz (ede123) wrote :

I just committed
  https://gitlab.com/inkscape/inkscape/commit/b1d63f1a3bed6abe4b74f232172137d5f48232dd

It removes the whole code to set PYTHONPATH (it was not required in MSYS2 builds anymore).

Can anybody experiencing issues with Inkscape's previous behavior retest if this is still an issue?
We keep adding Inkscape to PATH, but I think this should be fine in most (hopefully all) situations.

Also note that a different Python executable can be selected using the "python-interpreter" preference as explained at [1].

I also confirmed previously that if Inkscape's bundled Python is not installed but a different Python is available on the search path it will be used, too (without modifying "python-interpreter", which defaults to "pythonw" on Windows).

[1] http://wiki.inkscape.org/wiki/index.php/Extension_Interpreters

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.