How you can Switch to an older Python Version when doing Adobe Illustrator SDK Plugin Development

Adobe Illustrator SDK Python C++

For developers working on Adobe Illustrator plugins, using the Adobe Illustrator SDK can be incredibly powerful, but it also presents certain compatibility challenges, particularly when working with Python scripts for which it is more than likely that you are on version 3.x for normal python programming. Many Adobe SDKs, including the Illustrator SDK, still rely on Python scripts for tasks like plugin initialization and resource compilation. However, these scripts use features from older versions of Python—typically Python 2.7—that have become incompatible with modern Python 3.x installations. Considering that Python 2.7 was released in 2010 it seems surprising that Adobe hasn’t updated this requirement.

In this blog post, we’ll look at why this Python version swap is needed for Illustrator SDK plugin development, how to manage the version switch in a Windows environment, and provide a batch script solution for seamless toggling between Python installations.

Why Python Version Compatibility Matters for the Illustrator SDK

The Adobe Illustrator SDK includes a set of tools and resources for building plugins and extensions that enhance or automate Illustrator functionality. As part of the development process, many of the SDK’s scripts are used to generate required files, such as pipl resources, that define plugin metadata and behavior. However, these scripts were originally developed using Python 2.7, which uses different syntax and data handling compared to Python 3.x.

Since Python 2.7 reached its end of life in 2020, Python 3.x has become the standard version that most developers have installed. Running these Python 2-based scripts in a Python 3.x environment can lead to errors, such as:

TypeError: a bytes-like object is required, not 'str'

This error arises because Python 3.x handles strings and bytes differently than Python 2.7, causing compatibility issues when the Illustrator SDK scripts try to process data. Therefore, switching to Python 2.7 temporarily is necessary to successfully execute these scripts.

Solution: Switching Between Python Versions on Windows

If you already have Python 3 installed, adding Python 2.7 to your system can create conflicts in the system PATH, leading to confusion over which Python version is being called when you run python commands. One approach to handle this is to switch between the two versions by modifying the PATH environment variable temporarily to prioritize the correct version.

To make this process simpler, we’ve developed a batch script that lets you choose between C:\python (for Python 3.x) and C:\python27 (for Python 2.7) before running your Illustrator SDK scripts. This script modifies the PATH variable so that the chosen Python version is always used without causing conflicts or requiring manual changes each time.

The Batch Script for Switching Python Versions

Here’s the batch script you can use to select the appropriate Python version:

batchCopy code@echo off
REM Prompt user for choice
echo Select the Python path to set:
echo 1. C:\python
echo 2. C:\python27
set /p choice="Enter your choice (1 or 2): "

REM Set the selected Python path based on user input
if "%choice%"=="1" (
    set "python_path=C:\python"
) else if "%choice%"=="2" (
    set "python_path=C:\python27"
) else (
    echo Invalid choice. Exiting.
    exit /b
)

REM Initialize newpath variable to accumulate non-Python entries
set "newpath=%python_path%"

REM Loop through each entry in PATH, handling spaces properly
for %%P in ("%PATH:;=" "%") do (
    echo %%P | findstr /i /c:"C:\python27" >nul
    if %errorlevel% neq 0 (
        echo %%P | findstr /i /c:"C:\python" >nul
        if %errorlevel% neq 0 (
            set "newpath=%newpath%;%%~P"
        )
    )
)

REM Set the new PATH with the selected Python path at the beginning, excluding other Python paths
setx PATH "%newpath%"
echo PATH is now set to include only %python_path% without other Python paths

How the Script Works

  1. Prompt for User Selection: The script first prompts the user to select either Python 3.x (C:\python) or Python 2.7 (C:\python27).
  2. Remove Conflicting Python Paths: After the user makes a selection, the script loops through all entries in PATH, excluding any entries with C:\python or C:\python27.
  3. Set the Desired Python Path: The selected Python path is then added to the beginning of PATH, ensuring it is the version called when you run Python commands.

Running the Script

  1. Save the script as a .bat file (e.g., set_python_version.bat).
  2. Run the Script by double-clicking it or executing it in the Command Prompt. Choose 1 for Python 3.x or 2 for Python 2.7 based on the version needed for your task.
  3. Open a New Command Prompt after running the script to use the updated PATH.

By using this script, you can quickly toggle between Python versions as needed, ensuring compatibility with Illustrator SDK tools while maintaining the convenience of Python 3.x for other development work.

Solution: Using pyenv to Manage Python Versions on macOS

