bchatard / alfred-jetbrains

Alfred5 workflow to easily open your projects with your favorite JetBrains product.
MIT License
621 stars 49 forks source link

STDERR: JetBrains - Open Project - v3[Run Script] env: python: No such file or directory #263

Closed hachikozjq closed 2 years ago

hachikozjq commented 2 years ago

FAQ

Describe the bug

idea project A message is displayed, indicating that the actual IDEA does not respond and debugging is displayed: STDERR: JetBrains - Open Project - v3[Run Script] env: python: No such file or directory

image

To Reproduce

1:idea project 2: image 3:IDEA no response 4:debug info: STDERR: JetBrains - Open Project - v3[Run Script] env: python: No such file or directory

Expected behavior

No response

Alfred Version

4.6.4

Node Version

16.14.0

NPM Version

8.3.1

Jetbrains Product & Version

idea 2021.2

Installation type

Homebrew

OS

macOS 12.3.1

hachikozjq commented 2 years ago

image

hachikozjq commented 2 years ago

image

bchatard commented 2 years ago

Did it work if you try to open a project with the idea bin?

hachikozjq commented 2 years ago

Did it work if you try to open a project with the idea bin?

idea normal work,but idea bin no work.

there was an opening announcement, but idea no work.

debug log no python command is displayed,but i installed python3.

bchatard commented 2 years ago

Ok, so issue is not related to this workflow. You should have the idea bin working first. Try to remove it and create it again through Idea or toolbox

bchatard commented 2 years ago

following your info from #273 I ask you to have your idea bin working properly before.

I'm surprised that your bin still need python, maybe recreate it from your IDE/Toolbox . If you can also update your IDE

Put the content of your bin here to check too: cat $(which idea)

My looks like this:

cat $(which idea)
#!/bin/bash
#Generated by JetBrains Toolbox 1.24.12080 at 2022-05-30T12:29:07.716582

declare -a ideargs=()
declare -- wait=""

for o in "$@"; do
  if [[ "$o" = "--wait" || "$o" = "-w" ]]; then
    wait="-W"
    o="--wait"
  fi
  if [[ "$o" =~ " " ]]; then
    ideargs+=("\"$o\"")
  else
    ideargs+=("$o")
  fi
done

open -na "/Users/bchatard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/221.5591.52/IntelliJ IDEA.app/Contents/MacOS/idea" $wait --args "${ideargs[@]}"
hachikozjq commented 2 years ago

following your info from #273 I ask you to have your idea bin working properly before.

I'm surprised that your bin still need python, maybe recreate it from your IDE/Toolbox . If you can also update your IDE

Put the content of your bin here to check too: cat $(which idea)

My looks like this:

cat $(which idea)
#!/bin/bash
#Generated by JetBrains Toolbox 1.24.12080 at 2022-05-30T12:29:07.716582

declare -a ideargs=()
declare -- wait=""

for o in "$@"; do
  if [[ "$o" = "--wait" || "$o" = "-w" ]]; then
    wait="-W"
    o="--wait"
  fi
  if [[ "$o" =~ " " ]]; then
    ideargs+=("\"$o\"")
  else
    ideargs+=("$o")
  fi
done

open -na "/Users/bchatard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/221.5591.52/IntelliJ IDEA.app/Contents/MacOS/idea" $wait --args "${ideargs[@]}"
#!/usr/bin/env python
#  Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

import os
import socket
import struct
import sys
import traceback

# See com.intellij.idea.SocketLock for the server side of this interface.

RUN_PATH = u'/Applications/IntelliJ IDEA.app'
CONFIG_PATH = u'/Users/jq/Library/Application Support/JetBrains/IntelliJIdea2021.2'
SYSTEM_PATH = u'/Users/jq/Library/Caches/JetBrains/IntelliJIdea2021.2'

def print_usage(cmd):
    print(('Usage:\n' +
           '  {0} -h | -? | --help\n' +
           '  {0} [project_dir] [-w|--wait]\n' +
           '  {0} [-l|--line line] [project_dir|--temp-project] [-w|--wait] file[:line]\n' +
           '  {0} diff <left> <right>\n' +
           '  {0} merge <local> <remote> [base] <merged>').format(cmd))

def write_to_sock(sock, data):
    if sys.version_info[0] >= 3:
        data = data.encode('utf-8')
    sock.send(struct.pack('>h', len(data)) + data)

def read_from_sock(sock):
    length = struct.unpack('>h', sock.recv(2))[0]
    return sock.recv(length).decode('utf-8')

