You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win10下Bash中运行调用SQL的Python脚本及pid_info.py报错求助

Fixes for Running Your SQL-Calling Python Script in Windows 10 Bash

Hey there! Let's walk through the most common tweaks you'll need to get python pid_info.py 12345 working smoothly in Windows 10's Bash environment:

  • Double-check your Python command alias
    In many Windows Bash setups, python points to Python 2 by default, but your script is likely written for Python 3. Try replacing the command with python3 pid_info.py 12345 first. Also, make sure your script starts with the correct shebang line at the top: #!/usr/bin/env python3 to ensure the right interpreter is used.

  • Install SQL-related dependencies in Bash
    Your Windows Python environment's packages don't carry over to the Bash subsystem. If your script uses libraries like psycopg2 (PostgreSQL), pyodbc (SQL Server), or mysql-connector-python (MySQL), install them directly in Bash with the correct pip command. For example:

    # For PostgreSQL
    pip3 install psycopg2-binary
    # For MySQL
    pip3 install mysql-connector-python
    # For SQL Server
    pip3 install pyodbc
    
  • Fix SQL database connection settings
    If your script connects to a Windows-local database, localhost won't work in Bash (it refers to the Linux subsystem itself). Replace localhost with your Windows machine's actual IP address (you can find this via ipconfig in Command Prompt). Also:

    • Ensure your database allows remote connections from the Bash subsystem's IP range.
    • Double-check that your username, password, database name, and port number are correct in the script's connection string.
  • Verify script path and permissions
    If you're not in the same directory as pid_info.py, either cd to that folder first or use the full absolute path in the command (e.g., python3 /home/your_username/scripts/pid_info.py 12345). You can also add execute permissions to the script with chmod +x pid_info.py so you can run it directly (if you have the shebang line set).

  • Validate command-line parameter handling
    Make sure your script properly captures the 12345 argument. At minimum, it should include:

    import sys
    if len(sys.argv) < 2:
        print("Please provide a PID as an argument")
        sys.exit(1)
    pid = int(sys.argv[1])  # Convert to integer if needed for SQL queries
    

    If you skip converting to the right type, your SQL query might throw a type mismatch error.

  • Adjust Windows file paths for Bash
    If your script references Windows file paths (like config files or CSV inputs), convert them to Bash's Linux-style path format. For example, C:\Users\jhallvid\db_config.txt becomes /mnt/c/Users/jhallvid/db_config.txt. Bash can't read Windows-style paths directly, which could break your SQL setup if it relies on external files.

内容的提问来源于stack exchange,提问作者jhallvid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:27:54