One of the easiest ways to handle multiple Python versions on macOS is to use a tool called pyenv. pyenv allows you to install multiple Python versions and switch between them seamlessly. Here’s how you can set it up:

Step 1: Install pyenv

  1. Install Homebrew (if you haven’t already) by running this command in Terminal:
  2. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Install pyenv using Homebrew:
  4. brew install pyenv
  5. Add pyenv to your shell configuration (e.g., .zshrc for Zsh or .bash_profile for Bash):
  6. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
    echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
  7. Restart your shell or source the configuration file:
  8. source ~/.zshrc

Step 2: Install Python 2.7 and Python 3.x

With pyenv installed, you can now install and manage different Python versions:

  1. Install Python 2.7:
  2. pyenv install 2.7.18
  3. Install Python 3.x (e.g., Python 3.9):
  4. pyenv install 3.9.9
  5. List all installed versions to verify the installations:
  6. pyenv versions

Step 3: Set the Python Version for the Illustrator SDK Project

pyenv allows you to set a specific Python version for your current shell session, a particular directory, or globally. This is useful if you want to use Python 2.7 just for running Illustrator SDK scripts without affecting other Python work.

  1. Set the Python version for the current terminal session (useful for quick testing):
  2. pyenv shell 2.7.18
  3. Set the Python version for a specific directory (e.g., your Illustrator SDK project directory). This option is convenient because every time you’re in the project directory, pyenv will automatically use the specified version:
  4. cd /path/to/illustrator-sdk-project
    pyenv local 2.7.18
  5. Set the global Python version (if you want Python 2.7 to be the default for all Terminal sessions):
  6. pyenv global 2.7.18

Now, whenever you run Python commands in the specified directory or session, the specified version will be used.

Step 4: Verify the Python Version

You can check which Python version is currently active by running:

python --version

This should display the Python version you selected with pyenv.

Step 5: Running the Illustrator SDK Scripts

With the appropriate Python version set, you can now navigate to the Illustrator SDK tools directory and run the pipl generation scripts without compatibility issues:

python /path/to/illustrator-sdk/tools/pipl/create_pipl.py

This setup should ensure that Illustrator SDK scripts run smoothly with Python 2.7, while you still have access to Python 3.x for other projects.

Additional Tips

  • Switch Back to Python 3.x: When you’re done with Illustrator SDK scripts, you can switch back to Python 3.x by running:
    pyenv shell 3.9.9
  • Automate Directory-Based Version Switching: Setting a Python version with pyenv local will automatically use that version whenever you navigate to the directory, making it ideal for project-based workflows.

Using pyenv on macOS provides an efficient way to manage multiple Python versions, ensuring compatibility for legacy tasks like the Illustrator SDK while maintaining the flexibility to use newer Python versions across other projects.

Final Thoughts

While the need to switch between Python versions may seem cumbersome, this approach allows you to maintain both versions on your system without constant adjustments. Given that Adobe SDKs may still rely on older Python scripts, understanding how to manage Python versions effectively is valuable for seamless plugin development. Until Adobe updates its SDKs to work with Python 3, this solution ensures you can continue developing Illustrator plugins without disruption and easily switch between the versions when required.

Author: Michael Peters, Technical Director, Mapsoft

https://www.linkedin.com/in/mpmapsoft

Share the Post:

Related Posts

c c++ programming comparison

A Comparison of C and C++

At Mapsoft, we harness the power of both C and C++ in our software development. While C is renowned for its simplicity and efficiency in system programming, C++ elevates the game with its support for object-oriented and generic programming. Curious about how these two languages compare? From memory management to exception handling, our detailed analysis explores the unique features and strengths of each language. Whether you’re developing low-level system components or complex applications, understanding these differences can significantly impact your project’s success. Dive in to discover which language best suits your needs!

Read More

Join Our Newsletter

How you can Switch to an older Python Version when doing Adobe Illustrator SDK Plugin Development

Adobe Illustrator SDK Python C++
Share the Post:

Related Posts

c c++ programming comparison

A Comparison of C and C++

At Mapsoft, we harness the power of both C and C++ in our software development. While C is renowned for its simplicity and efficiency in system programming, C++ elevates the game with its support for object-oriented and generic programming. Curious about how these two languages compare? From memory management to exception handling, our detailed analysis explores the unique features and strengths of each language. Whether you’re developing low-level system components or complex applications, understanding these differences can significantly impact your project’s success. Dive in to discover which language best suits your needs!

Read More

Join Our Newsletter