ModuleNotFoundError: No module named 'mysql' error: exit status 255 #8690

Closed
opened 2026-02-21 18:27:03 -05:00 by yindo · 1 comment
Owner

Originally created by @gongshaojie12 on GitHub (Feb 27, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Operating Steps:

  1. docker exec -it docker-sandbox-1 bash

  2. pip install mysql-connector-python

  3. exit docker container

  4. Importing mysql.connector in the code execution module of the frontend page, with the code: import mysql.connector.

The following error occurred after running:
Traceback (most recent call last): File "/var/sandbox/sandbox-python/tmp/7a48f825_42ff_4c0d_a893_d338eb1bc314.py", line 48, in <module> File "<string>", line 3, in <module> ModuleNotFoundError: No module named 'mysql' error: exit status 255

How do I import a third-party package?

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @gongshaojie12 on GitHub (Feb 27, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Operating Steps: 1. `docker exec -it docker-sandbox-1 bash` 2. `pip install mysql-connector-python` 3. exit docker container 4. Importing mysql.connector in the code execution module of the frontend page, with the code: `import mysql.connector`. The following error occurred after running: `Traceback (most recent call last): File "/var/sandbox/sandbox-python/tmp/7a48f825_42ff_4c0d_a893_d338eb1bc314.py", line 48, in <module> File "<string>", line 3, in <module> ModuleNotFoundError: No module named 'mysql' error: exit status 255` How do I import a third-party package? ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 18:27:03 -05:00
yindo closed this issue 2026-02-21 18:27:03 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 27, 2025):

I found a similar closed issue that might help you resolve the ModuleNotFoundError for the 'mysql-connector-python' library. The suggested solution involves ensuring the library is installed in the correct environment used by Dify for executing Python scripts. Here are the steps you can follow:

  1. Custom Docker Image: Modify the Docker Compose configuration for the sandbox service to use a custom Docker image that includes 'mysql-connector-python'. This ensures the library is available for scripts executed via the web interface.

  2. Dependency Installation Script: If Dify allows initializing the sandbox with a script, use it to install 'mysql-connector-python' before running your main script.

  3. Refresh Python Environment: Use the post_start_command.sh script to update the Python environment within Dify, ensuring all dependencies, including 'mysql-connector-python', are correctly installed.

By ensuring 'mysql-connector-python' is accessible in the sandbox environment where Dify executes Python scripts, the ModuleNotFoundError should be resolved, allowing your scripts to run as expected [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Feb 27, 2025): <!-- Answer --> I found a similar closed issue that might help you resolve the `ModuleNotFoundError` for the 'mysql-connector-python' library. The suggested solution involves ensuring the library is installed in the correct environment used by Dify for executing Python scripts. Here are the steps you can follow: 1. **Custom Docker Image**: Modify the Docker Compose configuration for the `sandbox` service to use a custom Docker image that includes 'mysql-connector-python'. This ensures the library is available for scripts executed via the web interface. 2. **Dependency Installation Script**: If Dify allows initializing the sandbox with a script, use it to install 'mysql-connector-python' before running your main script. 3. **Refresh Python Environment**: Use the `post_start_command.sh` script to update the Python environment within Dify, ensuring all dependencies, including 'mysql-connector-python', are correctly installed. By ensuring 'mysql-connector-python' is accessible in the sandbox environment where Dify executes Python scripts, the `ModuleNotFoundError` should be resolved, allowing your scripts to run as expected <sup>[[1]](https://github.com/langgenius/dify/issues/4463)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/14772912-2383-4109-bc21-0377462a5659?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8690