Inkscape.org
Using Inkscape with Other Programs How do I set Python environment?
  1. #1
    bitrat bitrat @bitrat
    *

    Hi,

    I'm using an Inkscape AppImage v1.0 (4035a4f, 2020-05-01) and I'd like to experiment with Python scripting. 

    Unless I set PYTHONPATH and PYTHONHOME before I run the AppImage, I get:

    Fatal Python error: Py_Initialize: Unable to get the locale encoding

    ModuleNotFoundError: No module named 'encodings'

    However, I still find missing module errors when I run scripts, eg:

    ModuleNotFoundError: No module named 'lxml'

    I'm going to try running Inkscape in a virtualenv, but I'm interested to know if this problem has been solved in some way I should know about.  For example, it would be nice if I could set Inkscape's Python environment from Inkscape itself, rather than having to maintain a separate enclosing environment. 

    Maybe there's something in .config/inkscape/preferences.xml?

    This page says:

    • The --extension-directory/-x options that printed out the system extension directory containing Inkscape's stock extensions have been removed.

    They have been replaced by --system-data-directory and --user-data-directory, which print out the Inkscape installation's data directory and the user's profile directory respectively.

    There's nothing about setting alternative configurations though.  

    The --system-data-directory is temporary, but maybe there's an extension init script or something that can be run from .config/inkscape/extension?

    Any suggestions would be appreciated.

    Cheers,

    bitrat

  2. #2
    inklinea inklinea @inklinea⛰️

    If you are using Ubuntu 20+ you should not have to do any of that. 

    If you are missing PIL: 

    https://pillow.readthedocs.io/en/stable/installation.html

  3. #3
    bitrat bitrat @bitrat
    *

    Hi @inklinea

    I'm on Bionic Beaver but currently upgrading to Jammy Jellyfish, so I'll see what happens then.

    It looks to me like Inkscape is only looking for libraries in /usr/local/lib but not /usr/lib.  I'll have to look into that..

    But isn't there a way to extend the default environment, without installing packages globally.  I generally use virtualenv...

     

     

    Cheers,

    bitrat

     

     

  4. #4
    Jacek Pardyak Jacek Pardyak @jacek.pardyak
    *

    Hi @bitrat

    I don't know what kind of experiments are in your scope, but maybe you will find it useful:

    https://github.com/JacekPardyak/inkscaper (calling Inkscape from R/Py)

    https://github.com/JacekPardyak/r-py-inkscape (calling R/Py from Inkscape)

  5. #5
    Kaalleen Kaalleen @Kaalleen
    bitrat

    Maybe there's something in .config/inkscape/preferences.xml?

    Actually there is. In the preferences file search for extensions and add the python-interpreter attribute. Set it to your specific python path:

    <group id="extensions" python-interpreter="[...]" />

  6. #6
    削除されたユーザー gulshan212 🚫

    Hello this is Gulshan Negi

    Well, To set up a Python environment, you need to follow these steps:
    1. Install Python
    2. Create a Virtual Environment
    3. Activate the Virtual Environment
    4. Install Required Packages
    5. Deactivate the Virtual Environment
    This is a basic setup for a Python environment. You can install additional packages and configure the environment as per your project requirements.

    Thanks