def read_sequence_from_sock(sock):
    result = []
    while True:
        try:
            data = read_from_sock(sock)
            if data == '---':
                break
            result.append(data)
        except (socket.error, IOError) as e:
            print("I/O error({0}): {1} ({2})".format(e.errno, e.strerror, e))
            traceback.print_exception(*sys.exc_info())
            break
    return result

def process_args(argv):
    args = []

    skip_next = False
    for i, arg in enumerate(argv[1:]):
        if arg == '-h' or arg == '-?' or arg == '--help':
            print_usage(argv[0])
            exit(0)
        elif i == 0 and (arg == 'diff' or arg == 'merge' or arg == '--temp-project'):
            args.append(arg)
        elif arg == '-l' or arg == '--line':
            args.append(arg)
            skip_next = True
        elif arg == '-w' or arg == '--wait':
            args.append('--wait')
        elif arg == '-p' or arg == '--project':
            args.append(arg)
        elif arg == '-e' or arg == '--edit':
            args.append(arg)
        elif skip_next:
            args.append(arg)
            skip_next = False
        else:
            path = arg
            if ':' in arg:
                file_path, line_number = arg.rsplit(':', 1)
                if line_number.isdigit():
                    args.append('-l')
                    args.append(line_number)
                    path = file_path
            args.append(os.path.abspath(path))

    return args

def try_activate_instance(args):
    port_path = os.path.join(CONFIG_PATH, 'port')
    token_path = os.path.join(SYSTEM_PATH, 'token')
    if not (os.path.exists(port_path) and os.path.exists(token_path)):
        return False

    try:
        with open(port_path) as pf:
            port = int(pf.read())
        with open(token_path) as tf:
            token = tf.read()
    except ValueError:
        return False

    s = socket.socket()
    s.settimeout(1.0)
    try:
        s.connect(('127.0.0.1', port))
    except (socket.error, IOError):
        return False

    paths = read_sequence_from_sock(s)
    found = CONFIG_PATH in paths or os.path.realpath(CONFIG_PATH) in paths

    if found:
        write_to_sock(s, 'activate ' + token + '\0' + os.getcwd() + '\0' + '\0'.join(args))

        s.settimeout(None)
        response = read_sequence_from_sock(s)
        if len(response) < 2 or response[0] != 'ok':
            print('bad response: ' + str(response))
            exit(1)

        if len(response) > 2:
            print(response[2])

        exit(int(response[1]))

    return False

def start_new_instance(args):
    if sys.platform == 'darwin':
        if len(args) > 0:
            args.insert(0, '--args')
        if '--wait' in args:
            args.insert(0, '-W')
        os.execv('/usr/bin/open', ['open', '-na', RUN_PATH] + args)
    else:
        bin_file = os.path.split(RUN_PATH)[1]
        os.execv(RUN_PATH, [bin_file] + args)

ide_args = process_args(sys.argv)
if not try_activate_instance(ide_args):
    start_new_instance(ide_args)
hachikozjq commented 2 years ago

following your info from #273 I ask you to have your idea bin working properly before.

I'm surprised that your bin still need python, maybe recreate it from your IDE/Toolbox . If you can also update your IDE

Put the content of your bin here to check too: cat $(which idea)

My looks like this:

cat $(which idea)
#!/bin/bash
#Generated by JetBrains Toolbox 1.24.12080 at 2022-05-30T12:29:07.716582

declare -a ideargs=()
declare -- wait=""

for o in "$@"; do
  if [[ "$o" = "--wait" || "$o" = "-w" ]]; then
    wait="-W"
    o="--wait"
  fi
  if [[ "$o" =~ " " ]]; then
    ideargs+=("\"$o\"")
  else
    ideargs+=("$o")
  fi
done

open -na "/Users/bchatard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/221.5591.52/IntelliJ IDEA.app/Contents/MacOS/idea" $wait --args "${ideargs[@]}"

I've never set up Python。 image

bin python was removed from a version of MacOS

hachikozjq commented 2 years ago

@bchatard how solve problem

bchatard commented 2 years ago

drop your bin and create it again from Toolbox or IDE.

if still with python, try to take mine (adapt paths)

otherwise if still not good, I can't help you more on this because it's not related to this workflow. You should see with JetBrains: https://youtrack.jetbrains.com/issues/WI

spearkkk commented 2 years ago

I set up /usr/local/bin/idea for launcher script and then upgrade osx version. And then workflows did not works: env: python: No such file or directory. After I just set up launcher script agina(overwrite), workflow works.